clamp static method

double clamp(
  1. double x,
  2. double low,
  3. double high
)

Restrict x to the range low, high.

Implementation

static double clamp(double x, double low, double high) =>
    x < low ? low : (x > high ? high : x);