getLengths method

dynamic getLengths(
  1. dynamic divisions
)
inherited

Implementation

getLengths(divisions) {
  divisions ??= arcLengthDivisions;

  if (cacheArcLengths != null && (cacheArcLengths!.length == divisions + 1) && !needsUpdate) {
    return cacheArcLengths;
  }

  needsUpdate = false;

  List<num> cache = [];
  var current, last = getPoint(0, null);
  num sum = 0.0;

  cache.add(0);

  for (var p = 1; p <= divisions; p++) {
    current = getPoint(p / divisions, null);
    sum += current.distanceTo(last);
    cache.add(sum);
    last = current;
  }

  cacheArcLengths = cache;

  return cache; // { sums: cache, sum: sum }; Sum is in the last element.
}