Пример #1
0
        private void ReorganizeNode(PartitionNode <T> node)
        {
            // After adding objects and creating new partitions, checks to see if any of the upper level objects can go deeper into the tree.
            Queue <PartitionNode <T> > all_nodes = new Queue <PartitionNode <T> >();

            all_nodes.Enqueue(node);

            while (all_nodes.Count > 0)
            {
                List <SpatialObj <T> > rects_removed = new List <SpatialObj <T> >();
                PartitionNode <T>      current_node  = all_nodes.Dequeue();

                foreach (SpatialObj <T> rect in current_node.GetOverflowObjs())
                {
                    PartitionNode <T> deepest_field = FindContainingField(rect, current_node);

                    if (!deepest_field.Equals(current_node))
                    {
                        bool overflown = deepest_field.StoreRectangle(rect);
                        rects_removed.Add(rect);
                    }
                }
                if (rects_removed.Count > 0)
                {
                    current_node.DeleteRectangles(rects_removed, true);
                }

                if (current_node.HasChildren())
                {
                    foreach (PartitionNode <T> child in current_node.GetChildren())
                    {
                        all_nodes.Enqueue(child);
                    }
                }
            }
        }