Compares a
and b
and returns:
a
< b
;a
> b
;a
is equal to b
.The easing function that receives t
∈ [0, 1] and return a mapped value.
Bitwise AND operator for large unsigned integers.
Returns -1 if a
< b
, 1 if a
> b
and 0 otherwise.
Searches the specified array xs
for the specified value x
using the binary search algorithm. The array must be
sorted into ascending order according to the natural ordering of its elements prior to making this call. If it is
not sorted, the results are undefined.
The array to be searched.
The value to be searched for.
The callback that defines the sort order. If omitted, the array elements are compared using comparison operators.
The index of the searched value, if it is contained in the array; otherwise, -(insertion point) - 1. The insertion point is defined as the point at which the searched value would be inserted into the array: the index of the first element greater than the searched value, or array length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be ≥ 0 if and only if the searched value is found.
Converts number to non-NaN 8-bit unsigned integer.
If value
is a function then the invocation result is returned. Otherwise value
is returned as is.
Clamps x
to range [a
, b
].
Range can be inverse.
Clamps x
to range [0, 1].
Returns the closest value to x
from arr
.
If arr
is empty then x
is returned as is.
closest(1.8, [0, 3, 6]) // → 3
Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.
The type of the destination array.
The source array.
The destination array.
The start position in the source array.
The start position in the destination array.
The number of elements to copy.
The destination array.
Computes cubic splines for given pivot points.
Note: This function doesn't do any checks of arguments for performance reasons.
const splines = createCSplines(xs, ys, xs.length);
The array of X coordinates of pivot points in ascending order, length must be at least 2.
The array of corresponding Y coordinates of pivot points.
The number of pivot points, usually equals xs.length
.
Mutable array that would be populated with spline components, length must be at least 3 * n
.
The splines
array.
Computes monotonous splines for xs
and ys
that prevents overshoot of interpolated values.
Note: This function doesn't do any checks of arguments for performance reasons.
const splines = createCSplinesMonot(xs, ys, xs.length);
The array of X coordinates of pivot points in ascending order, length must be at least 2.
The array of corresponding Y coordinates of pivot points.
The number of pivot points, usually equals xs.length
.
Mutable array that would be populated with spline components, length must be at least 3 * n - 2
.
The splines
array.
Returns a natural cubic spline interpolation function for given pivot points.
Notes: Don't mutate xs
and ys
arrays after creating this function since data from these arrays is read during
interpolation.
const f = cspline(xs, ys);
const y = f(x);
The array of X coordinates of pivot points in ascending order.
The array of corresponding Y coordinates of pivot points.
The function that takes X coordinate and returns an interpolated Y coordinate.
Returns a monotonous cubic spline interpolation function for given pivot points, that prevent overshoot of interpolated values.
Notes: Don't mutate xs
and ys
arrays after creating this function since data from these arrays is read
during interpolation.
const f = csplineMonot(xs, ys);
const y = f(x);
The array of X coordinates of pivot points in ascending order.
The array of corresponding Y coordinates of pivot points.
The function that takes X coordinate and returns an interpolated Y coordinate.
Brings x
to the range [a
, b
] by adding or subtracting the range size |a
- b
|.
Range can be inverse.
cycle(12, 0, 10) // → 2
cycle(-333, 100, 33) // → 69
Converts degrees to radians.
Returns 1 if a
< b
, -1 if a
> b
and 0 otherwise.
Maps t
∈ [0, 1] exponentially to [0, 1].
The value to map.
Greater values produce more bent curve, f(t, 0) = t
.
Maps t
∈ [0, 1] logarithmically to [0, 1].
The value to map.
Greater values produce more bent curve, f(t, 0) = t
.
Flips x
∈ [a1
, b1
] to [a2
, b2
].
Ranges can be inverse.
Returns the square root of the sum of squares of its arguments.
Converts number to a non-NaN large integer.
Interpolates y
at x
using a natural cubic spline algorithm for a set of pivot points.
Note: This function doesn't do any checks of arguments for performance reasons.
const y = interpolateCSpline(xs, ys, x, xs.length, createCSplines(xs, ys, xs.length));
The array of X coordinates of pivot points in ascending order, length must be at least 2.
The array of corresponding Y coordinates of pivot points.
The X coordinate of interpolated point.
The number of pivot points, usually equals xs.length
.
The array of spline components, length must be 3 * n
.
Interpolated Y coordinate.
Computes y
at x
for a set of pivot points (xs
and ys
) using monotonous cubic spline interpolation that
prevents overshoot of interpolated values.
Note: This function doesn't do any checks of arguments for performance reasons.
const y = interpolateCSplineMonot(xs, ys, x, xs.length, createCSplinesMonot(xs, ys, xs.length));
The array of X coordinates of pivot points in ascending order, length must be al least 2.
The array of corresponding Y coordinates of pivot points.
The X coordinate of interpolated point.
The number of pivot points, usually equals xs.length
.
The array of spline components, length must be 3 * n - 2
.
Interpolated Y coordinate.
Returns true
if x
is in range [a
, b
].
Range can be inverse.
Returns true
if x
is in the eps
neighbourhood of a
.
Returns true
if x
is not null
and can be cast to a non-NaN number.
isNumeric(1); // → true
isNumeric('1'); // → true
isNumeric('1a'); // → false
isNumeric(null); // → false
Bitwise left shift operator for large unsigned integers.
left(0xAB, 8); // → 0xAB_00
// or
0xAB << 8;
Returns a linear interpolation function for given pivot points.
Notes: Don't mutate xs
and ys
arrays after creating this function since data from these arrays is read during
interpolation.
const f = lerp(xs, ys);
const y = f(x);
The array of X coordinates of pivot points in ascending order.
The array of corresponding Y coordinates of pivot points.
The function that takes X coordinate and returns an interpolated Y coordinate.
Returns the logarithm of x
with base n
.
logx(64, 2) // → 6
logx(1000, 10) // → 3
logx(99, 10) // → 1.99563519459755
logx(0.01, 10) // → -2
Bitwise OR operator for large unsigned integers.
Converts radians to degrees.
Creates an array of length n
and fills it with numbers in range [a
, b
].
The array length.
The minimum value or 0 if omitted.
The maximum value or 1 if omitted.
The easing function that receives t
∈ [0, 1] and return a mapped value.
The array of numbers.
Populates first n
elements of an array with numbers in range [a
, b
].
The array to populate.
The array length.
The minimum value.
The maximum value.
The easing function that receives t
∈ [0, 1] and return a mapped value.
The array of numbers.
Bitwise right shift operator for large unsigned integers.
right(0xAB_CD, 8); // → 0xAB
// or
0xAB_CD >> 8;
Returns either a positive or negative +/- 1, indicating the sign of a number passed into the argument. If the number
passed into sign()
is 0, it will return a +/- 0. Note that if the number is positive, an explicit (+) will not be
returned.
Rounds x
to the closest value that is divided by n
without any remainder.
snap(17, 10) // → 20
snap(-10, 3) // → -9
Sorts the array in-place using an optional comparator and invokes a callback after a pair of elements was swapped.
swap
or comparator
callbacks are guaranteed to be called after the elements of arr
are swapped.
The mutable array-like data structure that is sorted in-place.
The callback that is invoked with indices that were swapped.
The callback that defines the sort order. If omitted, the array elements are compared using comparison operators.
The arr
array.
Semantic shortcut for n
** 2.
Swaps i
and j
elements of the array arr
.
Returns the integer part of a number by removing any fractional digits.
Converts number to a non-NaN large unsigned integer.
Returns x
as is or n
if x
is NaN
.
Bitwise XOR operator for large unsigned integers.
Generated using TypeDoc
Infers a type of an array value.