Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="addEnv"></param>
        /// <returns></returns>
        public static Node CreateExpanded(Node node, IEnvelope addEnv)
        {
            Envelope expandEnv = new Envelope(addEnv);
            if (node != null)
                expandEnv.ExpandToInclude(node._env);

            Node largerNode = CreateNode(expandEnv);
            if (node != null)
                largerNode.InsertNode(node);
            return largerNode;
        }
Example #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>
 private static 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.Minimum.X, itemEnv.Maximum.X);
     bool isZeroY = IntervalSize.IsZeroWidth(itemEnv.Minimum.X, itemEnv.Maximum.X);
     NodeBase node;
     if (isZeroX || isZeroY)
         node = tree.Find(itemEnv);
     else node = tree.GetNode(itemEnv);
     node.Add(item);
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private Node CreateSubnode(int index)
        {
            // create a new subquad in the appropriate quadrant
            double minx = 0.0;
            double maxx = 0.0;
            double miny = 0.0;
            double maxy = 0.0;

            switch (index)
            {
                case 0:
                    minx = _env.Minimum.X;
                    maxx = _centre.X;
                    miny = _env.Minimum.Y;
                    maxy = _centre.Y;
                    break;
                case 1:
                    minx = _centre.X;
                    maxx = _env.Maximum.X;
                    miny = _env.Minimum.Y;
                    maxy = _centre.Y;
                    break;
                case 2:
                    minx = _env.Minimum.X;
                    maxx = _centre.X;
                    miny = _centre.Y;
                    maxy = _env.Maximum.Y;
                    break;
                case 3:
                    minx = _centre.X;
                    maxx = _env.Maximum.X;
                    miny = _centre.Y;
                    maxy = _env.Maximum.Y;
                    break;
                default:
                    break;
            }
            Envelope sqEnv = new Envelope(minx, maxx, miny, maxy);
            Node node = new Node(sqEnv, _level - 1);
            return node;
        }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="env"></param>
 /// <returns></returns>
 public static Node CreateNode(IEnvelope env)
 {
     Key key = new Key(env);
     Node node = new Node(key.Envelope, key.Level);
     return node;
 }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="node"></param>
 public virtual void InsertNode(Node node)
 {
     Assert.IsTrue(_env == null || _env.Contains(node.Envelope));
     int index = GetSubnodeIndex(node._env, _centre);
     if (node._level == _level - 1)
         Nodes[index] = node;
     else
     {
         // the quad is not a direct child, so make a new child quad to contain it
         // and recursively insert the quad
         Node childNode = CreateSubnode(index);
         childNode.InsertNode(node);
         Nodes[index] = childNode;
     }
 }