pointsOnLineFromPoint method

(Coord, Coord) pointsOnLineFromPoint(
  1. Coord point,
  2. num distance
)

Returns two coords equal distance, distance from the given point on the line.

Note:- if distance is less than the distanceFromPoint, function will return the 2 same points, i.e pointOnLineClosestTo;

Implementation

(Coord, Coord) pointsOnLineFromPoint(Coord point, num distance) {
  final pointOnLine = pointOnLineClosestTo(point);

  final distFromPoint = distanceFromPoint(point);
  if (distFromPoint > distance || distance == 0) {
    return (pointOnLine, pointOnLine);
  }

  final angleMadeByPoint = Angle.fromCos(distFromPoint, distance);
  final distOnLine = distance * angleMadeByPoint.sinValue;

  final first = _addDistToPointOnLine(pointOnLine, slope, distOnLine);
  final second = _addDistToPointOnLine(pointOnLine, slope, -distOnLine);
  return (first, second);
}