Skip to main content

Math

Functions

clamp

clamp(num, min, max): number

Helper function to normalize a number, ensuring that it is within a certain range.

  • If num is less than min, then it will be clamped to min.
  • If num is greater than max, then it will be clamped to max.

Parameters

NameType
numnumber
minnumber
maxnumber

Returns

number

Defined in

packages/isaacscript-common/src/functions/math.ts:10


getAngleDifference

getAngleDifference(angle1, angle2): float

Parameters

NameType
angle1float
angle2float

Returns

float

Defined in

packages/isaacscript-common/src/functions/math.ts:14


getCircleDiscretizedPoints

getCircleDiscretizedPoints(centerPos, radius, numPoints, xMultiplier?, yMultiplier?, initialDirection?): ReadonlyArray<Readonly<Vector>>

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

NameTypeDefault valueDescription
centerPosVectorundefinedA position that represents the center of the center to get the points from.
radiusfloatundefinedThe length of the radius of the circle.
numPointsintundefinedThe number of points on the circumference of the circle to get.
xMultipliernumber1An optional multiplier to get the points around an oval. Default is 1.
yMultipliernumber1An optional multiplier to get the points around an oval. Default is 1.
initialDirectionDirectionDirection.UPBy default, the first point on the circle will be on the top center, but this can be optionally changed by specifying this argument.

Returns

ReadonlyArray<Readonly<Vector>>

Defined in

packages/isaacscript-common/src/functions/math.ts:31


inRectangle

inRectangle(position, topLeft, bottomRight): boolean

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

NameType
positionVector
topLeftVector
bottomRightVector

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/math.ts:59


isCircleIntersectingRectangle

isCircleIntersectingRectangle(circleCenter, circleRadius, rectangleTopLeft, rectangleBottomRight): boolean

From: https://www.geeksforgeeks.org/check-if-any-point-overlaps-the-given-circle-and-rectangle/

Parameters

NameType
circleCenterVector
circleRadiusfloat
rectangleTopLeftVector
rectangleBottomRightVector

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/math.ts:75


isEven

isEven(num): boolean

Parameters

NameType
numint

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/math.ts:98


isOdd

isOdd(num): boolean

Parameters

NameType
numint

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/math.ts:103


lerp

lerp(a, b, pos): number

Parameters

NameType
anumber
bnumber
posfloat

Returns

number

Defined in

packages/isaacscript-common/src/functions/math.ts:108


lerpAngleDegrees

lerpAngleDegrees(aStart, aEnd, percent): number

Parameters

NameType
aStartnumber
aEndnumber
percentfloat

Returns

number

Defined in

packages/isaacscript-common/src/functions/math.ts:112


round

round(num, numDecimalPlaces?): float

If rounding fails, this function returns 0.

From: http://lua-users.org/wiki/SimpleRound

Parameters

NameTypeDefault valueDescription
numfloatundefinedThe number to round.
numDecimalPlacesnumber0Optional. Default is 0.

Returns

float

Defined in

packages/isaacscript-common/src/functions/math.ts:128


sign

sign(n): int

Parameters

NameType
nnumber

Returns

int

1 if n is positive, -1 if n is negative, or 0 if n is 0.

Defined in

packages/isaacscript-common/src/functions/math.ts:135


splitNumber

splitNumber(num, size, startAtZero?): ReadonlyArray<readonly [min: int, max: int]>

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

NameTypeDefault valueDescription
numintundefinedThe number to split into chunks. This must be a positive integer.
sizeintundefinedThe size of each chunk. This must be a positive integer.
startAtZerobooleanfalseWhether to start at 0. Defaults to false. If true, the chunks will start at 0 instead of 1.

Returns

ReadonlyArray<readonly [min: int, max: int]>

Defined in

packages/isaacscript-common/src/functions/math.ts:163


tanh

tanh(x): number

Parameters

NameType
xnumber

Returns

number

Defined in

packages/isaacscript-common/src/functions/math.ts:192