/// <summary> /// Returns the subquad containing the envelope. /// Creates the subquad if /// it does not already exist. /// </summary> /// <param name="searchEnv"></param> public virtual Node GetNode(IEnvelope searchEnv) { int subnodeIndex = GetSubnodeIndex(searchEnv, _centre); // if subquadIndex is -1 searchEnv is not contained in a subquad if (subnodeIndex != -1) { // create the quad if it does not exist Node node = GetSubnode(subnodeIndex); // recursively search the found/created quad return(node.GetNode(searchEnv)); } return(this); }
/// <summary> /// Insert an item which is known to be contained in the tree rooted at /// the given QuadNode root. Lower levels of the tree will be created /// if necessary to hold the item. /// </summary> private static void InsertContained(Node tree, IEnvelope itemEnv, object item) { Assert.IsTrue(tree.Envelope.Contains(itemEnv)); /* * Do NOT create a new quad for zero-area envelopes - this would lead * to infinite recursion. Instead, use a heuristic of simply returning * the smallest existing quad containing the query */ bool isZeroX = IntervalSize.IsZeroWidth(itemEnv.Minimum.X, itemEnv.Maximum.X); bool isZeroY = IntervalSize.IsZeroWidth(itemEnv.Minimum.X, itemEnv.Maximum.X); NodeBase node; if (isZeroX || isZeroY) { node = tree.Find(itemEnv); } else { node = tree.GetNode(itemEnv); } node.Add(item); }
/// <summary> /// Insert an item which is known to be contained in the tree rooted at /// the given QuadNode root. Lower levels of the tree will be created /// if necessary to hold the item. /// </summary> private static void InsertContained(Node tree, IEnvelope itemEnv, object item) { Assert.IsTrue(tree.Envelope.Contains(itemEnv)); /* * Do NOT create a new quad for zero-area envelopes - this would lead * to infinite recursion. Instead, use a heuristic of simply returning * the smallest existing quad containing the query */ bool isZeroX = IntervalSize.IsZeroWidth(itemEnv.Minimum.X, itemEnv.Maximum.X); bool isZeroY = IntervalSize.IsZeroWidth(itemEnv.Minimum.X, itemEnv.Maximum.X); NodeBase node; if (isZeroX || isZeroY) node = tree.Find(itemEnv); else node = tree.GetNode(itemEnv); node.Add(item); }