@rbxts/mathcat
v0.0.6
Published
a collection of math helpers for 3D graphics and simulations
Maintainers
Readme
> npm install @rbxts/mathcatmathcat
mathcat is a collection of math helpers for 3D graphics and simulations.
Features:
- Vector, Quaternion, Euler, and Matrix math
- Easing functions
- Randomness utilities
- Noise utilities
- Simple JSON-serializable data structures (no classes or typed arrays)
- TypeScript-first, great DX for both JavaScript and TypeScript projects
- Excellent tree-shaking support
Acknowledgements:
- The vec*, quat*, mat* code started as a typescript port of glMatrix (https://glmatrix.net/). This library doesn't aim to stay in sync with glMatrix however.
- Simplex noise functions are adapted from https://github.com/pmndrs/maath, which were adapted from https://github.com/josephg/noisejs :)
API Documentation
types
vec2
vec3
vec4
euler
quat
quat2
mat2
mat2d
mat3
mat4
circle
segment2
triangle2
box3
obb3
sphere
triangle3
quickhull3
quickhull2
easing
noise
random
common
Reference
types
Vec2
/** A 2D vector */
export type Vec2 = [
x: number,
y: number
];Vec3
/** A 3D vector */
export type Vec3 = [
x: number,
y: number,
z: number
];Vec4
/** A 4D vector */
export type Vec4 = [
x: number,
y: number,
z: number,
w: number
];Quat
/** A quaternion that represents rotation */
export type Quat = [
x: number,
y: number,
z: number,
w: number
];Quat2
/** A dual quaternion that represents both rotation and translation */
export type Quat2 = [
x: number,
y: number,
z: number,
w: number,
x2: number,
y2: number,
z2: number,
w2: number
];Mat2
/** A 2x2 matrix */
export type Mat2 = [
e1: number,
e2: number,
e3: number,
e4: number
];Mat3
/** A 3x3 matrix */
export type Mat3 = [
e1: number,
e2: number,
e3: number,
e4: number,
e5: number,
e6: number,
e7: number,
e8: number,
e9: number
];Mat4
/** A 4x4 matrix */
export type Mat4 = [
e1: number,
e2: number,
e3: number,
e4: number,
e5: number,
e6: number,
e7: number,
e8: number,
e9: number,
e10: number,
e11: number,
e12: number,
e13: number,
e14: number,
e15: number,
e16: number
];Mat2d
/** A 2D affine transform matrix */
export type Mat2d = [
e1: number,
e2: number,
e3: number,
e4: number,
e5: number,
e6: number
];Box3
/** A box in 3D space */
export type Box3 = [
min: Vec3,
max: Vec3
];OBB3
/** A oriented bounding box in 3D space */
export type OBB3 = {
center: Vec3;
halfExtents: Vec3;
quaternion: Quat;
};EulerOrder
/** Euler orders */
export type EulerOrder = 'xyz' | 'xzy' | 'yxz' | 'yzx' | 'zxy' | 'zyx';Euler
/** A Euler in 3D space, with an optional order (default is 'xyz') */
export type Euler = [
x: number,
y: number,
z: number,
order?: EulerOrder
];Triangle3
/** A triangle in 3D space */
export type Triangle3 = [
a: Vec3,
b: Vec3,
c: Vec3
];Triangle2
/** A triangle in 2D space */
export type Triangle2 = [
a: Vec2,
b: Vec2,
c: Vec2
];Plane3
/**
* A plane in 3D space
* normal - a unit length vector defining the normal of the plane.
* constant - the signed distance from the origin to the plane.
*/
export type Plane3 = {
normal: Vec3;
constant: number;
};Sphere
/** A sphere in 3D space */
export type Sphere = {
center: Vec3;
radius: number;
};Circle
/** A circle in 2D space */
export type Circle = {
center: Vec2;
radius: number;
};MutableArrayLike
export type MutableArrayLike<T> = {
[index: number]: T;
length: number;
};vec2
vec2.create
/**
* Creates a new, empty vec2
*
* @returns a new 2D vector
*/
export function create(): Vec2;vec2.clone
/**
* Creates a new vec2 initialized with values from an existing vector
*
* @param a vector to clone
* @returns a new 2D vector
*/
export function clone(a: Vec2): Vec2;vec2.fromValues
/**
* Creates a new vec2 initialized with the given values
*
* @param x X component
* @param y Y component
* @returns a new 2D vector
*/
export function fromValues(x: number, y: number): Vec2;vec2.copy
/**
* Copy the values from one vec2 to another
*
* @param out the receiving vector
* @param a the source vector
* @returns out
*/
export function copy(out: Vec2, a: Vec2): Vec2;vec2.set
/**
* Set the components of a vec2 to the given values
*
* @param out the receiving vector
* @param x X component
* @param y Y component
* @returns out
*/
export function set(out: Vec2, x: number, y: number): Vec2;vec2.add
/**
* Adds two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.addScalar
/**
* Adds a scalar value to all components of a vec2
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to add
* @returns out
*/
export function addScalar(out: Vec2, a: Vec2, b: number): Vec2;vec2.subtract
/**
* Subtracts vector b from vector a
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.subtractScalar
/**
* Subtracts a scalar value from all components of a vec2
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to subtract
* @returns out
*/
export function subtractScalar(out: Vec2, a: Vec2, b: number): Vec2;vec2.multiply
/**
* Multiplies two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.divide
/**
* Divides two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function divide(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.ceil
/**
* Math.ceil the components of a vec2
*
* @param out the receiving vector
* @param a vector to ceil
* @returns out
*/
export function ceil(out: Vec2, a: Vec2): Vec2;vec2.floor
/**
* Math.floor the components of a vec2
*
* @param out the receiving vector
* @param a vector to floor
* @returns out
*/
export function floor(out: Vec2, a: Vec2): Vec2;vec2.min
/**
* Returns the minimum of two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function min(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.max
/**
* Returns the maximum of two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function max(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.round
/**
* symmetric round the components of a vec2
*
* @param out the receiving vector
* @param a vector to round
* @returns out
*/
export function round(out: Vec2, a: Vec2): Vec2;vec2.scale
/**
* Scales a vec2 by a scalar number
*
* @param out the receiving vector
* @param a the vector to scale
* @param b amount to scale the vector by
* @returns out
*/
export function scale(out: Vec2, a: Vec2, b: number): Vec2;vec2.scaleAndAdd
/**
* Adds two vec2's after scaling the second operand by a scalar value
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b by before adding
* @returns out
*/
export function scaleAndAdd(out: Vec2, a: Vec2, b: Vec2, scale: number): Vec2;vec2.distance
/**
* Calculates the euclidian distance between two vec2's
*
* @param a the first operand
* @param b the second operand
* @returns distance between a and b
*/
export function distance(a: Vec2, b: Vec2): number;vec2.squaredDistance
/**
* Calculates the squared euclidian distance between two vec2's
*
* @param a the first operand
* @param b the second operand
* @returns squared distance between a and b
*/
export function squaredDistance(a: Vec2, b: Vec2): number;vec2.length
/**
* Calculates the length of a vec2
*
* @param a vector to calculate length of
* @returns length of a
*/
export function length(a: Vec2): number;vec2.squaredLength
/**
* Calculates the squared length of a vec2
*
* @param a vector to calculate squared length of
* @returns squared length of a
*/
export function squaredLength(a: Vec2): number;vec2.negate
/**
* Negates the components of a vec2
*
* @param out the receiving vector
* @param a vector to negate
* @returns out
*/
export function negate(out: Vec2, a: Vec2): Vec2;vec2.inverse
/**
* Returns the inverse of the components of a vec2
*
* @param out the receiving vector
* @param a vector to invert
* @returns out
*/
export function inverse(out: Vec2, a: Vec2): Vec2;vec2.normalize
/**
* Normalize a vec2
*
* @param out the receiving vector
* @param a vector to normalize
* @returns out
*/
export function normalize(out: Vec2, a: Vec2): Vec2;vec2.dot
/**
* Calculates the dot product of two vec2's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export function dot(a: Vec2, b: Vec2): number;vec2.cross
/**
* Computes the cross product of two vec2's
* Note that the cross product must by definition produce a 3D vector
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function cross(out: Vec3, a: Vec2, b: Vec2): Vec3;vec2.lerp
/**
* Performs a linear interpolation between two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Vec2, a: Vec2, b: Vec2, t: number): Vec2;vec2.transformMat2
/**
* Transforms the vec2 with a mat2
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat2(out: Vec2, a: Vec2, m: Mat2): Vec2;vec2.transformMat2d
/**
* Transforms the vec2 with a mat2d
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat2d(out: Vec2, a: Vec2, m: Mat2d): Vec2;vec2.transformMat3
/**
* Transforms the vec2 with a mat3
* 3rd vector component is implicitly '1'
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat3(out: Vec2, a: Vec2, m: Mat3): Vec2;vec2.transformMat4
/**
* Transforms the vec2 with a mat4
* 3rd vector component is implicitly '0'
* 4th vector component is implicitly '1'
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat4(out: Vec2, a: Vec2, m: Mat4): Vec2;vec2.rotate
/**
* Rotate a 2D vector
* @param out The receiving vec2
* @param a The vec2 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotate(out: Vec2, a: Vec2, b: Vec2, rad: number): Vec2;vec2.angle
/**
* Get the angle between two 2D vectors
* @param a The first operand
* @param b The second operand
* @returns The angle in radians
*/
export function angle(a: Vec2, b: Vec2): number;vec2.zero
/**
* Set the components of a vec2 to zero
*
* @param out the receiving vector
* @returns out
*/
export function zero(out: Vec2): Vec2;vec2.str
/**
* Returns a string representation of a vector
*
* @param a vector to represent as a string
* @returns string representation of the vector
*/
export function str(a: Vec2): string;vec2.exactEquals
/**
* Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function exactEquals(a: Vec2, b: Vec2): boolean;vec2.equals
/**
* Returns whether or not the vectors have approximately the same elements in the same position.
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function equals(a: Vec2, b: Vec2): boolean;vec2.finite
/**
* Returns whether or not the vector is finite
* @param a vector to test
* @returns whether or not the vector is finite
*/
export function finite(a: Vec2): boolean;vec2.len
/**
* Alias for {@link length}
*/
export const len = length;vec2.sub
/**
* Alias for {@link subtract}
*/
export const sub = subtract;vec2.mul
/**
* Alias for {@link multiply}
*/
export const mul = multiply;vec2.div
/**
* Alias for {@link divide}
*/
export const div = divide;vec2.dist
/**
* Alias for {@link distance}
*/
export const dist = distance;vec2.sqrDist
/**
* Alias for {@link squaredDistance}
*/
export const sqrDist = squaredDistance;vec2.sqrLen
/**
* Alias for {@link squaredLength}
*/
export const sqrLen = squaredLength;vec3
vec3.create
/**
* Creates a new, empty vec3
*
* @returns a new 3D vector
*/
export function create(): Vec3;vec3.clone
/**
* Creates a new vec3 initialized with values from an existing vector
*
* @param a vector to clone
* @returns a new 3D vector
*/
export function clone(a: Vec3): Vec3;vec3.length
/**
* Calculates the length of a vec3
*
* @param a vector to calculate length of
* @returns length of a
*/
export function length(a: Vec3): number;vec3.fromValues
/**
* Creates a new vec3 initialized with the given values
*
* @param x X component
* @param y Y component
* @param z Z component
* @returns a new 3D vector
*/
export function fromValues(x: number, y: number, z: number): Vec3;vec3.copy
/**
* Copy the values from one vec3 to another
*
* @param out the receiving vector
* @param a the source vector
* @returns out
*/
export function copy(out: Vec3, a: Vec3): Vec3;vec3.set
/**
* Set the components of a vec3 to the given values
*
* @param out the receiving vector
* @param x X component
* @param y Y component
* @param z Z component
* @returns out
*/
export function set(out: Vec3, x: number, y: number, z: number): Vec3;vec3.fromBuffer
/**
* Sets the components of a vec3 from a buffer
* @param out the receiving vector
* @param buffer the source buffer
* @param startIndex the starting index in the buffer
* @returns out
*/
export function fromBuffer(out: Vec3, buffer: ArrayLike<number>, startIndex = 0): Vec3;vec3.toBuffer
/**
* Writes the components of a vec3 to a buffer
* @param outBuffer The output buffer
* @param vec The source vector
* @param startIndex The starting index in the buffer
* @returns The output buffer
*/
export function toBuffer(outBuffer: MutableArrayLike<number>, vec: Vec3, startIndex = 0): ArrayLike<number>;vec3.add
/**
* Adds two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.addScalar
/**
* Adds a scalar value to all components of a vec3
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to add
* @returns out
*/
export function addScalar(out: Vec3, a: Vec3, b: number): Vec3;vec3.subtract
/**
* Subtracts vector b from vector a
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.subtractScalar
/**
* Subtracts a scalar value from all components of a vec3
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to subtract
* @returns out
*/
export function subtractScalar(out: Vec3, a: Vec3, b: number): Vec3;vec3.multiply
/**
* Multiplies two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.divide
/**
* Divides two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function divide(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.ceil
/**
* Math.ceil the components of a vec3
*
* @param out the receiving vector
* @param a vector to ceil
* @returns out
*/
export function ceil(out: Vec3, a: Vec3): Vec3;vec3.floor
/**
* Math.floor the components of a vec3
*
* @param out the receiving vector
* @param a vector to floor
* @returns out
*/
export function floor(out: Vec3, a: Vec3): Vec3;vec3.min
/**
* Returns the minimum of two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function min(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.max
/**
* Returns the maximum of two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function max(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.round
/**
* symmetric round the components of a vec3
*
* @param out the receiving vector
* @param a vector to round
* @returns out
*/
export function round(out: Vec3, a: Vec3): Vec3;vec3.scale
/**
* Scales a vec3 by a scalar number
*
* @param out the receiving vector
* @param a the vector to scale
* @param b amount to scale the vector by
* @returns out
*/
export function scale(out: Vec3, a: Vec3, b: number): Vec3;vec3.scaleAndAdd
/**
* Adds two vec3's after scaling the second operand by a scalar value
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b by before adding
* @returns out
*/
export function scaleAndAdd(out: Vec3, a: Vec3, b: Vec3, scale: number): Vec3;vec3.distance
/**
* Calculates the euclidian distance between two vec3's
*
* @param a the first operand
* @param b the second operand
* @returns distance between a and b
*/
export function distance(a: Vec3, b: Vec3): number;vec3.squaredDistance
/**
* Calculates the squared euclidian distance between two vec3's
*
* @param a the first operand
* @param b the second operand
* @returns squared distance between a and b
*/
export function squaredDistance(a: Vec3, b: Vec3): number;vec3.squaredLength
/**
* Calculates the squared length of a vec3
*
* @param a vector to calculate squared length of
* @returns squared length of a
*/
export function squaredLength(a: Vec3): number;vec3.negate
/**
* Negates the components of a vec3
*
* @param out the receiving vector
* @param a vector to negate
* @returns out
*/
export function negate(out: Vec3, a: Vec3): Vec3;vec3.inverse
/**
* Returns the inverse of the components of a vec3
*
* @param out the receiving vector
* @param a vector to invert
* @returns out
*/
export function inverse(out: Vec3, a: Vec3): Vec3;vec3.normalize
/**
* Normalize a vec3
*
* @param out the receiving vector
* @param a vector to normalize
* @returns out
*/
export function normalize(out: Vec3, a: Vec3): Vec3;vec3.dot
/**
* Calculates the dot product of two vec3's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export function dot(a: Vec3, b: Vec3): number;vec3.cross
/**
* Computes the cross product of two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function cross(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.lerp
/**
* Performs a linear interpolation between two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3;vec3.slerp
/**
* Performs a spherical linear interpolation between two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function slerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3;vec3.hermite
/**
* Performs a hermite interpolation with two control points
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param c the third operand
* @param d the fourth operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function hermite(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3;vec3.bezier
/**
* Performs a bezier interpolation with two control points
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param c the third operand
* @param d the fourth operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function bezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3;vec3.transformMat4
/**
* Transforms the vec3 with a mat4.
* 4th vector component is implicitly '1'
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat4(out: Vec3, a: Vec3, m: Mat4): Vec3;vec3.transformMat3
/**
* Transforms the vec3 with a mat3.
*
* @param out the receiving vector
* @param a the vector to transform
* @param m the 3x3 matrix to transform with
* @returns out
*/
export function transformMat3(out: Vec3, a: Vec3, m: Mat3): Vec3;vec3.transformQuat
/**
* Transforms the vec3 with a quat
* Can also be used for dual quaternions. (Multiply it with the real part)
*
* @param out the receiving vector
* @param a the vector to transform
* @param q quaternion to transform with
* @returns out
*/
export function transformQuat(out: Vec3, a: Vec3, q: Quat): Vec3;vec3.rotateX
/**
* Rotate a 3D vector around the x-axis
* @param out The receiving vec3
* @param a The vec3 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotateX(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3;vec3.rotateY
/**
* Rotate a 3D vector around the y-axis
* @param out The receiving vec3
* @param a The vec3 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotateY(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3;vec3.rotateZ
/**
* Rotate a 3D vector around the z-axis
* @param out The receiving vec3
* @param a The vec3 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotateZ(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3;vec3.angle
/**
* Get the angle between two 3D vectors
* @param a The first operand
* @param b The second operand
* @returns The angle in radians
*/
export function angle(a: Vec3, b: Vec3): number;vec3.zero
/**
* Set the components of a vec3 to zero
*
* @param out the receiving vector
* @returns out
*/
export function zero(out: Vec3): Vec3;vec3.str
/**
* Returns a string representation of a vector
*
* @param a vector to represent as a string
* @returns string representation of the vector
*/
export function str(a: Vec3): string;vec3.exactEquals
/**
* Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function exactEquals(a: Vec3, b: Vec3): boolean;vec3.equals
/**
* Returns whether or not the vectors have approximately the same elements in the same position.
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function equals(a: Vec3, b: Vec3): boolean;vec3.finite
/**
* Returns whether or not the vector is finite
* @param a vector to test
* @returns whether or not the vector is finite
*/
export function finite(a: Vec3): boolean;vec3.sub
/**
* Alias for {@link subtract}
*/
export const sub = subtract;vec3.mul
/**
* Alias for {@link multiply}
*/
export const mul = multiply;vec3.div
/**
* Alias for {@link divide}
*/
export const div = divide;vec3.dist
/**
* Alias for {@link distance}
*/
export const dist = distance;vec3.sqrDist
/**
* Alias for {@link squaredDistance}
*/
export const sqrDist = squaredDistance;vec3.len
/**
* Alias for {@link length}
*/
export const len = length;vec3.sqrLen
/**
* Alias for {@link squaredLength}
*/
export const sqrLen = squaredLength;vec4
vec4.create
/**
* Creates a new, empty vec4
*
* @returns a new 4D vector
*/
export function create(): Vec4;vec4.clone
/**
* Creates a new vec4 initialized with values from an existing vector
*
* @param a vector to clone
* @returns a new 4D vector
*/
export function clone(a: Vec4): Vec4;vec4.fromValues
/**
* Creates a new vec4 initialized with the given values
*
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
* @returns a new 4D vector
*/
export function fromValues(x: number, y: number, z: number, w: number): Vec4;vec4.copy
/**
* Copy the values from one vec4 to another
*
* @param out the receiving vector
* @param a the source vector
* @returns out
*/
export function copy(out: Vec4, a: Vec4): Vec4;vec4.set
/**
* Set the components of a vec4 to the given values
*
* @param out the receiving vector
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
* @returns out
*/
export function set(out: Vec4, x: number, y: number, z: number, w: number): Vec4;vec4.add
/**
* Adds two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.subtract
/**
* Subtracts vector b from vector a
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.multiply
/**
* Multiplies two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.divide
/**
* Divides two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function divide(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.ceil
/**
* Math.ceil the components of a vec4
*
* @param out the receiving vector
* @param a vector to ceil
* @returns out
*/
export function ceil(out: Vec4, a: Vec4): Vec4;vec4.floor
/**
* Math.floor the components of a vec4
*
* @param out the receiving vector
* @param a vector to floor
* @returns out
*/
export function floor(out: Vec4, a: Vec4): Vec4;vec4.min
/**
* Returns the minimum of two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function min(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.max
/**
* Returns the maximum of two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function max(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.round
/**
* symmetric round the components of a vec4
*
* @param out the receiving vector
* @param a vector to round
* @returns out
*/
export function round(out: Vec4, a: Vec4): Vec4;vec4.scale
/**
* Scales a vec4 by a scalar number
*
* @param out the receiving vector
* @param a the vector to scale
* @param b amount to scale the vector by
* @returns out
*/
export function scale(out: Vec4, a: Vec4, b: number): Vec4;vec4.scaleAndAdd
/**
* Adds two vec4's after scaling the second operand by a scalar value
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b by before adding
* @returns out
*/
export function scaleAndAdd(out: Vec4, a: Vec4, b: Vec4, scale: number): Vec4;vec4.distance
/**
* Calculates the euclidian distance between two vec4's
*
* @param a the first operand
* @param b the second operand
* @returns distance between a and b
*/
export function distance(a: Vec4, b: Vec4): number;vec4.squaredDistance
/**
* Calculates the squared euclidian distance between two vec4's
*
* @param a the first operand
* @param b the second operand
* @returns squared distance between a and b
*/
export function squaredDistance(a: Vec4, b: Vec4): number;vec4.length
/**
* Calculates the length of a vec4
*
* @param a vector to calculate length of
* @returns length of a
*/
export function length(a: Vec4): number;vec4.squaredLength
/**
* Calculates the squared length of a vec4
*
* @param a vector to calculate squared length of
* @returns squared length of a
*/
export function squaredLength(a: Vec4): number;vec4.negate
/**
* Negates the components of a vec4
*
* @param out the receiving vector
* @param a vector to negate
* @returns out
*/
export function negate(out: Vec4, a: Vec4): Vec4;vec4.inverse
/**
* Returns the inverse of the components of a vec4
*
* @param out the receiving vector
* @param a vector to invert
* @returns out
*/
export function inverse(out: Vec4, a: Vec4): Vec4;vec4.normalize
/**
* Normalize a vec4
*
* @param out the receiving vector
* @param a vector to normalize
* @returns out
*/
export function normalize(out: Vec4, a: Vec4): Vec4;vec4.dot
/**
* Calculates the dot product of two vec4's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export function dot(a: Vec4, b: Vec4): number;vec4.cross
/**
* Returns the cross-product of three vectors in a 4-dimensional space
*
* @param out the receiving vector
* @param u the first vector
* @param v the second vector
* @param w the third vector
* @returns result
*/
export function cross(out: Vec4, u: Vec4, v: Vec4, w: Vec4): Vec4;vec4.lerp
/**
* Performs a linear interpolation between two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Vec4, a: Vec4, b: Vec4, t: number): Vec4;vec4.transformMat4
/**
* Transforms the vec4 with a mat4.
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat4(out: Vec4, a: Vec4, m: Mat4): Vec4;vec4.transformQuat
/**
* Transforms the vec4 with a quat
*
* @param out the receiving vector
* @param a the vector to transform
* @param q quaternion to transform with
* @returns out
*/
export function transformQuat(out: Vec4, a: Vec4, q: Quat): Vec4;vec4.zero
/**
* Set the components of a vec4 to zero
*
* @param out the receiving vector
* @returns out
*/
export fu