splitNode() private method

private splitNode ( VelocityDb.Collection.Spatial.RTree rTree, Rectangle r ) : NodeLeaf
rTree VelocityDb.Collection.Spatial.RTree
r Rectangle
return NodeLeaf
Esempio n. 1
0
        /// <summary>
        /// Adds a new entry at a specified level in the tree
        /// </summary>
        /// <param name="r">the rectangle added</param>
        internal void AddInternal(Rectangle r)
        {
            // I1 [Find position for new record] Invoke ChooseLeaf to select a leaf node L in which to place r
            NodeLeaf n       = (NodeLeaf)chooseNode(r, 1);
            NodeLeaf newLeaf = null;

            // I2 [Add record to leaf node] If L has room for another entry, install E. Otherwise invoke SplitNode to obtain L and LL containing E and all the old entries of L
            if (n.entryCount < maxNodeEntries)
            {
                n.addEntry(ref r);
            }
            else
            {
                newLeaf = n.splitNode(this, r);
            }

            // I3 [Propagate changes upwards] Invoke AdjustTree on L, also passing LL if a split was performed
            NodeBase newNode = n.adjustTree(this, newLeaf);

            // I4 [Grow tree taller] If node split propagation caused the root to split, create a new root whose children are the two resulting nodes.
            if (newNode != null)
            {
                NodeBase     oldRoot = rootNode;
                NodeInternal root    = new NodeInternal(++treeHeight, maxNodeEntries);
                rootNode = root;
                root.addEntry(ref newNode.minimumBoundingRectangle, newNode);
                root.addEntry(ref oldRoot.minimumBoundingRectangle, oldRoot);
            }
        }