getLengths method

List<double> getLengths(
  1. int? divisions
)

Get list of cumulative segment lengths

Implementation

List<double> getLengths(int? divisions) {
  divisions ??= arcLengthDivisions;

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

  needsUpdate = false;

  List<double> cache = [];
  Vector? current;
  Vector last = getPoint(0)!;
  double sum = 0.0;

  cache.add(0);

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

  cacheArcLengths = cache;

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