adaptivePathToPoints function
Converts a path into a list of points with adaptive spacing.
The path
parameter represents the path to convert.
The maxTolerance
parameter specifies the maximum tolerance for spacing between points.
Returns a list of points representing the path with adaptive spacing.
Implementation
List<Offset> adaptivePathToPoints(Path path, double maxTolerance) {
List<Offset> points = [];
PathMetric pathMetric = path.computeMetrics().first;
double distance = 0.0;
double step = 1.0; // Initial step size
while (distance < pathMetric.length) {
Tangent? tangent = pathMetric.getTangentForOffset(distance);
if (tangent == null) continue;
points.add(tangent.position);
double curvature = calculateCurvature(tangent, pathMetric, distance, step);
// double curvature = tangent.angle;
// Adjust step based on curvature
step = maxTolerance / (1 + curvature.abs());
distance += step;
}
return points;
}