@tempots/std
wrap() function
Passed two boundaries values (min
, max
), wrap
ensures that the passed value v
will be included in the boundaries. If the value exceeds max
, the value is reduced by min
repeatedely until it falls within the range. Similar and inverted treatment is performed if the value is below min
.
Signature:
wrap: (v: number, min: number, max: number) => number
Parameters
Parameter |
Type |
Description |
---|---|---|
v |
number |
The value to wrap. |
min |
number |
The minimum value of the range. |
max |
number |
The maximum value of the range. |
Returns: number
The wrapped value.
Example
wrap(5, 0, 10) // returns 5
wrap(15, 0, 10) // returns 5
wrap(-5, 0, 10) // returns 5