docs: public static Point nearestSegmentPoint(double startX, double startY, double endX, double endY, double pointX, double pointY) {
          double xDiff = endX - startX;
          double yDiff = endY - startY;
          double length2 = xDiff * xDiff + yDiff * yDiff;
          if (length2 == 0) return new Point(startX, startY);
          double t = ((pointX - startX) * (endX - startX) + (pointY - startY) * (endY - startY)) / length2;
          if (t < 0) return new Point(startX, startY);
          if (t > 1) return new Point(endX, endY);
          return new Point(startX + t * (endX - startX), startY + t * (endY - startY));
      }