예제 #1
0
 private static void TightenFor(RTreeMemoryIndex <T> .Node parent, RTreeMemoryIndex <T> .Node child)
 {
     for (int index = 0; index < parent.Children.Count; ++index)
     {
         if (parent.Children[index] == child)
         {
             parent.Boxes[index] = child.GetBox();
         }
     }
 }
예제 #2
0
        private static RTreeMemoryIndex <T> .Node Add(RTreeMemoryIndex <T> .Node leaf, BoxF2D box, T item, int minimumSize, int maximumSize)
        {
            if (box == null)
            {
                throw new ArgumentNullException("box");
            }
            if (leaf == null)
            {
                throw new ArgumentNullException("leaf");
            }
            RTreeMemoryIndex <T> .Node node1 = (RTreeMemoryIndex <T> .Node)null;
            if (leaf.Boxes.Count == maximumSize)
            {
                leaf.Boxes.Add(box);
                leaf.Children.Add((object)item);
                RTreeMemoryIndex <T> .Node[] nodeArray = RTreeMemoryIndex <T> .SplitNode(leaf, minimumSize);

                leaf.Boxes    = nodeArray[0].Boxes;
                leaf.Children = nodeArray[0].Children;
                RTreeMemoryIndex <T> .SetParents(leaf);

                node1 = nodeArray[1];
            }
            else
            {
                leaf.Boxes.Add(box);
                leaf.Children.Add((object)item);
            }
            RTreeMemoryIndex <T> .Node child = leaf;
            RTreeMemoryIndex <T> .Node node2 = node1;
            RTreeMemoryIndex <T> .Node parent;
            for (; child.Parent != null; child = parent)
            {
                parent = child.Parent;
                RTreeMemoryIndex <T> .TightenFor(parent, child);

                if (node2 != null)
                {
                    if (parent.Boxes.Count == maximumSize)
                    {
                        parent.Boxes.Add(node2.GetBox());
                        parent.Children.Add((object)node2);
                        RTreeMemoryIndex <T> .Node[] nodeArray = RTreeMemoryIndex <T> .SplitNode(parent, minimumSize);

                        parent.Boxes    = nodeArray[0].Boxes;
                        parent.Children = nodeArray[0].Children;
                        RTreeMemoryIndex <T> .SetParents(parent);

                        node2 = nodeArray[1];
                    }
                    else
                    {
                        parent.Boxes.Add(node2.GetBox());
                        parent.Children.Add((object)node2);
                        node2.Parent = parent;
                        node2        = (RTreeMemoryIndex <T> .Node)null;
                    }
                }
            }
            if (node2 == null)
            {
                return((RTreeMemoryIndex <T> .Node)null);
            }
            RTreeMemoryIndex <T> .Node node3 = new RTreeMemoryIndex <T> .Node();

            node3.Boxes = new List <BoxF2D>();
            node3.Boxes.Add(child.GetBox());
            node3.Boxes.Add(node2.GetBox());
            node3.Children = (IList) new List <RTreeMemoryIndex <T> .Node>();
            node3.Children.Add((object)child);
            child.Parent = node3;
            node3.Children.Add((object)node2);
            node2.Parent = node3;
            return(node3);
        }