pointAt method

Point pointAt(
  1. double t
)

Get point at parameter t along the entire polyline

t = 0 returns first point, t = 1 returns last point.

Implementation

Point pointAt(double t) {
  if (t <= 0) return points.first;
  if (t >= 1) return points.last;

  final targetLen = t * length;
  double accumulated = 0;

  for (int i = 0; i < points.length - 1; i++) {
    final segLen = points[i].distanceTo(points[i + 1]);
    if (accumulated + segLen >= targetLen) {
      final localT = (targetLen - accumulated) / segLen;
      return Line(points[i], points[i + 1]).lerp(localT);
    }
    accumulated += segLen;
  }
  return points.last;
}