Пример #1
0
 private static int CompareNodesByMinY(RTreeNode <T> a, RTreeNode <T> b)
 {
     return(a.Envelope.Y1.CompareTo(b.Envelope.Y1));
 }
Пример #2
0
 // calculate node's bbox from bboxes of its children
 private static void RefreshEnvelope(RTreeNode <T> node)
 {
     node.Envelope = SumChildBounds(node, 0, node.Children.Count);
 }
Пример #3
0
 public void Insert(RTreeNode <T> item)
 {
     Insert(item, root.Height - 1);
 }
Пример #4
0
        public void Remove(T item, Envelope envelope)
        {
            var node         = root;
            var itemEnvelope = envelope;

            var path    = new Stack <RTreeNode <T> >();
            var indexes = new Stack <int>();

            var           i       = 0;
            var           goingUp = false;
            RTreeNode <T> parent  = null;

            // depth-first iterative tree traversal
            while (node != null || path.Count > 0)
            {
                if (node == null)
                {
                    // go up
                    node   = path.TryPop();
                    parent = path.TryPeek();
                    i      = indexes.TryPop();

                    goingUp = true;
                }

                if (node != null && node.IsLeaf)
                {
                    // check current node
                    var index = node.Children.FindIndex(n => Comparer.Equals(item, n.Data));

                    if (index != -1)
                    {
                        // item found, remove the item and condense tree upwards
                        node.Children.RemoveAt(index);
                        path.Push(node);
                        CondenseNodes(path.ToArray());

                        return;
                    }
                }

                if (!goingUp && !node.IsLeaf && node.Envelope.Contains(itemEnvelope))
                {
                    // go down
                    path.Push(node);
                    indexes.Push(i);
                    i      = 0;
                    parent = node;
                    node   = node.Children[0];
                }
                else if (parent != null)
                {
                    i++;
                    if (i == parent.Children.Count)
                    {
                        // end of list; will go up
                        node = null;
                    }
                    else
                    {
                        // go right
                        node    = parent.Children[i];
                        goingUp = false;
                    }
                }
                else
                {
                    node = null;                  // nothing found
                }
            }
        }
Пример #5
0
 public void Clear()
 {
     root = new RTreeNode <T> {
         IsLeaf = true, Height = 1
     };
 }