High-performance JavaScript library for vector and matrix mathematical operations optimized for WebGL applications and 3D graphics programming
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive 2D, 3D, and 4D vector mathematical operations including arithmetic, normalization, transformations, and interpolation. All vector operations follow consistent patterns with separate output parameters for maximum performance.
Operations for 2-component vectors commonly used in 2D graphics and UI calculations.
/**
* Creates a new, empty vec2
* @returns New vec2 initialized to [0, 0]
*/
function create(): vec2;
/**
* Creates a new vec2 initialized with given values
* @param x - X component
* @param y - Y component
* @returns New vec2 with specified values
*/
function fromValues(x: number, y: number): vec2;
/**
* Creates a new vec2 from an existing vector
* @param a - Vector to clone
* @returns New vec2 with copied values
*/
function clone(a: ReadonlyVec2): vec2;
/**
* Copy values from one vec2 to another
* @param out - Receiving vector
* @param a - Source vector
* @returns out parameter
*/
function copy(out: vec2, a: ReadonlyVec2): vec2;
/**
* Set components of a vec2
* @param out - Receiving vector
* @param x - X component
* @param y - Y component
* @returns out parameter
*/
function set(out: vec2, x: number, y: number): vec2;/**
* Adds two vec2s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function add(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2;
/**
* Subtracts vector b from vector a
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function subtract(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2;
/**
* Multiplies two vec2s component-wise
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function multiply(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2;
/**
* Divides two vec2s component-wise
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function divide(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2;
/**
* Scales a vec2 by a scalar number
* @param out - Receiving vector
* @param a - Vector to scale
* @param b - Amount to scale the vector by
* @returns out parameter
*/
function scale(out: vec2, a: ReadonlyVec2, b: number): vec2;
/**
* Adds two vec2s after scaling the second operand by a scalar value
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param scale - Amount to scale b by before adding
* @returns out parameter
*/
function scaleAndAdd(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, scale: number): vec2;/**
* Calculates the euclidean distance between two vec2s
* @param a - First vector
* @param b - Second vector
* @returns Distance between vectors
*/
function distance(a: ReadonlyVec2, b: ReadonlyVec2): number;
/**
* Calculates the squared euclidean distance between two vec2s
* @param a - First vector
* @param b - Second vector
* @returns Squared distance between vectors
*/
function squaredDistance(a: ReadonlyVec2, b: ReadonlyVec2): number;
/**
* Calculates the length of a vec2
* @param a - Vector to calculate length of
* @returns Length of the vector
*/
function length(a: ReadonlyVec2): number;
/**
* Calculates the squared length of a vec2
* @param a - Vector to calculate length of
* @returns Squared length of the vector
*/
function squaredLength(a: ReadonlyVec2): number;
/**
* Negates the components of a vec2
* @param out - Receiving vector
* @param a - Vector to negate
* @returns out parameter
*/
function negate(out: vec2, a: ReadonlyVec2): vec2;
/**
* Returns the inverse of the components of a vec2
* @param out - Receiving vector
* @param a - Vector to invert
* @returns out parameter
*/
function inverse(out: vec2, a: ReadonlyVec2): vec2;
/**
* Normalize a vec2
* @param out - Receiving vector
* @param a - Vector to normalize
* @returns out parameter
*/
function normalize(out: vec2, a: ReadonlyVec2): vec2;
/**
* Calculates the dot product of two vec2s
* @param a - First operand
* @param b - Second operand
* @returns Dot product of a and b
*/
function dot(a: ReadonlyVec2, b: ReadonlyVec2): number;
/**
* Computes the cross product of two vec2s
* @param out - Receiving vec3
* @param a - First operand
* @param b - Second operand
* @returns out parameter (as vec3)
*/
function cross(out: vec3, a: ReadonlyVec2, b: ReadonlyVec2): vec3;/**
* Transforms the vec2 with a mat2
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat2(out: vec2, a: ReadonlyVec2, m: ReadonlyMat2): vec2;
/**
* Transforms the vec2 with a mat2d
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat2d(out: vec2, a: ReadonlyVec2, m: ReadonlyMat2d): vec2;
/**
* Transforms the vec2 with a mat3
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat3(out: vec2, a: ReadonlyVec2, m: ReadonlyMat3): vec2;
/**
* Transforms the vec2 with a mat4
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat4(out: vec2, a: ReadonlyVec2, m: ReadonlyMat4): vec2;
/**
* Rotate a 2D vector
* @param out - Receiving vec2
* @param a - Vec2 point to rotate
* @param b - Origin of rotation
* @param rad - Angle of rotation in radians
* @returns out parameter
*/
function rotate(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, rad: number): vec2;/**
* Performs a linear interpolation between two vec2s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param t - Interpolation amount (0.0 - 1.0)
* @returns out parameter
*/
function lerp(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, t: number): vec2;
/**
* Get the angle between two 2D vectors
* @param a - First vector
* @param b - Second vector
* @returns Angle in radians
*/
function angle(a: ReadonlyVec2, b: ReadonlyVec2): number;
/**
* Get the signed angle between two 2D vectors
* @param a - First vector
* @param b - Second vector
* @returns Signed angle in radians
*/
function signedAngle(a: ReadonlyVec2, b: ReadonlyVec2): number;/**
* Math.ceil the components of a vec2
* @param out - Receiving vector
* @param a - Vector to ceil
* @returns out parameter
*/
function ceil(out: vec2, a: ReadonlyVec2): vec2;
/**
* Math.floor the components of a vec2
* @param out - Receiving vector
* @param a - Vector to floor
* @returns out parameter
*/
function floor(out: vec2, a: ReadonlyVec2): vec2;
/**
* Returns the minimum of two vec2s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function min(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2;
/**
* Returns the maximum of two vec2s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function max(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2;
/**
* Symmetric round the components of a vec2
* @param out - Receiving vector
* @param a - Vector to round
* @returns out parameter
*/
function round(out: vec2, a: ReadonlyVec2): vec2;
/**
* Set the components of a vec2 to zero
* @param out - Receiving vector
* @returns out parameter
*/
function zero(out: vec2): vec2;
/**
* Generates a random vector with the given scale
* @param out - Receiving vector
* @param scale - Length of the resulting vector. If omitted, a unit vector will be returned
* @returns out parameter
*/
function random(out: vec2, scale?: number): vec2;
/**
* Returns a string representation of a vector
* @param a - Vector to represent as a string
* @returns String representation of the vector
*/
function str(a: ReadonlyVec2): string;
/**
* Returns whether or not the vectors exactly have the same elements in the same position
* @param a - First vector
* @param b - Second vector
* @returns True if the vectors are equal, false otherwise
*/
function exactEquals(a: ReadonlyVec2, b: ReadonlyVec2): boolean;
/**
* Returns whether or not the vectors have approximately the same elements in the same position
* @param a - First vector
* @param b - Second vector
* @returns True if the vectors are equal, false otherwise
*/
function equals(a: ReadonlyVec2, b: ReadonlyVec2): boolean;
/**
* Perform some operation over an array of vec2s
* @param a - Array of vectors to iterate over
* @param stride - Number of elements between the start of each vec2. If 0 assumes tightly packed
* @param offset - Number of elements to skip at the beginning of the array
* @param count - Number of vec2s to iterate over. If 0 iterates over entire array
* @param fn - Function to call for each vector in the array
* @param arg - Additional argument to pass to fn
* @returns a parameter
*/
function forEach(a: any[], stride: number, offset: number, count: number, fn: Function, arg?: any): any[];// Common aliases for shorter code
const len: typeof length;
const sub: typeof subtract;
const mul: typeof multiply;
const div: typeof divide;
const dist: typeof distance;
const sqrDist: typeof squaredDistance;
const sqrLen: typeof squaredLength;Operations for 3-component vectors used extensively in 3D graphics, physics, and spatial calculations.
/**
* Creates a new, empty vec3
* @returns New vec3 initialized to [0, 0, 0]
*/
function create(): vec3;
/**
* Creates a new vec3 initialized with the given values
* @param x - X component
* @param y - Y component
* @param z - Z component
* @returns New vec3 with specified values
*/
function fromValues(x: number, y: number, z: number): vec3;
/**
* Creates a new vec3 from an existing vector
* @param a - Vector to clone
* @returns New vec3 with copied values
*/
function clone(a: ReadonlyVec3): vec3;
/**
* Copy values from one vec3 to another
* @param out - Receiving vector
* @param a - Source vector
* @returns out parameter
*/
function copy(out: vec3, a: ReadonlyVec3): vec3;
/**
* Set the components of a vec3
* @param out - Receiving vector
* @param x - X component
* @param y - Y component
* @param z - Z component
* @returns out parameter
*/
function set(out: vec3, x: number, y: number, z: number): vec3;/**
* Computes the cross product of two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function cross(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Performs a spherical linear interpolation between two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param t - Interpolation amount (0.0 - 1.0)
* @returns out parameter
*/
function slerp(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, t: number): vec3;
/**
* Performs a hermite interpolation between two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param c - Third operand
* @param d - Fourth operand
* @param t - Interpolation amount (0.0 - 1.0)
* @returns out parameter
*/
function hermite(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, c: ReadonlyVec3, d: ReadonlyVec3, t: number): vec3;
/**
* Performs a bezier interpolation between two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param c - Third operand
* @param d - Fourth operand
* @param t - Interpolation amount (0.0 - 1.0)
* @returns out parameter
*/
function bezier(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, c: ReadonlyVec3, d: ReadonlyVec3, t: number): vec3;/**
* Transforms the vec3 with a mat4
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat4(out: vec3, a: ReadonlyVec3, m: ReadonlyMat4): vec3;
/**
* Transforms the vec3 with a mat3
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat3(out: vec3, a: ReadonlyVec3, m: ReadonlyMat3): vec3;
/**
* Transforms the vec3 with a quat
* @param out - Receiving vector
* @param a - Vector to transform
* @param q - Quaternion to transform with
* @returns out parameter
*/
function transformQuat(out: vec3, a: ReadonlyVec3, q: ReadonlyQuat): vec3;
/**
* Rotate a 3D vector around the x-axis
* @param out - Receiving vec3
* @param a - Vec3 point to rotate
* @param b - Origin of rotation
* @param rad - Angle of rotation in radians
* @returns out parameter
*/
function rotateX(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, rad: number): vec3;
/**
* Rotate a 3D vector around the y-axis
* @param out - Receiving vec3
* @param a - Vec3 point to rotate
* @param b - Origin of rotation
* @param rad - Angle of rotation in radians
* @returns out parameter
*/
function rotateY(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, rad: number): vec3;
/**
* Rotate a 3D vector around the z-axis
* @param out - Receiving vec3
* @param a - Vec3 point to rotate
* @param b - Origin of rotation
* @param rad - Angle of rotation in radians
* @returns out parameter
*/
function rotateZ(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, rad: number): vec3;/**
* Calculates the length of a vec3
* @param a - Vector to calculate length of
* @returns Length of the vector
*/
function length(a: ReadonlyVec3): number;
/**
* Adds two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function add(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Subtracts vector b from vector a
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function subtract(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Multiplies two vec3s component-wise
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function multiply(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Divides two vec3s component-wise
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function divide(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Scales a vec3 by a scalar number
* @param out - Receiving vector
* @param a - Vector to scale
* @param b - Amount to scale the vector by
* @returns out parameter
*/
function scale(out: vec3, a: ReadonlyVec3, b: number): vec3;
/**
* Adds two vec3s after scaling the second operand by a scalar value
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param scale - Amount to scale b by before adding
* @returns out parameter
*/
function scaleAndAdd(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, scale: number): vec3;
/**
* Negates the components of a vec3
* @param out - Receiving vector
* @param a - Vector to negate
* @returns out parameter
*/
function negate(out: vec3, a: ReadonlyVec3): vec3;
/**
* Returns the inverse of the components of a vec3
* @param out - Receiving vector
* @param a - Vector to invert
* @returns out parameter
*/
function inverse(out: vec3, a: ReadonlyVec3): vec3;/**
* Calculates the euclidean distance between two vec3s
* @param a - First vector
* @param b - Second vector
* @returns Distance between vectors
*/
function distance(a: ReadonlyVec3, b: ReadonlyVec3): number;
/**
* Calculates the squared euclidean distance between two vec3s
* @param a - First vector
* @param b - Second vector
* @returns Squared distance between vectors
*/
function squaredDistance(a: ReadonlyVec3, b: ReadonlyVec3): number;
/**
* Calculates the squared length of a vec3
* @param a - Vector to calculate length of
* @returns Squared length of the vector
*/
function squaredLength(a: ReadonlyVec3): number;
/**
* Normalize a vec3
* @param out - Receiving vector
* @param a - Vector to normalize
* @returns out parameter
*/
function normalize(out: vec3, a: ReadonlyVec3): vec3;
/**
* Calculates the dot product of two vec3s
* @param a - First operand
* @param b - Second operand
* @returns Dot product of a and b
*/
function dot(a: ReadonlyVec3, b: ReadonlyVec3): number;
/**
* Get the angle between two 3D vectors
* @param a - First vector
* @param b - Second vector
* @returns Angle in radians
*/
function angle(a: ReadonlyVec3, b: ReadonlyVec3): number;/**
* Performs a linear interpolation between two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param t - Interpolation amount (0.0 - 1.0)
* @returns out parameter
*/
function lerp(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3, t: number): vec3;/**
* Math.ceil the components of a vec3
* @param out - Receiving vector
* @param a - Vector to ceil
* @returns out parameter
*/
function ceil(out: vec3, a: ReadonlyVec3): vec3;
/**
* Math.floor the components of a vec3
* @param out - Receiving vector
* @param a - Vector to floor
* @returns out parameter
*/
function floor(out: vec3, a: ReadonlyVec3): vec3;
/**
* Returns the minimum of two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function min(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Returns the maximum of two vec3s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function max(out: vec3, a: ReadonlyVec3, b: ReadonlyVec3): vec3;
/**
* Symmetric round the components of a vec3
* @param out - Receiving vector
* @param a - Vector to round
* @returns out parameter
*/
function round(out: vec3, a: ReadonlyVec3): vec3;
/**
* Set the components of a vec3 to zero
* @param out - Receiving vector
* @returns out parameter
*/
function zero(out: vec3): vec3;
/**
* Generates a random vector with the given scale
* @param out - Receiving vector
* @param scale - Length of the resulting vector. If omitted, a unit vector will be returned
* @returns out parameter
*/
function random(out: vec3, scale?: number): vec3;
/**
* Returns a string representation of a vector
* @param a - Vector to represent as a string
* @returns String representation of the vector
*/
function str(a: ReadonlyVec3): string;
/**
* Returns whether or not the vectors exactly have the same elements in the same position
* @param a - First vector
* @param b - Second vector
* @returns True if the vectors are equal, false otherwise
*/
function exactEquals(a: ReadonlyVec3, b: ReadonlyVec3): boolean;
/**
* Returns whether or not the vectors have approximately the same elements in the same position
* @param a - First vector
* @param b - Second vector
* @returns True if the vectors are equal, false otherwise
*/
function equals(a: ReadonlyVec3, b: ReadonlyVec3): boolean;
/**
* Perform some operation over an array of vec3s
* @param a - Array of vectors to iterate over
* @param stride - Number of elements between the start of each vec3. If 0 assumes tightly packed
* @param offset - Number of elements to skip at the beginning of the array
* @param count - Number of vec3s to iterate over. If 0 iterates over entire array
* @param fn - Function to call for each vector in the array
* @param arg - Additional argument to pass to fn
* @returns a parameter
*/
function forEach(a: any[], stride: number, offset: number, count: number, fn: Function, arg?: any): any[];// Common aliases for shorter code
const len: typeof length;
const sub: typeof subtract;
const mul: typeof multiply;
const div: typeof divide;
const dist: typeof distance;
const sqrDist: typeof squaredDistance;
const sqrLen: typeof squaredLength;Operations for 4-component vectors used in homogeneous coordinates and 4D transformations.
/**
* Creates a new, empty vec4
* @returns New vec4 initialized to [0, 0, 0, 0]
*/
function create(): vec4;
/**
* Creates a new vec4 initialized with given values
* @param x - X component
* @param y - Y component
* @param z - Z component
* @param w - W component
* @returns New vec4 with specified values
*/
function fromValues(x: number, y: number, z: number, w: number): vec4;
/**
* Copy values from one vec4 to another
* @param out - Receiving vector
* @param a - Source vector
* @returns out parameter
*/
function copy(out: vec4, a: ReadonlyVec4): vec4;
/**
* Set the components of a vec4
* @param out - Receiving vector
* @param x - X component
* @param y - Y component
* @param z - Z component
* @param w - W component
* @returns out parameter
*/
function set(out: vec4, x: number, y: number, z: number, w: number): vec4;/**
* Computes the 4-dimensional cross product of three vec4s
* @param out - Receiving vector
* @param u - First operand
* @param v - Second operand
* @param w - Third operand
* @returns out parameter
*/
function cross(out: vec4, u: ReadonlyVec4, v: ReadonlyVec4, w: ReadonlyVec4): vec4;/**
* Transforms the vec4 with a mat4
* @param out - Receiving vector
* @param a - Vector to transform
* @param m - Matrix to transform with
* @returns out parameter
*/
function transformMat4(out: vec4, a: ReadonlyVec4, m: ReadonlyMat4): vec4;
/**
* Transforms the vec4 with a quat
* @param out - Receiving vector
* @param a - Vector to transform
* @param q - Quaternion to transform with
* @returns out parameter
*/
function transformQuat(out: vec4, a: ReadonlyVec4, q: ReadonlyQuat): vec4;/**
* Creates a new vec4 initialized with values from an existing vector
* @param a - Vector to clone
* @returns New vec4 with copied values
*/
function clone(a: ReadonlyVec4): vec4;
/**
* Calculates the length of a vec4
* @param a - Vector to calculate length of
* @returns Length of the vector
*/
function length(a: ReadonlyVec4): number;
/**
* Adds two vec4s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function add(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4): vec4;
/**
* Subtracts vector b from vector a
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function subtract(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4): vec4;
/**
* Multiplies two vec4s component-wise
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function multiply(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4): vec4;
/**
* Divides two vec4s component-wise
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function divide(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4): vec4;
/**
* Scales a vec4 by a scalar number
* @param out - Receiving vector
* @param a - Vector to scale
* @param b - Amount to scale the vector by
* @returns out parameter
*/
function scale(out: vec4, a: ReadonlyVec4, b: number): vec4;
/**
* Adds two vec4s after scaling the second operand by a scalar value
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param scale - Amount to scale b by before adding
* @returns out parameter
*/
function scaleAndAdd(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4, scale: number): vec4;
/**
* Negates the components of a vec4
* @param out - Receiving vector
* @param a - Vector to negate
* @returns out parameter
*/
function negate(out: vec4, a: ReadonlyVec4): vec4;
/**
* Returns the inverse of the components of a vec4
* @param out - Receiving vector
* @param a - Vector to invert
* @returns out parameter
*/
function inverse(out: vec4, a: ReadonlyVec4): vec4;/**
* Calculates the euclidean distance between two vec4s
* @param a - First vector
* @param b - Second vector
* @returns Distance between vectors
*/
function distance(a: ReadonlyVec4, b: ReadonlyVec4): number;
/**
* Calculates the squared euclidean distance between two vec4s
* @param a - First vector
* @param b - Second vector
* @returns Squared distance between vectors
*/
function squaredDistance(a: ReadonlyVec4, b: ReadonlyVec4): number;
/**
* Calculates the squared length of a vec4
* @param a - Vector to calculate length of
* @returns Squared length of the vector
*/
function squaredLength(a: ReadonlyVec4): number;
/**
* Normalize a vec4
* @param out - Receiving vector
* @param a - Vector to normalize
* @returns out parameter
*/
function normalize(out: vec4, a: ReadonlyVec4): vec4;
/**
* Calculates the dot product of two vec4s
* @param a - First operand
* @param b - Second operand
* @returns Dot product of a and b
*/
function dot(a: ReadonlyVec4, b: ReadonlyVec4): number;/**
* Performs a linear interpolation between two vec4s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @param t - Interpolation amount (0.0 - 1.0)
* @returns out parameter
*/
function lerp(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4, t: number): vec4;/**
* Math.ceil the components of a vec4
* @param out - Receiving vector
* @param a - Vector to ceil
* @returns out parameter
*/
function ceil(out: vec4, a: ReadonlyVec4): vec4;
/**
* Math.floor the components of a vec4
* @param out - Receiving vector
* @param a - Vector to floor
* @returns out parameter
*/
function floor(out: vec4, a: ReadonlyVec4): vec4;
/**
* Returns the minimum of two vec4s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function min(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4): vec4;
/**
* Returns the maximum of two vec4s
* @param out - Receiving vector
* @param a - First operand
* @param b - Second operand
* @returns out parameter
*/
function max(out: vec4, a: ReadonlyVec4, b: ReadonlyVec4): vec4;
/**
* Symmetric round the components of a vec4
* @param out - Receiving vector
* @param a - Vector to round
* @returns out parameter
*/
function round(out: vec4, a: ReadonlyVec4): vec4;
/**
* Set the components of a vec4 to zero
* @param out - Receiving vector
* @returns out parameter
*/
function zero(out: vec4): vec4;
/**
* Generates a random vector with the given scale
* @param out - Receiving vector
* @param scale - Length of the resulting vector. If omitted, a unit vector will be returned
* @returns out parameter
*/
function random(out: vec4, scale?: number): vec4;
/**
* Returns a string representation of a vector
* @param a - Vector to represent as a string
* @returns String representation of the vector
*/
function str(a: ReadonlyVec4): string;
/**
* Returns whether or not the vectors exactly have the same elements in the same position
* @param a - First vector
* @param b - Second vector
* @returns True if the vectors are equal, false otherwise
*/
function exactEquals(a: ReadonlyVec4, b: ReadonlyVec4): boolean;
/**
* Returns whether or not the vectors have approximately the same elements in the same position
* @param a - First vector
* @param b - Second vector
* @returns True if the vectors are equal, false otherwise
*/
function equals(a: ReadonlyVec4, b: ReadonlyVec4): boolean;
/**
* Perform some operation over an array of vec4s
* @param a - Array of vectors to iterate over
* @param stride - Number of elements between the start of each vec4. If 0 assumes tightly packed
* @param offset - Number of elements to skip at the beginning of the array
* @param count - Number of vec4s to iterate over. If 0 iterates over entire array
* @param fn - Function to call for each vector in the array
* @param arg - Additional argument to pass to fn
* @returns a parameter
*/
function forEach(a: any[], stride: number, offset: number, count: number, fn: Function, arg?: any): any[];// Common aliases for shorter code
const len: typeof length;
const sub: typeof subtract;
const mul: typeof multiply;
const div: typeof divide;
const dist: typeof distance;
const sqrDist: typeof squaredDistance;
const sqrLen: typeof squaredLength;All vector modules (vec2, vec3, vec4) share these common operations:
/**
* Math operations available for all vector types
*/
function ceil(out: vec, a: ReadonlyVec): vec;
function floor(out: vec, a: ReadonlyVec): vec;
function min(out: vec, a: ReadonlyVec, b: ReadonlyVec): vec;
function max(out: vec, a: ReadonlyVec, b: ReadonlyVec): vec;
function round(out: vec, a: ReadonlyVec): vec;
/**
* Utility functions available for all vector types
*/
function random(out: vec, scale?: number): vec;
function zero(out: vec): vec;
function str(a: ReadonlyVec): string;
function exactEquals(a: ReadonlyVec, b: ReadonlyVec): boolean;
function equals(a: ReadonlyVec, b: ReadonlyVec): boolean;
function forEach(a: Array, stride: number, offset: number, count: number, fn: Function, arg?: any): Array;import { vec2, vec3, vec4 } from "gl-matrix";
// 2D vector operations
const pos2d = vec2.fromValues(10, 20);
const vel2d = vec2.fromValues(1, -1);
vec2.add(pos2d, pos2d, vel2d);
// 3D vector operations
const position = vec3.fromValues(0, 0, -5);
const forward = vec3.fromValues(0, 0, 1);
const right = vec3.create();
vec3.cross(right, forward, [0, 1, 0]); // Cross with up vector
// Normalize vectors
vec3.normalize(forward, forward);
vec2.normalize(vel2d, vel2d);
// Calculate distances
const distance3d = vec3.distance(position, vec3.fromValues(1, 1, 1));
const distance2d = vec2.distance(pos2d, vec2.fromValues(0, 0));All vector modules provide convenient aliases for common operations:
len - alias for lengthsub - alias for subtractmul - alias for multiplydiv - alias for dividedist - alias for distancesqrDist - alias for squaredDistancesqrLen - alias for squaredLength