public void Insert(TBounds bounds, TItem entry, ISpatialIndexNode <TBounds, TItem> node, INodeSplitStrategy <TBounds, TItem> nodeSplitStrategy, IndexBalanceHeuristic heuristic, out ISpatialIndexNode <TBounds, TItem> newSiblingFromSplit) { newSiblingFromSplit = null; //TODO: handle null node.. // Terminating case if (node.IsLeaf) { node.Add(entry); // Handle node overflow if (node.ItemCount > heuristic.NodeItemMaximumCount) { // Split the node using the given strategy newSiblingFromSplit = nodeSplitStrategy.SplitNode(node, heuristic); //if (++_tempSplitCount % 100 == 0) //{ // Debug.Print("Node split # {0}", _tempSplitCount); //} } } else { // NOTE: Descending the tree recursively here // can make for a very expensive build of a tree, // even for moderate amounts of data. Double leastExpandedArea = Double.MaxValue; Double leastExpandedChildArea = Double.MaxValue; //TBounds currentBounds = new ComputationExtents(bounds); ISpatialIndexNode <TBounds, TItem> leastExpandedChild; leastExpandedChild = findLeastExpandedChild(node.SubNodes, bounds, leastExpandedArea, leastExpandedChildArea); Debug.Assert(leastExpandedChild != null); // Found least expanded child node - insert into it Insert(bounds, entry, leastExpandedChild, nodeSplitStrategy, heuristic, out newSiblingFromSplit); // Adjust this node... node.Bounds.ExpandToInclude(bounds); // Check for overflow and add to current node if it occured if (newSiblingFromSplit != null) { // Add new sibling node to the current node node.Add(newSiblingFromSplit); newSiblingFromSplit = null; // Split the current node, since the child count is too high, // and return the split to the caller if (node.ItemCount > heuristic.NodeItemMaximumCount) { newSiblingFromSplit = nodeSplitStrategy.SplitNode(node, heuristic); } } } }