0.1.2 • Published 5 years ago

@internet/maths v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Maths utilities

:books: Documentation | :globe_with_meridians: Internet modules

Requirements

Module Installation

# using npm
$ npm install --save @internet/maths

# or using yarn
$ yarn add @internet/maths

API

Example

import { mod, map, lerp, ... } from '@internet/maths'

API

maths.mod(dividend, divisor) ⇒ number

Perform a modulo operation.

Kind: static method of maths
Returns: number - Result of the modulo operation

ParamTypeDescription
dividendnumberA dividend
divisornumberA divisor

Example

const resut = mod(-1, 5) // return 4

maths.map(value, start1, stop1, start2, stop2) ⇒ number

Re-maps a number from one range to another.

Kind: static method of maths

ParamTypeDescription
valuenumberThe incoming value to be converted
start1numberLower bound of the value's current range
stop1numberUpper bound of the value's current range
start2numberLower bound of the value`'s target range
stop2numberUpper bound of the value's target range

maths.clamp(value, min, max) ⇒ number

Constrains a value to not exceed a maximum and minimum value.

Kind: static method of maths

ParamTypeDescription
valuenumberThe value to constrain
minnumberMinimum limit
maxnumberMaximum limit

maths.norm(value, min, max) ⇒ number

Normalizes a number from another range into a value between 0 and 1.

Kind: static method of maths
Returns: number - Normalized value

ParamTypeDescription
valuenumberThe incoming value to be converted
minnumberLower bound of the value's current range
maxnumberUpper bound of the value's current range

maths.lerp(start, end, amount) ⇒ number

Perform a linear interpolation between two values. Equivalent of mix in GLSL.

Kind: static method of maths
Returns: number - Lerped value

ParamTypeDescription
startnumberStart of the range in which to interpolate
endnumberEnd of the range in which to interpolate
amountnumberAmount to lerp between the two number (from 0 to 1)

maths.damp(source, target, smoothing, dt) ⇒ number

Frame-rate aware damping function

Kind: static method of maths
Returns: number - Damped value

ParamTypeDescription
sourcenumberInitial value
targetnumberTarget value
smoothingnumberSmoothing rate
dtnumberDelta-time (in milliseconds)

maths.dist(x1, y1, x2, y2) ⇒ number

Calculates the distance between two points (2D)

Kind: static method of maths
Returns: number - Distance

ParamTypeDescription
x1numberx-coordinate of the first point
y1numbery-coordinate of the first point
x2numberx-coordinate of the second point
y2numbery-coordinate of the second point

maths.sqdist(x1, y1, x2, y2) ⇒ number

Calculates the squared distance between two points (2D)

Kind: static method of maths
Returns: number - Distance

ParamTypeDescription
x1numberx-coordinate of the first point
y1numbery-coordinate of the first point
x2numberx-coordinate of the second point
y2numbery-coordinate of the second point

maths.ang(x1, y1, x2, y2) ⇒ number

Calculates the angle between two points (2D)

Kind: static method of maths
Returns: number - Angle (in Radians)

ParamTypeDescription
x1numberx-coordinate of the first point
y1numbery-coordinate of the first point
x2numberx-coordinate of the second point
y2numbery-coordinate of the second point

maths.polarToCart(radius, angle) ⇒ array

Calculates the angle between two points (2D)

Kind: static method of maths
Returns: array - Array containing the cartesian coordinates x, y

ParamTypeDescription
radiusnumberRadius / Distance
anglenumberAngle

maths.radToDeg(angle) ⇒ number

Convert angle from radians to degrees

Kind: static method of maths
Returns: number - Angle in degree

ParamTypeDescription
anglenumberAngle in radian

maths.degToRad(angle) ⇒ number

Convert angle from degrees to radians

Kind: static method of maths
Returns: number - Angle in radian

ParamTypeDescription
anglenumberAngle in degree

maths.mean(values) ⇒ number

Get the mean average of values

Kind: static method of maths
Returns: number - mean value

ParamType
valuesarray

maths.median(values) ⇒ number

Get the median average of values

Kind: static method of maths
Returns: number - median value

ParamType
valuesarray

0.1.2

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago