Skip to main content

Class: MathUtils

Defined in: utils/MathUtils.ts:2

Utility methods for numeric clamping and alignment

Constructors

Constructor

new MathUtils(): MathUtils

Returns

MathUtils

Methods

align()

static align(n, m): number

Defined in: utils/MathUtils.ts:26

Aligns a positive number n to the next multiple of m

If n is already a multiple of m, returns n. Otherwise, returns the smallest multiple of m that is greater than n.

Parameters

n

number

The non-negative number to align

m

number

The strictly positive multiple to align to

Returns

number

The aligned number

Throws

Error if n is negative, or if m is not strictly positive


clamp()

static clamp(value, min, max): number

Defined in: utils/MathUtils.ts:11

Clamps a value to the range [min, max]

Parameters

value

number

The value to clamp

min

number

Lower bound

max

number

Upper bound

Returns

number

The clamped value