snap static method
Snaps value to the nearest discrete position for the given range.
Implementation
static double snap(double value, double start, double end, double step) {
final positions = discreteValues(start: start, end: end, step: step);
if (positions.isEmpty) return value.clamp(start, end);
double nearest = positions.first;
double bestDist = (value - nearest).abs();
for (final candidate in positions) {
final dist = (value - candidate).abs();
if (dist < bestDist) {
bestDist = dist;
nearest = candidate;
}
}
return nearest;
}