findNearestSnap method
Returns the snap point closest to the given value.
Assumes snapPoints are ordered from highest to lowest.
Implementation
double findNearestSnap(double value, List<double> snapPoints) {
for (int i = 0; i < snapPoints.length - 1; i++) {
final double upper = snapPoints[i];
final double lower = snapPoints[i + 1];
final double mid = (upper + lower) / 2;
if (value >= mid) {
return upper;
}
}
return snapPoints.last;
}