simplify method

NmLassoSelection simplify(
  1. double tolerance
)

Simplify the path by removing points that are too close together

Implementation

NmLassoSelection simplify(double tolerance) {
  if (points.length < 3) return this;

  final simplified = <Offset>[points.first];
  for (int i = 1; i < points.length - 1; i++) {
    final distance = (points[i] - simplified.last).distance;
    if (distance >= tolerance) {
      simplified.add(points[i]);
    }
  }
  simplified.add(points.last);

  return NmLassoSelection(points: simplified, isClockwise: isClockwise, startTime: startTime);
}