# Namespace: MathUtils
# Table of contents
# Functions
# Functions
# clamp
▸ clamp(value
: number, min
: number, max
: number): number
Ensures that input value fits in a given range.
# Parameters
Name | Type | Description |
---|---|---|
value | number | The value to be clamped. |
min | number | Minimum value. |
max | number | Maximum value. |
Returns: number
Clamped value.
# easeInOutCubic
▸ easeInOutCubic(startValue
: number, endValue
: number, time
: number): number
Smoothly interpolates between two values using cubic formula
# Parameters
Name | Type | Description |
---|---|---|
startValue | number | - |
endValue | number | - |
time | number | - |
Returns: number
Result of the interpolation within the range of [startValue, endValue]
# equals
▸ equals(num1
: number, num2
: number, dotErr?
: number): boolean
判断两个数是否相等
# Parameters
Name | Type | Default value | Description |
---|---|---|---|
num1 | number | - | |
num2 | number | - | |
dotErr | number | 8 | 允许误差的小数点后几位,默认8位 |
Returns: boolean
# isClamped
▸ isClamped(value
: number, lowerBound
: number | undefined, upperBound
: number | undefined): boolean
Checks if the value of a given number is inside an upper or lower bound. The bounds may be undefined, in which case their value is ignored.
# Parameters
Name | Type | Description |
---|---|---|
value | number | Value to check. |
lowerBound | number | undefined | The lower bound to check the value against. |
upperBound | number | undefined | The upper bound to check the value against. |
Returns: boolean
true
if value is inside the bounds or if the bounds are undefined
, false
otherwise.
# lerp
▸ lerp(v1
: number, v2
: number, value
: number): number
线性插值
# Parameters
Name | Type |
---|---|
v1 | number |
v2 | number |
value | number |
Returns: number
# map
▸ map(val
: number, inMin
: number, inMax
: number, outMin
: number, outMax
: number): number
Maps a number from one range to another.
# Parameters
Name | Type | Description |
---|---|---|
val | number | The incoming value to be converted. |
inMin | number | Lower bound of the value's current range. |
inMax | number | Upper bound of the value's current range. |
outMin | number | Lower bound of the value's target range. |
outMax | number | Upper bound of the value's target range. |
Returns: number
# max2
▸ max2(a
: number | undefined, b
: number | undefined): number | undefined
Returns the larger of the two given numbers. Both numbers may be undefined, in which case the result is undefined. If only one of the numbers is undefined, the other number is returned.
# Parameters
Name | Type | Description |
---|---|---|
a | number | undefined | First number. |
b | number | undefined | Second number. |
Returns: number | undefined
# min2
▸ min2(a
: number | undefined, b
: number | undefined): number | undefined
Returns the smaller of the two given numbers. Both numbers may be undefined, in which case the result is undefined. If only one of the numbers is undefined, the other number is returned.
# Parameters
Name | Type | Description |
---|---|---|
a | number | undefined | First number. |
b | number | undefined | Second number. |
Returns: number | undefined
# smoothStep
▸ smoothStep(edge0
: number, edge1
: number, x
: number): number
Returns a smooth interpolation between the values edge0 and edge1 based on the interpolation
factor x. 0 <= x <= 1
.
see
https://en.wikipedia.org/wiki/Smoothstep
# Parameters
Name | Type | Description |
---|---|---|
edge0 | number | - |
edge1 | number | - |
x | number | - |
Returns: number
# smootherStep
▸ smootherStep(edge0
: number, edge1
: number, x
: number): number
Returns a smooth interpolation between the values edge0 and edge1 based on the interpolation
factor x. 0 <= x <= 1
.
Improved version by Ken Perlin, which has zero 1st- and 2nd-order derivatives at x = 0
and
x = 1
:
see
https://en.wikipedia.org/wiki/Smoothstep
# Parameters
Name | Type | Description |
---|---|---|
edge0 | number | - |
edge1 | number | - |
x | number | - |
Returns: number
# wrap
▸ wrap(n
: number, min
: number, max
: number, isMin?
: boolean): number
constrain n to the given range, excluding the minimum, via modular arithmetic
# Parameters
Name | Type | Default value | Description |
---|---|---|---|
n | number | - | value |
min | number | - | the minimum value to be returned, (isMin is false, exclusive, is true inclusive) |
max | number | - | the maximum value to be returned, (isMin is false, inclusive, is true exclusive) |
isMin | boolean | false |
Returns: number
number