Methods
MathUtils.absClamp(value: number, min: number, max: number)
Limits the absolute value of a number between two positive numbers, then sets it to its original sign.
Arguments:
| value: number | The value to limit. |
| min: number | The minimum bound. If the absolute value of the specified value is less than this number, it is set to it. |
| max: number | The maximum bound. If the absolute value of the specified value is greater than this number, it is set to it. |
Returns:
| result: number | The new limited number. |
MathUtils.absMax(a: number, b: number)
Returns the number further from zero.
Arguments:
| a: number | The first number to compare. |
| b: number | The second number to compare. |
Returns:
| result: number | The specified number that was further from zero than the other. |
MathUtils.absMin(a: number, b: number)
Returns the number closer to zero.
Arguments:
| a: number | The first number to compare. |
| b: number | The second number to compare. |
Returns:
| result: number | The specified number that was closer to zero than the other. |
MathUtils.angle(x1: number, y1: number, x2: number, y2: number)
Returns the angle from one point to another.
Arguments:
| x1: number | The horizontal position of the first point. |
| y1: number | The vertical position of the first point. |
| x2: number | The horizontal position of the second point. |
| y2: number | The vertical position of the second point. |
Returns:
| angle: number | The angle from the first point to the second point. |
MathUtils.angleDiff(a: number, b: number)
Returns the distance between two angles, properly accounting for wrapping around.
Arguments:
| a: number | The first angle to compare. |
| b: number | The second angle to compare. |
Returns:
| diff: number | The difference between the two angles. |
MathUtils.approach(val: number, target: number, amount: number)
Moves the specified value towards a target value by a specified amount, without exceeding the target.
If the target is less than the value, then the amount will be subtracted from the value instead to approach it.
Arguments:
| val: number | The initial value. |
| target: number | The target value to approach. |
| amount: number | The amount the initial value should approach the target by. |
Returns:
| result: number | The new value. If the value would have passed the target value, it will instead be set to the target. |
MathUtils.approachAngle(val: number, target: number, amount: number)
Moves the specified angle towards a target angle by a specified amount, properly accounting for wrapping around.
Will always approach in the direction with the shorter distance.
Arguments:
| val: number | The initial angle. |
| target: number | The target angle to approach. |
| amount: number | The amount the initial angle should approach the target by. |
Returns:
| result: number | The new angle. If the angle would have passed the target angle, it will instead be set to the target. |
MathUtils.ceilToMultiple(value: number, to: number)
Rounds a number up to the nearest multiple of a specified number.
Arguments:
| value: number | The value to round. |
| to: number | The multiple to round down to. |
Returns:
| result: number | The rounded value. |
MathUtils.clamp(val: number, min: number, max: number)
Clamps the specified values between 2 bounds.
Arguments:
| val: number | The value to limit. |
| min: number | The minimum bound. |
| max: number | The maximum bound. |
Returns:
| result: number | The clamped result. |
MathUtils.dist(x1: number, y1: number, x2: number, y2: number)
Returns the distance between two points.
Arguments:
| x1: number | The horizontal position of the first point. |
| y1: number | The vertical position of the first point. |
| x2: number | The horizontal position of the second point. |
| y2: number | The vertical position of the second point. |
Returns:
| dist: number | The linear distance from the first point to the second point. |
MathUtils.floorToMultiple(value: number, to: number)
Rounds a number down to the nearest multiple of a specified number.
Arguments:
| value: number | The value to round. |
| to: number | The multiple to round down to. |
Returns:
| result: number | The rounded value. |
MathUtils.isInteger(value: number)
Checks if a number is an integer.
Arguments:
| value: number | The number to check. |
Returns:
| is_integer: boolean | Whether the value is an integer or not. |
MathUtils.lerp(from: number, to: number, factor: number)
Returns a value between two numbers, determined by a percentage from 0 to 1.
Arguments:
| from: number | The start value of the range. |
| to: number | The end value of the range. |
| factor: number | The percentage (from 0 to 1) that determines the point on the specified range. |
Returns:
| result: number | The new value from the range. |
MathUtils.lerpAngle(from: number, to: number, factor: number)
Lerps between two angles properly accounting for wrap arounds
Arguments:
| from: number | The starting angle (in radians) |
| to: number | The target angle (in radians) |
| factor: number | The interpolation factor (0-1) |
Returns:
| result: number | The interpolated angle |
MathUtils.lerpPoint(x1: number, y1: number, x2: number, y2: number, t: number)
Lerps between two coordinates.
Arguments:
| x1: number | The horizontal position of the first point. |
| y1: number | The vertical position of the first point. |
| x2: number | The horizontal position of the second point. |
| y2: number | The vertical position of the second point. |
| t: number | The percentage (from 0 to 1) that determines the new point on the specified range between the specified points. |
Returns:
| new_x: number | The horizontal position of the new point. |
| new_y: number | The vertical position of the new point. |
MathUtils.random(lower: number?, upper: number?)
Returns a randomly generated decimal value between the lower bound (inclusive) and the upper bound (exclusive).
If no upper bound is entered, it will be 1.
If no lower bound is entered, it will be 0.
Arguments:
| lower: number? | The lower bound. |
| upper: number? | The upper bound. |
Returns:
| value: number | The new random value. |
MathUtils.randomInt(lower: integer?, upper: integer)
Returns a randomly generated integer value between the lower bound (inclusive) and the upper bound (exclusive).
If no lower bound is entered, it will be 0.
Arguments:
| lower: integer? | The lower bound. |
| upper: integer | The upper bound. |
Returns:
| value: integer | The new random value. |
MathUtils.rangeMap(val: number, min_a: number, max_a: number, min_b: number, max_b: number)
Maps a value between a specified range to its equivalent position in a new range.
Does not automatically clamp.
Arguments:
| val: number | The initial value in the initial range. |
| min_a: number | The start value of the initial range. |
| max_a: number | The end value of the initial range. |
| min_b: number | The start value of the new range. |
| max_b: number | The end value of the new range. |
Returns:
| result: number | The value within the new range. |
MathUtils.round(value: number)
Rounds the specified value to the nearest integer.
Arguments:
| value: number | The value to round. |
Returns:
| result: number | The rounded value. |
MathUtils.roundFromZero(value: number)
Rounds the specified value to the nearest integer away from zero.
Arguments:
| value: number | The value to round. |
Returns:
| result: number | The rounded value. |
MathUtils.roundToMultiple(value: number, to: number)
Rounds the specified value to the nearest multiple of a specified number.
Arguments:
| value: number | The value to round. |
| to: number | The multiple to round down to. |
Returns:
| result: number | The rounded value. |
MathUtils.roundToZero(value: number)
Rounds the specified value to the nearest integer towards zero.
Arguments:
| value: number | The value to round. |
Returns:
| result: number | The rounded value. |
MathUtils.sign(num: number)
Returns the polarity of the specified value: -1 if it's negative, 1 if it's positive, and 0 otherwise.
Arguments:
| num: number | The value to check. |
Returns:
| sign: number | The sign of the value. |
MathUtils.wrap(val: number, min: number, max: number)
Limits the specified value to be between 2 bounds, wrapping around if it exceeds it.
Arguments:
| val: number | The value to wrap. |
| min: number | The minimum bound, inclusive. |
| max: number | The maximum bound, exclusive. |
Returns:
| result: number | The new wrapped number. |
MathUtils.wrapIndex(val: integer, length: integer)
Similar to MathUtils.wrap, intended to be used for wrapping a table index.
See: MathUtils.wrap
Arguments:
| val: integer | The value to wrap. |
| length: integer | The length of the table to wrap the index around. |
Returns:
| result: integer | The new wrapped index. |
MathUtils.xor(...: any)
XOR (eXclusive OR) logic operation
Arguments:
| ...: any | [conditions] |
Returns:
| 1: boolean |