docs: @Pure
  	public final int getNearestEndIndex(double x, double y, OutputParameter<Double> distance) {
  		final int count = getPointCount();
  		final Point2d firstPoint = getPointAt(0);
  		final Point2d lastPoint = getPointAt(count - 1);
  		final double d1 = Point2D.getDistancePointPoint(firstPoint.getX(), firstPoint.getY(), x, y);
  		final double d2 = Point2D.getDistancePointPoint(lastPoint.getX(), lastPoint.getY(), x, y);
  		if (d1 <= d2) {
  			if (distance != null) {
  				distance.set(d1);
  			}
  			return 0;
  		}
  		if (distance != null) {
  			distance.set(d2);
  		}
  		return count - 1;
  	}