in commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Interval.java [200:228]
public Vector1D project(final Vector1D pt) {
OrientedPoint boundary = null;
if (minBoundary != null && maxBoundary != null) {
// both boundaries are present; use the closest
final double minOffset = minBoundary.offset(pt.getX());
final double maxOffset = maxBoundary.offset(pt.getX());
final double minDist = Math.abs(minOffset);
final double maxDist = Math.abs(maxOffset);
// Project onto the max boundary if it's the closest or the point is on its plus side.
// Otherwise, project onto the min boundary.
if (maxDist < minDist || maxOffset > 0) {
boundary = maxBoundary;
} else {
boundary = minBoundary;
}
} else if (minBoundary != null) {
// only the min boundary is present
boundary = minBoundary;
} else if (maxBoundary != null) {
// only the max boundary is present
boundary = maxBoundary;
}
return (boundary != null) ? boundary.project(pt) : null;
}