Skip to content

Math

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 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.

number

number

number

number


getAngleDifference(angle1, angle2): float

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

float

float

float


getCircleDiscretizedPoints(centerPos, radius, numPoints, xMultiplier?, yMultiplier?, initialDirection?): readonly Readonly<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.

Vector

A position that represents the center of the center to get the points from.

float

The length of the radius of the circle.

int

The number of points on the circumference of the circle to get.

number = 1

An optional multiplier to get the points around an oval. Default is 1.

number = 1

An optional multiplier to get the points around an oval. Default is 1.

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.

readonly Readonly<Vector>[]


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.

Vector

Vector

Vector

boolean


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/

Vector

float

Vector

Vector

boolean


isEven(num): boolean

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

int

boolean


isOdd(num): boolean

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

int

boolean


lerp(a, b, pos): number

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

number

number

float

number


lerpAngleDegrees(aStart, aEnd, percent): number

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

number

number

float

number


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

float

The number to round.

number = 0

Optional. Default is 0.

float


sign(n): int

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

number

int

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


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]

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.

boolean = false

Whether to start at 0. Defaults to false. If true, the chunks will start at 0 instead of 1.

readonly readonly [int, int][]


tanh(x): number

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

number

number