Function clamp

  • Restricts a value to lie within a specified range.

    Ensures that value is no less than min and no greater than max.

    Parameters

    • value: number

      The input value to be clamped.

    • Optionalmin: number = 0

      The lower bound of the range (default is 0).

    • Optionalmax: number = 1

      The upper bound of the range (default is 1).

    Returns number

    • The clamped value within the range [min, max].
    clamp(1.5, 0.1, 0.9); // 0.9
    clamp(0.001, 0.1, 0.9); // 0.1
    clamp(0.5, 0, 1); // 0.5