mod function
Modulate a value between two ranges
Implementation
double mod(double value, List<double> a, List<double> b, {bool clamp = false}) {
final lh = b[0] < b[1] ? [b[0], b[1]] : [b[1], b[0]];
final result = b[0] + ((value - a[0]) / (a[1] - b[0])) * (b[1] - b[0]);
if (clamp) {
if (result < lh.first) return lh.first;
if (result > lh.last) return lh.last;
}
return result;
}