computeMaxError function

_MaxError computeMaxError(
  1. Points points,
  2. Curve bez,
  3. List<num> parameters
)

Implementation

_MaxError computeMaxError(Points points , Curve bez, List<num> parameters) {
  // maximum error
  double maxDist = 0;
  // index of point with maximum error
  int splitPoint = (points.length / 2).floor();

  final t_distMap = _mapTtoRelativeDistances(bez, 10);

  for (int i = 1; i < points.length - 1; i++) {
    final point = points[i];
    //Find 't' for a point on the bez curve that's as close to 'point' as possible:
    final t = _find_t(bez, parameters[i], t_distMap, 10);

    // vector from point to curve
    final v = _sub(_bezierQ(bez, t), point);
    // current error
    final dist = _squaredNorm(v);

    if (dist > maxDist) {
      maxDist = dist;
      splitPoint = i;
    }
  }

  return _MaxError(maxDist, splitPoint);
}