@fimbul-works/vec
Version:
A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.
12 lines (11 loc) • 627 B
JavaScript
/**
* Checks if two 4D vectors are approximately equal within epsilon.
* @param {ArrayVector4D} xyzw1 - First vector as `[x, y, z, w]`
* @param {ArrayVector4D} xyzw2 - Second vector as `[x, y, z, w]`
* @param {number} epsilon - Maximum difference (default: `Number.EPSILON`)
* @returns {boolean} `true` if vectors are approximately equal, `false` otherwise
*/
export const isEqualApprox4D = (xyzw1, xyzw2, epsilon = Number.EPSILON) => Math.abs(xyzw1[0] - xyzw2[0]) <= epsilon &&
Math.abs(xyzw1[1] - xyzw2[1]) <= epsilon &&
Math.abs(xyzw1[2] - xyzw2[2]) <= epsilon &&
Math.abs(xyzw1[3] - xyzw2[3]) <= epsilon;