/** Check if a node is the child before its parent in ascending order. * @param node child node considered * @return true is the node has a parent end is before it in ascending order */ private boolean isBeforeParent(final BSPTree<Euclidean1D> node) { final BSPTree<Euclidean1D> parent = node.getParent(); if (parent == null) { return false; } else { return node == childBefore(parent); } }
/** Find the leaf node just after an internal node. * @param node internal node at which the sub-tree starts * @return leaf node just after the internal node */ private BSPTree<Euclidean1D> leafAfter(BSPTree<Euclidean1D> node) { node = childAfter(node); while (node.getCut() != null) { node = childBefore(node); } return node; }
/** Find the leaf node just before an internal node. * @param node internal node at which the sub-tree starts * @return leaf node just before the internal node */ private BSPTree<Euclidean1D> leafBefore(BSPTree<Euclidean1D> node) { node = childBefore(node); while (node.getCut() != null) { node = childAfter(node); } return node; }
/** Get the previous internal node. * @param node current internal node * @return previous internal node in ascending order, or null * if this is the first internal node */ private BSPTree<Euclidean1D> previousInternalNode(BSPTree<Euclidean1D> node) { if (childBefore(node).getCut() != null) { // the next node is in the sub-tree return leafBefore(node).getParent(); } // there is nothing left deeper in the tree, we backtrack while (isBeforeParent(node)) { node = node.getParent(); } return node.getParent(); }
/** Check if a node is the child before its parent in ascending order. * @param node child node considered * @return true is the node has a parent end is before it in ascending order */ private boolean isBeforeParent(final BSPTree<Euclidean1D> node) { final BSPTree<Euclidean1D> parent = node.getParent(); if (parent == null) { return false; } else { return node == childBefore(parent); } }
/** Find the leaf node just after an internal node. * @param node internal node at which the sub-tree starts * @return leaf node just after the internal node */ private BSPTree<Euclidean1D> leafAfter(BSPTree<Euclidean1D> node) { node = childAfter(node); while (node.getCut() != null) { node = childBefore(node); } return node; }
/** Find the leaf node just before an internal node. * @param node internal node at which the sub-tree starts * @return leaf node just before the internal node */ private BSPTree<Euclidean1D> leafBefore(BSPTree<Euclidean1D> node) { node = childBefore(node); while (node.getCut() != null) { node = childAfter(node); } return node; }
/** Get the previous internal node. * @param node current internal node * @return previous internal node in ascending order, or null * if this is the first internal node */ private BSPTree<Euclidean1D> previousInternalNode(BSPTree<Euclidean1D> node) { if (childBefore(node).getCut() != null) { // the next node is in the sub-tree return leafBefore(node).getParent(); } // there is nothing left deeper in the tree, we backtrack while (isBeforeParent(node)) { node = node.getParent(); } return node.getParent(); }