Class: MathUtils
A utitlity class for basic math.
Constructors
constructor
• new MathUtils(): MathUtils
Returns
Properties
HALF_PI
▪ Static
Readonly
HALF_PI: number
Half the value of pi.
Defined in
src/sdk/math/MathUtils.ts:9
SQRT1_3
▪ Static
Readonly
SQRT1_3: number
Square root of 1/3.
Defined in
src/sdk/math/MathUtils.ts:15
SQRT3
▪ Static
Readonly
SQRT3: number
Square root of 3.
Defined in
src/sdk/math/MathUtils.ts:12
TWO_PI
▪ Static
Readonly
TWO_PI: number
Twice the value of pi.
Defined in
src/sdk/math/MathUtils.ts:6
Methods
ceil
▸ ceil(value
, precision?
): number
Ceils a number.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | number | undefined | The number to ceil. |
precision | number | 1 | The precision with which to ceil. Defaults to 1 . |
Returns
number
The ceiled number.
Defined in
src/sdk/math/MathUtils.ts:45
clamp
▸ clamp(value
, min
, max
): number
Clamps a numerical value to the min/max range.
Parameters
Name | Type | Description |
---|---|---|
value | number | The value to be clamped. |
min | number | The minimum. |
max | number | The maximum. |
Returns
number
The clamped numerical value..
Defined in
src/sdk/math/MathUtils.ts:25
diffAngle
▸ diffAngle(start
, end
, directional?
): number
Calculates the angular difference between two angles in the range [0, 2 * pi)
. The calculation supports both
directional and non-directional differences. The directional difference is the angle swept from the start angle
to the end angle proceeding in the direction of increasing angle. The non-directional difference is the smaller
of the two angles swept from the start angle to the end angle proceeding in either direction.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
start | number | undefined | The starting angle, in radians. |
end | number | undefined | The ending angle, in radians. |
directional | boolean | true | Whether to calculate the directional difference. Defaults to true . |
Returns
number
The angular difference between the two angles, in radians, in the range [0, 2 * pi)
.
Defined in
src/sdk/math/MathUtils.ts:69
diffAngleDeg
▸ diffAngleDeg(start
, end
, directional?
): number
Calculates the angular difference between two angles in the range [0, 360)
. The calculation supports both
directional and non-directional differences. The directional difference is the angle swept from the start angle
to the end angle proceeding in the direction of increasing angle. The non-directional difference is the smaller
of the two angles swept from the start angle to the end angle proceeding in either direction.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
start | number | undefined | The starting angle, in degrees. |
end | number | undefined | The ending angle, in degrees. |
directional | boolean | true | Whether to calculate the directional difference. Defaults to true . |
Returns
number
The angular difference between the two angles, in degrees, in the range [0, 360)
.
Defined in
src/sdk/math/MathUtils.ts:84
floor
▸ floor(value
, precision?
): number
Floors a number.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | number | undefined | The number to floor. |
precision | number | 1 | The precision with which to floor. Defaults to 1 . |
Returns
number
The floored number.
Defined in
src/sdk/math/MathUtils.ts:55
hardSign
▸ hardSign(n
): number
Gets the sign of a number, including 0.
Parameters
Name | Type | Description |
---|---|---|
n | number | The number to get the sign of. |
Returns
number
1.0 if the number is positive, +0 or Infinity; -1.0 if the number is negative, -0 or -Infinity; NaN if the number is NaN
Defined in
src/sdk/math/MathUtils.ts:141
lerp
▸ lerp(x
, x0
, x1
, y0
, y1
, clampStart?
, clampEnd?
): number
Linearly interpolates a keyed value along one dimension.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
x | number | undefined | The key of the value to interpolate. |
x0 | number | undefined | The key of the first known value. |
x1 | number | undefined | The key of the second known value. |
y0 | number | undefined | The first known value. |
y1 | number | undefined | The second known value. |
clampStart | boolean | false | Whether to clamp the interpolated value to the first known value. Defaults to false. |
clampEnd | boolean | false | Whether to clamp the interpolated value to the second known value. Defaults to false. |
Returns
number
The interpolated value corresponding to the specified key.
Defined in
src/sdk/math/MathUtils.ts:100
lerpVector
▸ lerpVector(out
, x
, x0
, x1
, y0
, y1
, clampStart?
, clampEnd?
): Float64Array
Linearly interpolates a keyed vector along one dimension. If the known vectors and the result vector have unequal lengths, then only the components shared by all vectors are interpolated in the result.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
out | Float64Array | undefined | The object to which to write the result. |
x | number | undefined | The key of the vector to interpolate. |
x0 | number | undefined | The key of the first known vector. |
x1 | number | undefined | The key of the second known vector. |
y0 | ArrayLike <number > | undefined | The first known vector. |
y1 | ArrayLike <number > | undefined | The second known vector. |
clampStart | boolean | false | Whether to clamp the components of the interpolated vector to those of the first known vector. Defaults to false. |
clampEnd | boolean | false | Whether to clamp the components of the interpolated vector to those of the second known vector. Defaults to false. |
Returns
Float64Array
The interpolated vector corresponding to the specified key.
Defined in
src/sdk/math/MathUtils.ts:124
round
▸ round(value
, precision?
): number
Rounds a number.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | number | undefined | The number to round. |
precision | number | 1 | The precision with which to round. Defaults to 1 . |
Returns
number
The rounded number.
Defined in
src/sdk/math/MathUtils.ts:35