Пример #1
0
        /// <summary>
        /// Returns the subquad containing the envelope.  Creates the subquad if it does not already exist.
        /// </summary>
        /// <param name="searchEnv"></param>
        /// <returns></returns>
        public Node GetNode(Envelope 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);
            }
        }
Пример #2
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>
        /// <param name="tree"></param>
        /// <param name="itemEnv"></param>
        /// <param name="item"></param>
        private void InsertContained(Node tree, Envelope itemEnv, Object item)
        {
            if (!tree.Envelope.Contains(itemEnv))
            {
                throw new TopologyException("Node envelope must contain item envelope");
            }

            // 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.MinX, itemEnv.MaxX);
            NodeBase node;

            if (isZeroX || isZeroY)
            {
                node = tree.Find(itemEnv);
            }
            else
            {
                node = tree.GetNode(itemEnv);
            }
            node.Add(item);
        }