/// <summary> /// Returns the smallest <i>existing</i> /// node containing the envelope. /// </summary> /// <param name="searchEnv"></param> public virtual NodeBase Find(IEnvelope searchEnv) { int subnodeIndex = GetSubnodeIndex(searchEnv, _centre); if (subnodeIndex == -1) { return(this); } if (Nodes[subnodeIndex] != null) { // query lies in subquad, so search it Node node = Nodes[subnodeIndex]; return(node.Find(searchEnv)); } // no existing subquad, so return this one anyway 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); }