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.
@param value
— The value to limit.
@param min
— The minimum bound. If the absolute value of the specified value is less than this number, it is set to it.
@param max
— The maximum bound. If the absolute value of the specified value is greater than this number, it is set to it.
@return result
— The new limited number.
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.
@param a
— The first number to compare.
@param b
— The second number to compare.
@return result
— The specified number that was further from zero than the other.
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.
@param a
— The first number to compare.
@param b
— The second number to compare.
@return result
— The specified number that was closer to zero than the other.
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.
@param x1
— The horizontal position of the first point.
@param y1
— The vertical position of the first point.
@param x2
— The horizontal position of the second point.
@param y2
— The vertical position of the second point.
@return angle
— The angle from the first point to the second point.
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.
@param a
— The first angle to compare.
@param b
— The second angle to compare.
@return diff
— The difference between the two angles.
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.
@param val
— The initial value.
@param target
— The target value to approach.
@param amount
— The amount the initial value should approach the target by.
@return result
— The new value. If the value would have passed the target value, it will instead be set to the target.
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.
@param val
— The initial angle.
@param target
— The target angle to approach.
@param amount
— The amount the initial angle should approach the target by.
@return result
— The new angle. If the angle would have passed the target angle, it will instead be set to the target.
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.
@param value
— The value to round.
@param to
— The multiple to round down to.
@return result
— The rounded value.
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.
@param val
— The value to limit.
@param min
— The minimum bound.
@param max
— The maximum bound.
@return result
— The clamped result.
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.
@param x1
— The horizontal position of the first point.
@param y1
— The vertical position of the first point.
@param x2
— The horizontal position of the second point.
@param y2
— The vertical position of the second point.
@return dist
— The linear distance from the first point to the second point.
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.
@param value
— The value to round.
@param to
— The multiple to round down to.
@return result
— The rounded value.
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.
@param value
— The number to check.
@return is_integer
— Whether the value is an integer or not.
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.
@param to
— The start value of the range.
@param from
— The end value of the range.
@param factor
— The percentage (from 0 to 1) that determines the point on the specified range.
@return result
— The new value from the range.
Arguments:
from: number | The end value of the range. |
to: number | The start 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.lerpPoint(x1: number, y1: number, x2: number, y2: number, t: number)
Lerps between two coordinates.
@param x1
— The horizontal position of the first point.
@param y1
— The vertical position of the first point.
@param x2
— The horizontal position of the second point.
@param y2
— The vertical position of the second point.
@param t
— The percentage (from 0 to 1) that determines the new point on the specified range between the specified points.
@return new_x
— The horizontal position of the new point.
@return new_y
— The vertical position of the new point.
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.
@param upper
— The upper bound.
@param lower
— The lower bound.
@return value
— The new random value.
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.
@param upper
— The upper bound.
@param lower
— The lower bound.
@return value
— The new random value.
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.
@param val
— The initial value in the initial range.
@param min_a
— The start value of the initial range.
@param max_a
— The end value of the initial range.
@param min_b
— The start value of the new range.
@param max_b
— The end value of the new range.
@return result
— The value within the new range.
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.
@param value
— The value to round.
@return result
— The rounded value.
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.
@param value
— The value to round.
@return result
— The rounded value.
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.
@param value
— The value to round.
@param to
— The multiple to round down to.
@return result
— The rounded value.
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.
@param value
— The value to round.
@return result
— The rounded value.
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.
@param num
— The value to check.
@return sign
— The sign of the value.
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.
@param val
— The value to wrap.
@param min
— The minimum bound, inclusive.
@param max
— The maximum bound, exclusive.
@return result
— The new wrapped number.
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.
@param val
— The value to wrap.
@param length
— The length of the table to wrap the index around.
@return result
— The new wrapped 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
@param ...
— [conditions]
Arguments:
: any | [conditions] |
Returns:
1: boolean |