clampTo method

double clampTo(
  1. double min,
  2. double max
)

Clamps the number between min and max.

Example:

15.5.clampTo(0.0, 10.0); // 10.0

Implementation

double clampTo(double min, double max) {
  assert(min <= max, 'min must be less than or equal to max');
  return this < min ? min : (this > max ? max : this);
}