onSegment static method

double onSegment(
  1. Vec2D segmentPoint1,
  2. Vec2D segmentPoint2,
  3. Vec2D pt
)

Implementation

static double onSegment(Vec2D segmentPoint1, Vec2D segmentPoint2, Vec2D pt) {
  double l2 = squaredDistance(segmentPoint1, segmentPoint2);
  if (l2 == 0) {
    return 0;
  }
  return ((pt.x - segmentPoint1.x) * (segmentPoint2.x - segmentPoint1.x) +
          (pt.y - segmentPoint1.y) * (segmentPoint2.y - segmentPoint1.y)) /
      l2;
}