Module utils
Various utility functions
Functions
clamp (value, min, max) | Clamps a value within the specified range. |
deadzone (value, size) | Returns value if it is equal or greater than |size |, or 0. |
threshold (value, threshold) | Check if value is equal or greater than threshold. |
tolerance (value, threshold) | Check if value is equal or less than threshold. |
map (value, min_in, max_in, min_out, max_out) | Scales a value from one range to another. |
lerp (low, high, progress) | Linear interpolation. |
decay (low, high, rate, dt) | Exponential decay |
smoothstep (progress, low, high) | Hermite interpolation. |
wrap (value, limit) | Wrap value around if it exceeds limit . |
is_pot (value) | Check if a value is a power-of-two. |
sign (value) | Get the sign of a number returns 1 for positive values, -1 for negative and 0 for zero. |
Fields
round | Round number at a given precision. |
is_nan | Check if a value is NaN Returns true if a number is not a valid number |
Functions
- clamp (value, min, max)
-
Clamps a value within the specified range.
Parameters:
- value Input value
- min Minimum output value
- max Maximum output value
Returns:
-
number
- deadzone (value, size)
-
Returns
value
if it is equal or greater than |size
|, or 0.Parameters:
- value
- size
Returns:
-
number
- threshold (value, threshold)
-
Check if value is equal or greater than threshold.
Parameters:
- value
- threshold
Returns:
-
boolean
- tolerance (value, threshold)
-
Check if value is equal or less than threshold.
Parameters:
- value
- threshold
Returns:
-
boolean
- map (value, min_in, max_in, min_out, max_out)
-
Scales a value from one range to another.
Parameters:
- value Input value
- min_in Minimum input value
- max_in Maximum input value
- min_out Minimum output value
- max_out Maximum output value
Returns:
-
number
- lerp (low, high, progress)
-
Linear interpolation.
Performs linear interpolation between 0 and 1 when
low
<progress
<high
.Parameters:
- low
value to return when
progress
is 0 - high
value to return when
progress
is 1 - progress (0-1)
Returns:
-
number
- low
value to return when
- decay (low, high, rate, dt)
-
Exponential decay
Parameters:
- low initial value
- high target value
- rate portion of the original value remaining per second
- dt time delta
Returns:
-
number
- smoothstep (progress, low, high)
-
Hermite interpolation.
Performs smooth Hermite interpolation between 0 and 1 when
low
<progress
<high
.Parameters:
- progress (0-1)
- low
value to return when
progress
is 0 - high
value to return when
progress
is 1
Returns:
-
number
- wrap (value, limit)
-
Wrap
value
around if it exceedslimit
.Parameters:
- value
- limit
Returns:
-
number
- is_pot (value)
-
Check if a value is a power-of-two.
Returns true if a number is a valid power-of-two, otherwise false.
Parameters:
- value
Returns:
-
boolean
- sign (value)
-
Get the sign of a number
returns 1 for positive values, -1 for negative and 0 for zero.
Parameters:
- value
Returns:
-
number