Math
Functions
clamp
▸ clamp(num, min, max): number
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
| Name | Type |
|---|---|
num | number |
min | number |
max | number |
Returns
number
Defined in
packages/isaacscript-common/src/functions/math.ts:10
getAngleDifference
▸ getAngleDifference(angle1, angle2): float
Parameters
| Name | Type |
|---|---|
angle1 | float |
angle2 | float |
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
| Name | Type | Default value | Description |
|---|---|---|---|
centerPos | Vector | undefined | A position that represents the center of the center to get the points from. |
radius | float | undefined | The length of the radius of the circle. |
numPoints | int | undefined | The number of points on the circumference of the circle to get. |
xMultiplier | number | 1 | An optional multiplier to get the points around an oval. Default is 1. |
yMultiplier | number | 1 | An optional multiplier to get the points around an oval. Default is 1. |
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
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
| Name | Type |
|---|---|
position | Vector |
topLeft | Vector |
bottomRight | Vector |
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
| Name | Type |
|---|---|
circleCenter | Vector |
circleRadius | float |
rectangleTopLeft | Vector |
rectangleBottomRight | Vector |
Returns
boolean
Defined in
packages/isaacscript-common/src/functions/math.ts:75
isEven
▸ isEven(num): boolean
Parameters
| Name | Type |
|---|---|
num | int |
Returns
boolean
Defined in
packages/isaacscript-common/src/functions/math.ts:98
isOdd
▸ isOdd(num): boolean
Parameters
| Name | Type |
|---|---|
num | int |
Returns
boolean
Defined in
packages/isaacscript-common/src/functions/math.ts:103
lerp
▸ lerp(a, b, pos): number
Parameters
| Name | Type |
|---|---|
a | number |
b | number |
pos | float |
Returns
number
Defined in
packages/isaacscript-common/src/functions/math.ts:108
lerpAngleDegrees
▸ lerpAngleDegrees(aStart, aEnd, percent): number
Parameters
| Name | Type |
|---|---|
aStart | number |
aEnd | number |
percent | float |
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
| Name | Type | Default value | Description |
|---|---|---|---|
num | float | undefined | The number to round. |
numDecimalPlaces | number | 0 | Optional. Default is 0. |
Returns
float
Defined in
packages/isaacscript-common/src/functions/math.ts:128
sign
▸ sign(n): int
Parameters
| Name | Type |
|---|---|
n | number |
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
| Name | Type | Default value | Description |
|---|---|---|---|
num | int | undefined | The number to split into chunks. This must be a positive integer. |
size | int | undefined | The size of each chunk. This must be a positive integer. |
startAtZero | boolean | false | Whether 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
| Name | Type |
|---|---|
x | number |
Returns
number