Restrict value from min to max.
min
max
double limit(double min, double max) { if (this < min) { return min; } if (this > max) { return max; } return this; }