along function
void
along()
Part of a polyline: the first len px of it.
Implementation
void along(
List<Point2> pts,
double len,
void Function(double x0, double y0, double x1, double y1, double d) fn,
) {
var d = 0.0;
for (var i = 1; i < pts.length && d < len; i++) {
final (x0, y0) = pts[i - 1];
final (x1, y1) = pts[i];
final l = hypot(x1 - x0, y1 - y0);
final f = math.min(1.0, (len - d) / l);
fn(x0, y0, x0 + (x1 - x0) * f, y0 + (y1 - y0) * f, d);
d += l;
}
}