コード例 #1
0
        /// <summary>
        /// Returns the subnode containing the envelope.
        /// Creates the node if
        /// it does not already exist.
        /// </summary>
        /// <param name="searchInterval"></param>
        public Node GetNode(Interval searchInterval)
        {
            int subnodeIndex = GetSubnodeIndex(searchInterval, centre);

            // if index is -1 searchEnv is not contained in a subnode
            if (subnodeIndex != -1)
            {
                // create the node if it does not exist
                Node node = GetSubnode(subnodeIndex);
                // recursively search the found/created node
                return(node.GetNode(searchInterval));
            }
            else
            {
                return(this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Insert an item which is known to be contained in the tree rooted at
        /// the given Node.  Lower levels of the tree will be created
        /// if necessary to hold the item.
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="itemInterval"></param>
        /// <param name="item"></param>
        private void InsertContained(Node tree, Interval itemInterval, object item)
        {
            Assert.IsTrue(tree.Interval.Contains(itemInterval));

            /*
             * Do NOT create a new node for zero-area intervals - this would lead
             * to infinite recursion. Instead, use a heuristic of simply returning
             * the smallest existing node containing the query
             */
            bool     isZeroArea = IntervalSize.IsZeroWidth(itemInterval.Min, itemInterval.Max);
            NodeBase node;

            if (isZeroArea)
            {
                node = tree.Find(itemInterval);
            }
            else
            {
                node = tree.GetNode(itemInterval);
            }
            node.Add(item);
        }