* Splits this node by creating two new nodes and dividing the this node's * children between them. This node is removed from its parent and the two * new nodes are added. * * If this node is the root, a new parent node is created. * * Returns the parent node.
(strategy: IRTreeSplitStrategy)
| 367 | * Returns the parent node. |
| 368 | */ |
| 369 | public split(strategy: IRTreeSplitStrategy): RTreeNode<T> { |
| 370 | // Remove self from parent. |
| 371 | if (this.parent != null) { |
| 372 | this.parent.remove(this); |
| 373 | } |
| 374 | |
| 375 | // Create children from split |
| 376 | const children: NodePair<T> = [ |
| 377 | new RTreeNode<T>(this.leaf), |
| 378 | new RTreeNode<T>(this.leaf), |
| 379 | ]; |
| 380 | strategy.split(this.entries, children); |
| 381 | |
| 382 | // Add new nodes to parent |
| 383 | // If root, create new non-leaf node as parent. |
| 384 | const parent = this.parent != null ? this.parent : new RTreeNode<T>(false); |
| 385 | parent.insert(children[0]); |
| 386 | parent.insert(children[1]); |
| 387 | // Always make the parent a non-leaf after split |
| 388 | parent.leaf = false; |
| 389 | return parent; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Returns the difference in area that adding an entry `bounds` to the node |
no test coverage detected