isPointOnLine function

bool isPointOnLine(
  1. LatLng pointA,
  2. LatLng pointB,
  3. LatLng pointToCheck, {
  4. double strokeWidth = 1.0,
})

Checks if a point lies on a line segment defined by two other points, considering a tolerance for line width.

Implementation

bool isPointOnLine(LatLng pointA, LatLng pointB, LatLng pointToCheck,
    {double strokeWidth = 1.0}) {
  // Calculate distances between points.
  final distanceAToB = differenceInMeters(pointA, pointB);
  final distanceAToX = differenceInMeters(pointA, pointToCheck);
  final distanceBToX = differenceInMeters(pointB, pointToCheck);

  // Calculate total distance along line segment.
  final distance = distanceAToX + distanceBToX - distanceAToB;

  // Check if point is within the line width tolerance.
  return distance <= strokeWidth;
}