forceBetween method
Clamps this value to be within the range from to to.
Returns:
fromif this value is less thanfromtoif this value is greater thanto- This value if it's within the range
Example:
5.0.forceBetween(0.0, 10.0); // 5.0
(-5.0).forceBetween(0.0, 10.0); // 0.0
15.0.forceBetween(0.0, 10.0); // 10.0
Implementation
double forceBetween(double from, double to) {
if (this < from) {
return from;
}
if (this > to) {
return to;
}
return this;
}