Restricts x to the range [low, high].
x
low
high
static double clamp(double x, double low, double high) => x < low ? low : (x > high ? high : x);