deleteLeaf method

void deleteLeaf(
  1. DBVTNode leaf
)

Implementation

void deleteLeaf(DBVTNode leaf) {
  if(leaf == root){
    root = null;
    return;
  }
  DBVTNode parent = leaf.parent!;
  DBVTNode sibling;
  if(parent.child1==leaf){
    sibling=parent.child2!;
  }
  else{
    sibling=parent.child1!;
  }
  if(parent==root){
    root=sibling;
    sibling.parent=null;
    return;
  }
  DBVTNode? grandParent = parent.parent;
  sibling.parent = grandParent;
  if(grandParent!.child1 == parent ) {
    grandParent.child1 = sibling;
  }
  else{
    grandParent.child2 = sibling;
  }
  if(numFreeNodes<16384){
    freeNodes[numFreeNodes++] = parent;
  }
  do{
    grandParent = balance(grandParent!);
    fix(grandParent);
    grandParent = grandParent.parent;
  }while( grandParent != null);
}