/// <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 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.MinX, itemEnv.MaxX); bool isZeroY = IntervalSize.IsZeroWidth(itemEnv.MinY, itemEnv.MaxY); NodeBase node; if (isZeroX || isZeroY) node = tree.Find(itemEnv); else node = tree.GetNode(itemEnv); node.Add(item); }
/// <summary> /// Returns the smallest <i>existing</i> /// node containing the envelope. /// </summary> /// <param name="searchEnv"></param> public NodeBase Find(IEnvelope searchEnv) { int subnodeIndex = GetSubnodeIndex(searchEnv, centre); if (subnodeIndex == -1) { return(this); } if (subnode[subnodeIndex] != null) { // query lies in subquad, so search it Node node = subnode[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 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.MinX, itemEnv.MaxX); bool isZeroY = IntervalSize.IsZeroWidth(itemEnv.MinY, itemEnv.MaxY); NodeBase node; if (isZeroX || isZeroY) { node = tree.Find(itemEnv); } else { node = tree.GetNode(itemEnv); } node.Add(item); }