Num

Num class provides static helper functions for basic numeric operations.

Class in src/Num.ts

Methods

STATIC average ( pts )

Average a group of numeric arrays

parameters
pts: PtLikeIterable

a Group or an Iterable

returns
Pt

a Pt of averages

source

STATIC boundValue ( val, min, max )

Different from Num.clamp in that the value out-of-bound will be "looped back" to the other end.

parameters
val: number

value to bound

min: number

min value

max: number

max value

returns
number

example

boundValue(361, 0, 360) will return 1

source

STATIC clamp ( val, min, max )

Clamp values between min and max.

parameters
val: number

value to clamp

min: number

min value

max: number

max value

returns
number

source

STATIC cycle ( t, method )

Given a value between 0 to 1, returns a value that cycles between 0 -> 1 -> 0 using the provided shaping method.

parameters
t: number

a value between 0 to 1

method: Fn(t:number) (default value: Shaping.sineInOut)

a shaping method. Default to Shaping.sineInOut.

returns
number

a value between 0 to 1

source

STATIC equals ( a, b, threshold )

Check if two numbers are equal or almost equal within a threshold.

parameters
a: number

number a

b: number

number b

threshold: number (default value: 0.00001)

threshold value that specifies the minimum difference within which the two numbers are considered equal

returns
boolean

source

STATIC lerp ( a, b, t )

Calculate linear interpolation between 2 values.

parameters
a: number

start value

b: number

end value

t: number

an interpolation value, usually between 0 to 1

returns
number

source

STATIC mapToRange ( n, currA, currB, targetA, targetB )

Map a value from one range to another.

parameters
n: number

a value in the first range

currA: number

currB: number

targetA: number

targetB: number

returns
number

a remapped value in the second range

source

STATIC normalizeValue ( n, a, b )

Normalize a value within a range.

parameters
n: number

the value to normalize

a: number

range value 1

b: number

range value 1

returns
number

source

STATIC random ( )

Return a random number between 0 and 1 from a seed, if the seed is not defined it uses Math.random

returns
number

a number between 0 and 1

source

STATIC randomPt ( a, b )

Get a random Pt within the range defined by either 1 or 2 Pt

parameters
a: PtLike

the range if only one Pt is used, or the start of the range if two Pt were used

b: PtLike

optional Pt to define the end of the range

returns
Pt

source

STATIC randomRange ( a, b )

Get a random number within a range.

parameters
a: number

range value 1

b: number (default value: 0)

range value 2

returns
number

source

STATIC seed ( seed )

Seed the pseudorandom generator.

parameters
seed: string

seed string

returns
void

source

STATIC sum ( pts )

Sum a group of numeric arrays.

parameters
pts: PtLikeIterable

a Group or an Iterable

returns
Pt

a Pt of the dimensional sums

source

STATIC within ( p, a, b )

Check if a value is within two other values

parameters
p: number

value to check

a: number

first bounding value

b: number

second bounding value

returns
boolean

source