QuadTreeNode <T> DeepChild(EQuadrant quad) { QuadTreeNode <T> current = this; while (!current.IsLeaf()) { current = current.Child(quad); } return(current); }
QuadTreeNode <T> Neighbour(ESide direction, EQuadrant corner) { QuadTreeNode <T> quadnode = Neighbour(direction); if (quadnode == null) { return(null); } while (!quadnode.IsLeaf()) { quadnode = quadnode.Child(Reflect(direction, corner)); } return(quadnode); }
EQuadrant Quadrant() { if (_parent == null) { throw new InvalidOperationException("The root node's quadrant isn't defined."); } if (_parent.Child(EQuadrant.NORTHWEST) == this) { return(EQuadrant.NORTHWEST); } else if (_parent.Child(EQuadrant.SOUTHWEST) == this) { return(EQuadrant.SOUTHWEST); } else if (_parent.Child(EQuadrant.NORTHEAST) == this) { return(EQuadrant.NORTHEAST); } else { return(EQuadrant.SOUTHEAST); } }
QuadTreeNode <T> Neighbour(ESide direction) { QuadTreeNode <T> neighbor = null; // Ascent the tree up to a common ancestor. if (_parent != null && Adjacent(direction, Quadrant())) { neighbor = _parent.Neighbour(direction); } else { neighbor = _parent; } // Backtrack mirroring the ascending moves. if (neighbor != null && !neighbor.IsLeaf()) { return(neighbor.Child(Reflect(direction, Quadrant()))); } else { return(neighbor); } }