Math
Functions
Section titled “Functions”clamp()
Section titled “clamp()”clamp(
num,min,max):number
Defined in: packages/isaacscript-common/src/functions/math.ts:10
Helper function to normalize a number, ensuring that it is within a certain range.
- If
numis less thanmin, then it will be clamped tomin. - If
numis greater thanmax, then it will be clamped tomax.
Parameters
Section titled “Parameters”number
number
number
Returns
Section titled “Returns”number
getAngleDifference()
Section titled “getAngleDifference()”getAngleDifference(
angle1,angle2):float
Defined in: packages/isaacscript-common/src/functions/math.ts:14
Parameters
Section titled “Parameters”angle1
Section titled “angle1”float
angle2
Section titled “angle2”float
Returns
Section titled “Returns”float
getCircleDiscretizedPoints()
Section titled “getCircleDiscretizedPoints()”getCircleDiscretizedPoints(
centerPos,radius,numPoints,xMultiplier?,yMultiplier?,initialDirection?): readonlyReadonly<Vector>[]
Defined in: packages/isaacscript-common/src/functions/math.ts:31
Helper function to get an array of equidistant points on the circumference around a circle. Useful for equally distributing things in a circle pattern.
Parameters
Section titled “Parameters”centerPos
Section titled “centerPos”Vector
A position that represents the center of the center to get the points from.
radius
Section titled “radius”float
The length of the radius of the circle.
numPoints
Section titled “numPoints”int
The number of points on the circumference of the circle to get.
xMultiplier?
Section titled “xMultiplier?”number = 1
An optional multiplier to get the points around an oval. Default is 1.
yMultiplier?
Section titled “yMultiplier?”number = 1
An optional multiplier to get the points around an oval. Default is 1.
initialDirection?
Section titled “initialDirection?”Direction = Direction.UP
By default, the first point on the circle will be on the top center, but this can be optionally changed by specifying this argument.
Returns
Section titled “Returns”readonly Readonly<Vector>[]
inRectangle()
Section titled “inRectangle()”inRectangle(
position,topLeft,bottomRight):boolean
Defined in: packages/isaacscript-common/src/functions/math.ts:59
Helper function to check if a given position is within a given rectangle.
This is an inclusive check, meaning that it will return true if the position is on the border of the rectangle.
Parameters
Section titled “Parameters”position
Section titled “position”Vector
topLeft
Section titled “topLeft”Vector
bottomRight
Section titled “bottomRight”Vector
Returns
Section titled “Returns”boolean
isCircleIntersectingRectangle()
Section titled “isCircleIntersectingRectangle()”isCircleIntersectingRectangle(
circleCenter,circleRadius,rectangleTopLeft,rectangleBottomRight):boolean
Defined in: packages/isaacscript-common/src/functions/math.ts:75
From: https://www.geeksforgeeks.org/check-if-any-point-overlaps-the-given-circle-and-rectangle/
Parameters
Section titled “Parameters”circleCenter
Section titled “circleCenter”Vector
circleRadius
Section titled “circleRadius”float
rectangleTopLeft
Section titled “rectangleTopLeft”Vector
rectangleBottomRight
Section titled “rectangleBottomRight”Vector
Returns
Section titled “Returns”boolean
isEven()
Section titled “isEven()”isEven(
num):boolean
Defined in: packages/isaacscript-common/src/functions/math.ts:98
Parameters
Section titled “Parameters”int
Returns
Section titled “Returns”boolean
isOdd()
Section titled “isOdd()”isOdd(
num):boolean
Defined in: packages/isaacscript-common/src/functions/math.ts:103
Parameters
Section titled “Parameters”int
Returns
Section titled “Returns”boolean
lerp()
Section titled “lerp()”lerp(
a,b,pos):number
Defined in: packages/isaacscript-common/src/functions/math.ts:108
Parameters
Section titled “Parameters”number
number
float
Returns
Section titled “Returns”number
lerpAngleDegrees()
Section titled “lerpAngleDegrees()”lerpAngleDegrees(
aStart,aEnd,percent):number
Defined in: packages/isaacscript-common/src/functions/math.ts:112
Parameters
Section titled “Parameters”aStart
Section titled “aStart”number
number
percent
Section titled “percent”float
Returns
Section titled “Returns”number
round()
Section titled “round()”round(
num,numDecimalPlaces?):float
Defined in: packages/isaacscript-common/src/functions/math.ts:128
If rounding fails, this function returns 0.
From: https://lua-users.org/wiki/SimpleRound
Parameters
Section titled “Parameters”float
The number to round.
numDecimalPlaces?
Section titled “numDecimalPlaces?”number = 0
Optional. Default is 0.
Returns
Section titled “Returns”float
sign()
Section titled “sign()”sign(
n):int
Defined in: packages/isaacscript-common/src/functions/math.ts:135
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”int
1 if n is positive, -1 if n is negative, or 0 if n is 0.
splitNumber()
Section titled “splitNumber()”splitNumber(
num,size,startAtZero?): readonly readonly [int,int][]
Defined in: packages/isaacscript-common/src/functions/math.ts:163
Breaks a number into chunks of a given size. This is similar to the String.split method, but
for a number instead of a string.
For example, splitNumber(90, 25) would return an array with four elements:
- [1, 25]
- [26, 50]
- [51, 75]
- [76, 90]
Parameters
Section titled “Parameters”int
The number to split into chunks. This must be a positive integer.
int
The size of each chunk. This must be a positive integer.
startAtZero?
Section titled “startAtZero?”boolean = false
Whether to start at 0. Defaults to false. If true, the chunks will start at 0 instead of 1.
Returns
Section titled “Returns”readonly readonly [int, int][]
tanh()
Section titled “tanh()”tanh(
x):number
Defined in: packages/isaacscript-common/src/functions/math.ts:192
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”number
