Beispiel #1
0
 /// <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);
 }
Beispiel #2
0
        /// <summary>
        /// Returns the subquad containing the envelope.
        /// Creates the subquad if
        /// it does not already exist.
        /// </summary>
        /// <param name="searchEnv"></param>
        public 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));
            }
            else
            {
                return(this);
            }
        }
Beispiel #3
0
        /// <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);
        }