コード例 #1
0
ファイル: Node.cs プロジェクト: AlvaIce/GFJT-2020
        /// <summary>
        /// Returns the smallest existing
        /// node containing the envelope.
        /// </summary>
        /// <param name="searchInterval"></param>
        public virtual NodeBase Find(Interval searchInterval)
        {
            int subnodeIndex = GetSubnodeIndex(searchInterval, _centre);

            if (subnodeIndex == -1)
            {
                return(this);
            }
            if (Nodes[subnodeIndex] != null)
            {
                // query lies in subnode, so search it
                Node node = Nodes[subnodeIndex];
                return(node.Find(searchInterval));
            }
            // no existing subnode, so return this one anyway
            return(this);
        }
コード例 #2
0
ファイル: Root.cs プロジェクト: AlvaIce/GFJT-2020
        /// <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 static 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);
        }