/** Get the first leaf node of a tree. * @param root tree root * @return first leaf node */ private BSPTree<Euclidean1D> getFirstLeaf(final BSPTree<Euclidean1D> root) { if (root.getCut() == null) { return root; } // find the smallest internal node BSPTree<Euclidean1D> smallest = null; for (BSPTree<Euclidean1D> n = root; n != null; n = previousInternalNode(n)) { smallest = n; } return leafBefore(smallest); }
/** Check if an internal node corresponds to the end abscissa of an interval. * @param node internal node to check * @return true if the node corresponds to the end abscissa of an interval */ private boolean isIntervalEnd(final BSPTree<Euclidean1D> node) { if (!(Boolean) leafBefore(node).getAttribute()) { // it has an outside cell before it, it may start an interval but not end it return false; } if ((Boolean) leafAfter(node).getAttribute()) { // it has an inside cell after it, it is a dummy cut in the middle of an interval return false; } // the cell has an inside before and an outside after it // it is the end of an interval return true; }
/** Check if an internal node corresponds to the start abscissa of an interval. * @param node internal node to check * @return true if the node corresponds to the start abscissa of an interval */ private boolean isIntervalStart(final BSPTree<Euclidean1D> node) { if ((Boolean) leafBefore(node).getAttribute()) { // it has an inside cell before it, it may end an interval but not start it return false; } if (!(Boolean) leafAfter(node).getAttribute()) { // it has an outside cell after it, it is a dummy cut away from real intervals return false; } // the cell has an outside before and an inside after it // it is the start of an interval return true; }
/** 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(); }
/** Get the first leaf node of a tree. * @param root tree root * @return first leaf node */ private BSPTree<Euclidean1D> getFirstLeaf(final BSPTree<Euclidean1D> root) { if (root.getCut() == null) { return root; } // find the smallest internal node BSPTree<Euclidean1D> smallest = null; for (BSPTree<Euclidean1D> n = root; n != null; n = previousInternalNode(n)) { smallest = n; } return leafBefore(smallest); }
/** Check if an internal node corresponds to the start abscissa of an interval. * @param node internal node to check * @return true if the node corresponds to the start abscissa of an interval */ private boolean isIntervalStart(final BSPTree<Euclidean1D> node) { if ((Boolean) leafBefore(node).getAttribute()) { // it has an inside cell before it, it may end an interval but not start it return false; } if (!(Boolean) leafAfter(node).getAttribute()) { // it has an outside cell after it, it is a dummy cut away from real intervals return false; } // the cell has an outside before and an inside after it // it is the start of an interval return true; }
/** Check if an internal node corresponds to the end abscissa of an interval. * @param node internal node to check * @return true if the node corresponds to the end abscissa of an interval */ private boolean isIntervalEnd(final BSPTree<Euclidean1D> node) { if (!(Boolean) leafBefore(node).getAttribute()) { // it has an outside cell before it, it may start an interval but not end it return false; } if ((Boolean) leafAfter(node).getAttribute()) { // it has an inside cell after it, it is a dummy cut in the middle of an interval return false; } // the cell has an inside before and an outside after it // it is the end of an interval return true; }
/** 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(); }