Exemplo n.º 1
0
        /// <summary>
        /// Returns the smallest existing node containing the envelope.
        /// </summary>
        /// <param name="searchEnv"></param>
        /// <returns></returns>
        public NodeBase Find(Envelope 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);
        }
Exemplo n.º 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);
        }