length method

double length({
  1. double accuracy = 0.1,
})

Calculates length of Cubic curve with given accuracy. 0 - fastest, raw accuracy. 1 - slowest, most accurate. Returns length of curve.

Implementation

double length({double accuracy = 0.1}) {
  final steps = (accuracy * 100).toInt();

  if (steps <= 1) {
    return _distance;
  }

  double length = 0.0;

  Offset prevPoint = start;
  for (int i = 1; i < steps; i++) {
    final t = i / steps;

    final next = point(t);

    length += prevPoint.distanceTo(next);
    prevPoint = next;
  }

  return length;
}