Skip to content
Permalink
Browse files
GEOMETRY-63: method simplification and misc cleanup
  • Loading branch information
darkma773r committed Aug 10, 2020
1 parent 84bf4c1 commit 0e6a7f48b449675ef1391e8491efc4a826a41bf3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
@@ -225,22 +225,19 @@ protected <R extends AbstractConvexHyperplaneBoundedRegion<P, S>> Split<R> split
final Function<List<S>, R> factory) {

return isFull() ?
splitInternalFull(splitter, thisInstance, boundaryType, factory) :
splitInternalFull(splitter, boundaryType, factory) :
splitInternalNonFull(splitter, thisInstance, boundaryType, factory);
}

/** Internal split method for use with full regions, i.e. regions that cover the entire space.
* @param splitter splitting hyperplane
* @param thisInstance a reference to the current instance; this is passed as
* an argument in order to allow it to be a generic type
* @param boundaryType the type used for the boundary hyperplane subsets
* @param factory function used to create new convex region instances
* @param <R> Region implementation type
* @return the result of the split operation
*/
private <R extends AbstractConvexHyperplaneBoundedRegion<P, S>> Split<R> splitInternalFull(
final Hyperplane<P> splitter, final R thisInstance, final Class<S> boundaryType,
final Function<List<S>, R> factory) {
final Hyperplane<P> splitter, final Class<S> boundaryType, final Function<List<S>, R> factory) {

final R minus = factory.apply(Collections.singletonList(boundaryType.cast(splitter.span())));
final R plus = factory.apply(Collections.singletonList(boundaryType.cast(splitter.reverse().span())));
@@ -149,24 +149,12 @@ protected void insertBoundaryInternal(final HyperplaneConvexSubset<P> boundary)
private void insertBoundaryRecursive(final N node, final HyperplaneConvexSubset<P> insert,
final HyperplaneConvexSubset<P> trimmed, final BiConsumer<N, HyperplaneConvexSubset<P>> leafFn) {
if (node.isLeaf()) {
insertBoundaryRecursiveLeafNode(node, insert, trimmed, leafFn);
leafFn.accept(node, trimmed);
} else {
insertBoundaryRecursiveInternalNode(node, insert, trimmed, leafFn);
}
}

/** Recursive boundary insertion method for leaf nodes.
* @param node node to insert into
* @param insert the hyperplane convex subset to insert
* @param trimmed version of the hyperplane convex subset filling the entire space of {@code node}
* @param leafFn function to apply to leaf nodes
* @see #insertBoundaryRecursive(AbstractRegionNode, HyperplaneConvexSubset, HyperplaneConvexSubset, BiConsumer)
*/
private void insertBoundaryRecursiveLeafNode(final N node, final HyperplaneConvexSubset<P> insert,
final HyperplaneConvexSubset<P> trimmed, final BiConsumer<N, HyperplaneConvexSubset<P>> leafFn) {
leafFn.accept(node, trimmed);
}

/** Recursive boundary insertion method for internal nodes.
* @param node node to insert into
* @param insert the hyperplane convex subset to insert
@@ -419,7 +419,7 @@ private Plane createPlane(final Vector3D p1, final Vector3D p2, final Vector3D p
* @throws IllegalStateException if no portion of the cutter plane intersects the node
*/
private void checkedCut(final RegionNode3D node, final Plane cutter, final RegionCutRule cutRule) {
if (!node.insertCut(cutter)) {
if (!node.insertCut(cutter, cutRule)) {
throw new IllegalStateException("Failed to cut BSP tree node with plane: " + cutter);
}
}
@@ -230,8 +230,8 @@ public static ConvexArea convexPolygonFromPath(final LinePath path) {
"Cannot construct convex polygon from path with less than 3 elements: " + path);
}

// go through the elements and validate that the produced area is convex and finite;
// use the precision context from the first path element
// go through the elements and validate that the produced area is convex and finite
// using the precision context from the first path element
final LineConvexSubset startElement = elements.get(0);
final Vector2D startVertex = startElement.getStartPoint();
final DoublePrecisionContext precision = startElement.getPrecision();
@@ -214,22 +214,8 @@ public List<AngularInterval> toIntervals() {

final int boundaryPairCount = insideBoundaryPairs.size();

// Find the index of the first boundary pair that is not connected to pair before it.
// This will be our start point for merging intervals together.
int startOffset = 0;
if (boundaryPairCount > 1) {
BoundaryPair current = null;
BoundaryPair previous = insideBoundaryPairs.get(boundaryPairCount - 1);

for (int i = 0; i < boundaryPairCount; ++i, previous = current) {
current = insideBoundaryPairs.get(i);

if (!Objects.equals(current.getMin(), previous.getMax())) {
startOffset = i;
break;
}
}
}
// Get the start point for merging intervals together.
int startOffset = getIntervalStartIndex(insideBoundaryPairs);

// Go through the pairs starting at the start offset and create intervals
// for each set of adjacent pairs.
@@ -265,6 +251,32 @@ public List<AngularInterval> toIntervals() {
return intervals;
}

/** Get the index that should be used as the starting point for combining adjacent boundary pairs
* into contiguous intervals. This is computed as the first boundary pair found that is not connected
* to the pair before it, or {@code 0} if no such entry exists.
* @param boundaryPairs list of boundary pairs to search; must be ordered by increasing azimuth
* @return the index to use as a starting place for combining adjacent boundary pairs
* into contiguous intervals
*/
private int getIntervalStartIndex(final List<BoundaryPair> boundaryPairs) {
final int size = boundaryPairs.size();

if (size > 0) {
BoundaryPair current = null;
BoundaryPair previous = boundaryPairs.get(size - 1);

for (int i = 0; i < size; ++i, previous = current) {
current = boundaryPairs.get(i);

if (!Objects.equals(current.getMin(), previous.getMax())) {
return i;
}
}
}

return 0;
}

/** Create an interval instance from the min boundary from the start boundary pair and
* the max boundary from the end boundary pair. The hyperplane directions are adjusted
* as needed.

0 comments on commit 0e6a7f4

Please sign in to comment.