in commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/AbstractConvexHyperplaneBoundedRegion.java [447:490]
private HyperplaneConvexSubset<P> splitBound(final Hyperplane<P> currentBound,
final Iterable<? extends Hyperplane<P>> bounds, final int currentBoundIdx) {
HyperplaneConvexSubset<P> boundary = currentBound.span();
final Iterator<? extends Hyperplane<P>> boundsIt = bounds.iterator();
Hyperplane<P> splitter;
int splitterIdx = -1;
while (boundsIt.hasNext() && boundary != null) {
splitter = boundsIt.next();
++splitterIdx;
if (GeometryInternalUtils.sameInstance(currentBound, splitter)) {
// do not split the bound with itself
if (currentBoundIdx > splitterIdx) {
// this hyperplane is duplicated in the list; skip all but the
// first insertion of its hyperplane subset
return null;
}
} else {
// split the boundary
final Split<? extends HyperplaneConvexSubset<P>> split = boundary.split(splitter);
if (split.getLocation() != SplitLocation.NEITHER) {
// retain the minus portion of the split
boundary = split.getMinus();
} else if (!currentBound.similarOrientation(splitter)) {
// two or more splitters are coincident and have opposite
// orientations, meaning that no area is on the minus side
// of both
throw nonConvexException(bounds);
} else if (currentBoundIdx > splitterIdx) {
// two or more hyperplanes are equivalent; only use the boundary
// from the first one and return null for this one
return null;
}
}
}
return boundary;
}