Function clamp

  • Clamp the value between two points. Ensures that value is between the minimum and maximum of the provided scope.

    Parameters

    • value: number

      The value to be clamped.

    • scope: number[] = ...

      The range to clamp the value between, defaulting to [0, 1].

    Returns number

    Example

    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