in commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Interval.java [409:435]
public static Interval of(final OrientedPoint a, final OrientedPoint b) {
validateBoundaryRelationship(a, b);
final boolean hasA = a != null;
final boolean hasB = b != null;
if (!hasA && !hasB) {
// both boundaries null; return the full space
return FULL;
}
// determine the ordering of the hyperplanes; we know that at least one is non-null
final OrientedPoint minBoundary = ((hasA && !a.isPositiveFacing()) || (hasB && b.isPositiveFacing())) ? a : b;
final OrientedPoint maxBoundary = ((hasA && a.isPositiveFacing()) || (hasB && !b.isPositiveFacing())) ? a : b;
// validate the boundary locations; this will ensure that we don't have NaN values
final double minLoc = (minBoundary != null) ? minBoundary.getLocation() : Double.NEGATIVE_INFINITY;
final double maxLoc = (maxBoundary != null) ? maxBoundary.getLocation() : Double.POSITIVE_INFINITY;
validateIntervalValues(minLoc, maxLoc);
// create the interval, replacing infinites with nulls
return new Interval(
Double.isFinite(minLoc) ? minBoundary : null,
Double.isFinite(maxLoc) ? maxBoundary : null);
}