Skip to content

@feds01/graphika


@feds01/graphika / utils/number

utils/number ​

Variables ​

TWO_PI ​

ts
const TWO_PI: number;

Defined in: utils/number.ts:15

Pre-computed constant for 2π, commonly used in arc/circle drawing.

Functions ​

clamp() ​

ts
function clamp(
   num, 
   min, 
   max
): number;

Defined in: utils/number.ts:25

Returns a number whose value is limited to the given range.

Parameters ​

ParameterTypeDescription
numnumber-
minnumberThe lower boundary of the output range.
maxnumberThe upper boundary of the output range.

Returns ​

number

A number in the range [min, max].


floor() ​

ts
function floor(num, dp): number;

Defined in: utils/number.ts:55

Function to floor a number to the nearest boundary. For example, floor a 5 to a boundary of 8 would round the number to 0. Flooring 11 with boundary of 8 would floor it to 8.

Parameters ​

ParameterTypeDescription
numnumberA number that is to be floored to the nearest number (with the same parity as the specified boundary).
dpnumber-

Returns ​

number

the original number that is floored.


isNum() ​

ts
function isNum(o): o is number;

Defined in: utils/number.ts:64

Check if the given object is a number and is not NaN.

Parameters ​

ParameterTypeDescription
ounknownThe object to check if it is a number.

Returns ​

o is number


lerp() ​

ts
function lerp(
   a, 
   b, 
   t
): number;

Defined in: utils/number.ts:76

Linear interpolation between two values.

Parameters ​

ParameterTypeDescription
anumberStart value.
bnumberEnd value.
tnumberInterpolation factor (0-1).

Returns ​

number

Interpolated value between a and b.


round() ​

ts
function round(num, bound): number;

Defined in: utils/number.ts:37

Function to round a number to the nearest boundary. For example, round a 5 to a boundary of 8 would round the number to 8. Rounding the number 11 with a boundary of 8 would round the number down to 8.

Parameters ​

ParameterTypeDescription
numnumberA number that is to be rounded to the nearest number (with the same parity as the specified boundary).
boundnumberThe specified boundary that the number should be rounded to.

Returns ​

number

Released under the ISC License.