Math Utility Functions
Configuration, numeric comparisons, angle conversions, and array helpers for core math.
Usageโ
import {config, equals} from '@math.gl/core/matrix';
Setting configuration
import {config} from '@math.gl/core/matrix';
config.EPSILON = 1e-12;
config.debug = true;
config.printRowMajor = true;
config.precision = 4;
Functionsโ
configureโ
configure(options)
Merge options into the shared global configuration and return it. Call configure({}) to read the current configuration.
checkNumberโ
checkNumber(value)
formatValueโ
formatValue(value, {precision = config.precision} = {})
isArrayโ
Returns true if value is either an array or a typed array
isArray(value)
Note: does not return true for ArrayBuffers and DataViews
cloneโ
clone(array)
Call the input's clone() method when present, otherwise copy it with slice().
toRadiansโ
toRadians(degrees)
Works on single values and vectors
toDegreesโ
toDegrees(radians)
Works on single values and vectors
safeModโ
safeMod(dividend, divisor)
Returns a modulo result that follows the sign of the divisor, including when the dividend is negative.
normalizeAngleโ
normalizeAngle(angle, range)
Normalizes an angle in radians. range is either:
'zero-to-two-pi'for the range from 0 to 2ฯ'negative-pi-to-pi'for the range from -ฯ to ฯ
equalsโ
equals(a, b, epsilon)
- Works on single values and vectors
- Numeric values need to be closer than
config.EPSILON - Objects will be compared with their
.equals()method if present.
exactEqualsโ
exactEquals(a, b)
- Works on single values and vectors.
- Numeric values need to be exactly identical
- Objects will be compared with their
.exactEquals()method if present.
GLSL equivalentsโ
radiansโ
radians(degrees)
GLSL equivalent: Works on single values and vectors
degreesโ
degrees(radians)
GLSL equivalent: Works on single values and vectors
clampโ
clamp(value, min, max)
Remarksโ
- When setting global configs, you may need to consider the order of code loadint when using
importsandrequires
equals and exactEqualsโ
equals(a, b, epsilon?) compares scalars or arrays with a relative/absolute tolerance. exactEquals(a, b) compares values directly. See floating point.