diff --git a/main.js b/main.js index 942b59cb..c74dc024 100644 --- a/main.js +++ b/main.js @@ -32990,8 +32990,6 @@ window.addEventListener('message', (e) => { sampleContainerElem.style.height = `${data.height}px`; break; } - default: - throw new Error(`unknown message cmd: ${cmd}`); } }); // Parse the first URL. diff --git a/main.js.map b/main.js.map index 64dd995d..ebd97e04 100644 --- a/main.js.map +++ b/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/sample/a-buffer/main.js b/sample/a-buffer/main.js index f896a4e5..4bea124e 100644 --- a/sample/a-buffer/main.js +++ b/sample/a-buffer/main.js @@ -1,4 +1,14 @@ -/* wgpu-matrix@2.8.0, license MIT */ +/* wgpu-matrix@3.0.0, license MIT */ +function wrapConstructor(OriginalConstructor, modifier) { + return class extends OriginalConstructor { + constructor(...args) { + super(...args); + modifier(this); + } + }; // Type assertion is necessary here +} +const ZeroArray = wrapConstructor((Array), a => a.fill(0)); + /* * Copyright 2022 Gregg Tavares * @@ -44,67 +54,673 @@ let EPSILON = 0.000001; * DEALINGS IN THE SOFTWARE. */ /** - * - * Vec3 math functions. - * - * Almost all functions take an optional `dst` argument. If it is not passed in the - * functions will create a new `Vec3`. In other words you can do this - * - * const v = vec3.cross(v1, v2); // Creates a new Vec3 with the cross product of v1 x v2. - * - * or - * - * const v = vec3.create(); - * vec3.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v - * - * The first style is often easier but depending on where it's used it generates garbage where - * as there is almost never allocation with the second style. - * - * It is always safe to pass any vector as the destination. So for example - * - * vec3.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1 - * - */ -let VecType$1 = Float32Array; -/** - * Sets the type this library creates for a Vec3 - * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array` - * @returns previous constructor for Vec3 - */ -function setDefaultType$5(ctor) { - const oldType = VecType$1; - VecType$1 = ctor; - return oldType; -} -/** - * Creates a vec3; may be called with x, y, z to set initial values. - * @param x - Initial x value. - * @param y - Initial y value. - * @param z - Initial z value. - * @returns the created vector + * Generates am typed API for Vec3 */ -function create$4(x, y, z) { - const dst = new VecType$1(3); - if (x !== undefined) { - dst[0] = x; - if (y !== undefined) { - dst[1] = y; - if (z !== undefined) { - dst[2] = z; +function getAPIImpl$5(Ctor) { + /** + * Creates a Vec2; may be called with x, y, z to set initial values. + * + * Note: Since passing in a raw JavaScript array + * is valid in all circumstances, if you want to + * force a JavaScript array into a Vec2's specified type + * it would be faster to use + * + * ``` + * const v = vec2.clone(someJSArray); + * ``` + * + * @param x - Initial x value. + * @param y - Initial y value. + * @returns the created vector + */ + function create(x = 0, y = 0) { + const newDst = new Ctor(2); + if (x !== undefined) { + newDst[0] = x; + if (y !== undefined) { + newDst[1] = y; } } + return newDst; + } + /** + * Creates a Vec2; may be called with x, y, z to set initial values. (same as create) + * @param x - Initial x value. + * @param y - Initial y value. + * @returns the created vector + */ + const fromValues = create; + /** + * Sets the values of a Vec2 + * Also see {@link vec2.create} and {@link vec2.copy} + * + * @param x first value + * @param y second value + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector with its elements set. + */ + function set(x, y, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = x; + newDst[1] = y; + return newDst; + } + /** + * Applies Math.ceil to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the ceil of each element of v. + */ + function ceil(v, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = Math.ceil(v[0]); + newDst[1] = Math.ceil(v[1]); + return newDst; + } + /** + * Applies Math.floor to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the floor of each element of v. + */ + function floor(v, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = Math.floor(v[0]); + newDst[1] = Math.floor(v[1]); + return newDst; + } + /** + * Applies Math.round to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the round of each element of v. + */ + function round(v, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = Math.round(v[0]); + newDst[1] = Math.round(v[1]); + return newDst; + } + /** + * Clamp each element of vector between min and max + * @param v - Operand vector. + * @param max - Min value, default 0 + * @param min - Max value, default 1 + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that the clamped value of each element of v. + */ + function clamp(v, min = 0, max = 1, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = Math.min(max, Math.max(min, v[0])); + newDst[1] = Math.min(max, Math.max(min, v[1])); + return newDst; + } + /** + * Adds two vectors; assumes a and b have the same dimension. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the sum of a and b. + */ + function add(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] + b[0]; + newDst[1] = a[1] + b[1]; + return newDst; + } + /** + * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension. + * @param a - Operand vector. + * @param b - Operand vector. + * @param scale - Amount to scale b + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the sum of a + b * scale. + */ + function addScaled(a, b, scale, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] + b[0] * scale; + newDst[1] = a[1] + b[1] * scale; + return newDst; + } + /** + * Returns the angle in radians between two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @returns The angle in radians between the 2 vectors. + */ + function angle(a, b) { + const ax = a[0]; + const ay = a[1]; + const bx = b[0]; + const by = b[1]; + const mag1 = Math.sqrt(ax * ax + ay * ay); + const mag2 = Math.sqrt(bx * bx + by * by); + const mag = mag1 * mag2; + const cosine = mag && dot(a, b) / mag; + return Math.acos(cosine); + } + /** + * Subtracts two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the difference of a and b. + */ + function subtract(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] - b[0]; + newDst[1] = a[1] - b[1]; + return newDst; + } + /** + * Subtracts two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the difference of a and b. + */ + const sub = subtract; + /** + * Check if 2 vectors are approximately equal + * @param a - Operand vector. + * @param b - Operand vector. + * @returns true if vectors are approximately equal + */ + function equalsApproximately(a, b) { + return Math.abs(a[0] - b[0]) < EPSILON && + Math.abs(a[1] - b[1]) < EPSILON; + } + /** + * Check if 2 vectors are exactly equal + * @param a - Operand vector. + * @param b - Operand vector. + * @returns true if vectors are exactly equal + */ + function equals(a, b) { + return a[0] === b[0] && a[1] === b[1]; + } + /** + * Performs linear interpolation on two vectors. + * Given vectors a and b and interpolation coefficient t, returns + * a + t * (b - a). + * @param a - Operand vector. + * @param b - Operand vector. + * @param t - Interpolation coefficient. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The linear interpolated result. + */ + function lerp(a, b, t, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] + t * (b[0] - a[0]); + newDst[1] = a[1] + t * (b[1] - a[1]); + return newDst; + } + /** + * Performs linear interpolation on two vectors. + * Given vectors a and b and interpolation coefficient vector t, returns + * a + t * (b - a). + * @param a - Operand vector. + * @param b - Operand vector. + * @param t - Interpolation coefficients vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns the linear interpolated result. + */ + function lerpV(a, b, t, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] + t[0] * (b[0] - a[0]); + newDst[1] = a[1] + t[1] * (b[1] - a[1]); + return newDst; + } + /** + * Return max values of two vectors. + * Given vectors a and b returns + * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])]. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The max components vector. + */ + function max(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = Math.max(a[0], b[0]); + newDst[1] = Math.max(a[1], b[1]); + return newDst; + } + /** + * Return min values of two vectors. + * Given vectors a and b returns + * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])]. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The min components vector. + */ + function min(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = Math.min(a[0], b[0]); + newDst[1] = Math.min(a[1], b[1]); + return newDst; + } + /** + * Multiplies a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + function mulScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = v[0] * k; + newDst[1] = v[1] * k; + return newDst; + } + /** + * Multiplies a vector by a scalar. (same as mulScalar) + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + const scale = mulScalar; + /** + * Divides a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + function divScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = v[0] / k; + newDst[1] = v[1] / k; + return newDst; + } + /** + * Inverse a vector. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The inverted vector. + */ + function inverse(v, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = 1 / v[0]; + newDst[1] = 1 / v[1]; + return newDst; + } + /** + * Invert a vector. (same as inverse) + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The inverted vector. + */ + const invert = inverse; + /** + * Computes the cross product of two vectors; assumes both vectors have + * three entries. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of a cross b. + */ + function cross(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + const z = a[0] * b[1] - a[1] * b[0]; + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = z; + return newDst; + } + /** + * Computes the dot product of two vectors; assumes both vectors have + * three entries. + * @param a - Operand vector. + * @param b - Operand vector. + * @returns dot product + */ + function dot(a, b) { + return a[0] * b[0] + a[1] * b[1]; + } + /** + * Computes the length of vector + * @param v - vector. + * @returns length of vector. + */ + function length(v) { + const v0 = v[0]; + const v1 = v[1]; + return Math.sqrt(v0 * v0 + v1 * v1); + } + /** + * Computes the length of vector (same as length) + * @param v - vector. + * @returns length of vector. + */ + const len = length; + /** + * Computes the square of the length of vector + * @param v - vector. + * @returns square of the length of vector. + */ + function lengthSq(v) { + const v0 = v[0]; + const v1 = v[1]; + return v0 * v0 + v1 * v1; + } + /** + * Computes the square of the length of vector (same as lengthSq) + * @param v - vector. + * @returns square of the length of vector. + */ + const lenSq = lengthSq; + /** + * Computes the distance between 2 points + * @param a - vector. + * @param b - vector. + * @returns distance between a and b + */ + function distance(a, b) { + const dx = a[0] - b[0]; + const dy = a[1] - b[1]; + return Math.sqrt(dx * dx + dy * dy); + } + /** + * Computes the distance between 2 points (same as distance) + * @param a - vector. + * @param b - vector. + * @returns distance between a and b + */ + const dist = distance; + /** + * Computes the square of the distance between 2 points + * @param a - vector. + * @param b - vector. + * @returns square of the distance between a and b + */ + function distanceSq(a, b) { + const dx = a[0] - b[0]; + const dy = a[1] - b[1]; + return dx * dx + dy * dy; + } + /** + * Computes the square of the distance between 2 points (same as distanceSq) + * @param a - vector. + * @param b - vector. + * @returns square of the distance between a and b + */ + const distSq = distanceSq; + /** + * Divides a vector by its Euclidean length and returns the quotient. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The normalized vector. + */ + function normalize(v, dst) { + const newDst = (dst ?? new Ctor(2)); + const v0 = v[0]; + const v1 = v[1]; + const len = Math.sqrt(v0 * v0 + v1 * v1); + if (len > 0.00001) { + newDst[0] = v0 / len; + newDst[1] = v1 / len; + } + else { + newDst[0] = 0; + newDst[1] = 0; + } + return newDst; + } + /** + * Negates a vector. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns -v. + */ + function negate(v, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = -v[0]; + newDst[1] = -v[1]; + return newDst; + } + /** + * Copies a vector. (same as {@link vec2.clone}) + * Also see {@link vec2.create} and {@link vec2.set} + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A copy of v. + */ + function copy(v, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = v[0]; + newDst[1] = v[1]; + return newDst; + } + /** + * Clones a vector. (same as {@link vec2.copy}) + * Also see {@link vec2.create} and {@link vec2.set} + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A copy of v. + */ + const clone = copy; + /** + * Multiplies a vector by another vector (component-wise); assumes a and + * b have the same length. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of products of entries of a and b. + */ + function multiply(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] * b[0]; + newDst[1] = a[1] * b[1]; + return newDst; + } + /** + * Multiplies a vector by another vector (component-wise); assumes a and + * b have the same length. (same as mul) + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of products of entries of a and b. + */ + const mul = multiply; + /** + * Divides a vector by another vector (component-wise); assumes a and + * b have the same length. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of quotients of entries of a and b. + */ + function divide(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = a[0] / b[0]; + newDst[1] = a[1] / b[1]; + return newDst; + } + /** + * Divides a vector by another vector (component-wise); assumes a and + * b have the same length. (same as divide) + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of quotients of entries of a and b. + */ + const div = divide; + /** + * Creates a random unit vector * scale + * @param scale - Default 1 + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The random vector. + */ + function random(scale = 1, dst) { + const newDst = (dst ?? new Ctor(2)); + const angle = Math.random() * 2 * Math.PI; + newDst[0] = Math.cos(angle) * scale; + newDst[1] = Math.sin(angle) * scale; + return newDst; + } + /** + * Zero's a vector + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The zeroed vector. + */ + function zero(dst) { + const newDst = (dst ?? new Ctor(2)); + newDst[0] = 0; + newDst[1] = 0; + return newDst; + } + /** + * transform Vec2 by 4x4 matrix + * @param v - the vector + * @param m - The matrix. + * @param dst - optional Vec2 to store result. If not passed a new one is created. + * @returns the transformed vector + */ + function transformMat4(v, m, dst) { + const newDst = (dst ?? new Ctor(2)); + const x = v[0]; + const y = v[1]; + newDst[0] = x * m[0] + y * m[4] + m[12]; + newDst[1] = x * m[1] + y * m[5] + m[13]; + return newDst; + } + /** + * Transforms vec4 by 3x3 matrix + * + * @param v - the vector + * @param m - The matrix. + * @param dst - optional Vec2 to store result. If not passed a new one is created. + * @returns the transformed vector + */ + function transformMat3(v, m, dst) { + const newDst = (dst ?? new Ctor(2)); + const x = v[0]; + const y = v[1]; + newDst[0] = m[0] * x + m[4] * y + m[8]; + newDst[1] = m[1] * x + m[5] * y + m[9]; + return newDst; + } + /** + * Rotate a 2D vector + * + * @param a The vec2 point to rotate + * @param b The origin of the rotation + * @param rad The angle of rotation in radians + * @returns the rotated vector + */ + function rotate(a, b, rad, dst) { + const newDst = (dst ?? new Ctor(2)); + // Translate point to the origin + const p0 = a[0] - b[0]; + const p1 = a[1] - b[1]; + const sinC = Math.sin(rad); + const cosC = Math.cos(rad); + //perform rotation and translate to correct position + newDst[0] = p0 * cosC - p1 * sinC + b[0]; + newDst[1] = p0 * sinC + p1 * cosC + b[1]; + return newDst; + } + /** + * Treat a 2D vector as a direction and set it's length + * + * @param a The vec2 to lengthen + * @param len The length of the resulting vector + * @returns The lengthened vector + */ + function setLength(a, len, dst) { + const newDst = (dst ?? new Ctor(2)); + normalize(a, newDst); + return mulScalar(newDst, len, newDst); + } + /** + * Ensure a vector is not longer than a max length + * + * @param a The vec2 to limit + * @param maxLen The longest length of the resulting vector + * @returns The vector, shortened to maxLen if it's too long + */ + function truncate(a, maxLen, dst) { + const newDst = (dst ?? new Ctor(2)); + if (length(a) > maxLen) { + return setLength(a, maxLen, newDst); + } + return copy(a, newDst); + } + /** + * Return the vector exactly between 2 endpoint vectors + * + * @param a Endpoint 1 + * @param b Endpoint 2 + * @returns The vector exactly residing between endpoints 1 and 2 + */ + function midpoint(a, b, dst) { + const newDst = (dst ?? new Ctor(2)); + return lerp(a, b, 0.5, newDst); } - return dst; + return { + create, + fromValues, + set, + ceil, + floor, + round, + clamp, + add, + addScaled, + angle, + subtract, + sub, + equalsApproximately, + equals, + lerp, + lerpV, + max, + min, + mulScalar, + scale, + divScalar, + inverse, + invert, + cross, + dot, + length, + len, + lengthSq, + lenSq, + distance, + dist, + distanceSq, + distSq, + normalize, + negate, + copy, + clone, + multiply, + mul, + divide, + div, + random, + zero, + transformMat4, + transformMat3, + rotate, + setLength, + truncate, + midpoint, + }; +} +const cache$5 = new Map(); +function getAPI$5(Ctor) { + let api = cache$5.get(Ctor); + if (!api) { + api = getAPIImpl$5(Ctor); + cache$5.set(Ctor, api); + } + return api; } -// This mess is because with Mat3 we have 3 unused elements. -// For Float32Array and Float64Array that's not an issue -// but for Array it's troublesome -const ctorMap = new Map([ - [Float32Array, () => new Float32Array(12)], - [Float64Array, () => new Float64Array(12)], - [Array, () => new Array(12).fill(0)], -]); -ctorMap.get(Float32Array); /* * Copyright 2022 Gregg Tavares @@ -128,2403 +744,4747 @@ ctorMap.get(Float32Array); * DEALINGS IN THE SOFTWARE. */ /** - * Creates a vec3; may be called with x, y, z to set initial values. (same as create) - * @param x - Initial x value. - * @param y - Initial y value. - * @param z - Initial z value. - * @returns the created vector - */ -const fromValues$2 = create$4; -/** - * Sets the values of a Vec3 - * Also see {@link vec3.create} and {@link vec3.copy} - * - * @param x first value - * @param y second value - * @param z third value - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector with its elements set. - */ -function set$3(x, y, z, dst) { - dst = dst || new VecType$1(3); - dst[0] = x; - dst[1] = y; - dst[2] = z; - return dst; -} -/** - * Applies Math.ceil to each element of vector - * @param v - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the ceil of each element of v. - */ -function ceil$1(v, dst) { - dst = dst || new VecType$1(3); - dst[0] = Math.ceil(v[0]); - dst[1] = Math.ceil(v[1]); - dst[2] = Math.ceil(v[2]); - return dst; -} -/** - * Applies Math.floor to each element of vector - * @param v - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the floor of each element of v. - */ -function floor$1(v, dst) { - dst = dst || new VecType$1(3); - dst[0] = Math.floor(v[0]); - dst[1] = Math.floor(v[1]); - dst[2] = Math.floor(v[2]); - return dst; -} -/** - * Applies Math.round to each element of vector - * @param v - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the round of each element of v. - */ -function round$1(v, dst) { - dst = dst || new VecType$1(3); - dst[0] = Math.round(v[0]); - dst[1] = Math.round(v[1]); - dst[2] = Math.round(v[2]); - return dst; -} -/** - * Clamp each element of vector between min and max - * @param v - Operand vector. - * @param max - Min value, default 0 - * @param min - Max value, default 1 - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that the clamped value of each element of v. - */ -function clamp$1(v, min = 0, max = 1, dst) { - dst = dst || new VecType$1(3); - dst[0] = Math.min(max, Math.max(min, v[0])); - dst[1] = Math.min(max, Math.max(min, v[1])); - dst[2] = Math.min(max, Math.max(min, v[2])); - return dst; -} -/** - * Adds two vectors; assumes a and b have the same dimension. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the sum of a and b. - */ -function add$2(a, b, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] + b[0]; - dst[1] = a[1] + b[1]; - dst[2] = a[2] + b[2]; - return dst; -} -/** - * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension. - * @param a - Operand vector. - * @param b - Operand vector. - * @param scale - Amount to scale b - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the sum of a + b * scale. - */ -function addScaled$1(a, b, scale, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] + b[0] * scale; - dst[1] = a[1] + b[1] * scale; - dst[2] = a[2] + b[2] * scale; - return dst; -} -/** - * Returns the angle in radians between two vectors. - * @param a - Operand vector. - * @param b - Operand vector. - * @returns The angle in radians between the 2 vectors. - */ -function angle$1(a, b) { - const ax = a[0]; - const ay = a[1]; - const az = a[2]; - const bx = a[0]; - const by = a[1]; - const bz = a[2]; - const mag1 = Math.sqrt(ax * ax + ay * ay + az * az); - const mag2 = Math.sqrt(bx * bx + by * by + bz * bz); - const mag = mag1 * mag2; - const cosine = mag && dot$2(a, b) / mag; - return Math.acos(cosine); -} -/** - * Subtracts two vectors. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the difference of a and b. - */ -function subtract$2(a, b, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] - b[0]; - dst[1] = a[1] - b[1]; - dst[2] = a[2] - b[2]; - return dst; -} -/** - * Subtracts two vectors. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A vector that is the difference of a and b. - */ -const sub$2 = subtract$2; -/** - * Check if 2 vectors are approximately equal - * @param a - Operand vector. - * @param b - Operand vector. - * @returns true if vectors are approximately equal - */ -function equalsApproximately$3(a, b) { - return Math.abs(a[0] - b[0]) < EPSILON && - Math.abs(a[1] - b[1]) < EPSILON && - Math.abs(a[2] - b[2]) < EPSILON; -} -/** - * Check if 2 vectors are exactly equal - * @param a - Operand vector. - * @param b - Operand vector. - * @returns true if vectors are exactly equal - */ -function equals$3(a, b) { - return a[0] === b[0] && a[1] === b[1] && a[2] === b[2]; -} -/** - * Performs linear interpolation on two vectors. - * Given vectors a and b and interpolation coefficient t, returns - * a + t * (b - a). - * @param a - Operand vector. - * @param b - Operand vector. - * @param t - Interpolation coefficient. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The linear interpolated result. - */ -function lerp$2(a, b, t, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] + t * (b[0] - a[0]); - dst[1] = a[1] + t * (b[1] - a[1]); - dst[2] = a[2] + t * (b[2] - a[2]); - return dst; -} -/** - * Performs linear interpolation on two vectors. - * Given vectors a and b and interpolation coefficient vector t, returns - * a + t * (b - a). - * @param a - Operand vector. - * @param b - Operand vector. - * @param t - Interpolation coefficients vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns the linear interpolated result. - */ -function lerpV$1(a, b, t, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] + t[0] * (b[0] - a[0]); - dst[1] = a[1] + t[1] * (b[1] - a[1]); - dst[2] = a[2] + t[2] * (b[2] - a[2]); - return dst; -} -/** - * Return max values of two vectors. - * Given vectors a and b returns - * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])]. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The max components vector. - */ -function max$1(a, b, dst) { - dst = dst || new VecType$1(3); - dst[0] = Math.max(a[0], b[0]); - dst[1] = Math.max(a[1], b[1]); - dst[2] = Math.max(a[2], b[2]); - return dst; -} -/** - * Return min values of two vectors. - * Given vectors a and b returns - * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])]. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The min components vector. - */ -function min$1(a, b, dst) { - dst = dst || new VecType$1(3); - dst[0] = Math.min(a[0], b[0]); - dst[1] = Math.min(a[1], b[1]); - dst[2] = Math.min(a[2], b[2]); - return dst; -} -/** - * Multiplies a vector by a scalar. - * @param v - The vector. - * @param k - The scalar. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The scaled vector. - */ -function mulScalar$2(v, k, dst) { - dst = dst || new VecType$1(3); - dst[0] = v[0] * k; - dst[1] = v[1] * k; - dst[2] = v[2] * k; - return dst; -} -/** - * Multiplies a vector by a scalar. (same as mulScalar) - * @param v - The vector. - * @param k - The scalar. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The scaled vector. - */ -const scale$3 = mulScalar$2; -/** - * Divides a vector by a scalar. - * @param v - The vector. - * @param k - The scalar. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The scaled vector. - */ -function divScalar$2(v, k, dst) { - dst = dst || new VecType$1(3); - dst[0] = v[0] / k; - dst[1] = v[1] / k; - dst[2] = v[2] / k; - return dst; -} -/** - * Inverse a vector. - * @param v - The vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The inverted vector. - */ -function inverse$3(v, dst) { - dst = dst || new VecType$1(3); - dst[0] = 1 / v[0]; - dst[1] = 1 / v[1]; - dst[2] = 1 / v[2]; - return dst; -} -/** - * Invert a vector. (same as inverse) - * @param v - The vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The inverted vector. - */ -const invert$2 = inverse$3; -/** - * Computes the cross product of two vectors; assumes both vectors have - * three entries. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The vector of a cross b. - */ -function cross(a, b, dst) { - dst = dst || new VecType$1(3); - const t1 = a[2] * b[0] - a[0] * b[2]; - const t2 = a[0] * b[1] - a[1] * b[0]; - dst[0] = a[1] * b[2] - a[2] * b[1]; - dst[1] = t1; - dst[2] = t2; - return dst; -} -/** - * Computes the dot product of two vectors; assumes both vectors have - * three entries. - * @param a - Operand vector. - * @param b - Operand vector. - * @returns dot product - */ -function dot$2(a, b) { - return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]); -} -/** - * Computes the length of vector - * @param v - vector. - * @returns length of vector. - */ -function length$2(v) { - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2); -} -/** - * Computes the length of vector (same as length) - * @param v - vector. - * @returns length of vector. - */ -const len$2 = length$2; -/** - * Computes the square of the length of vector - * @param v - vector. - * @returns square of the length of vector. - */ -function lengthSq$2(v) { - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - return v0 * v0 + v1 * v1 + v2 * v2; -} -/** - * Computes the square of the length of vector (same as lengthSq) - * @param v - vector. - * @returns square of the length of vector. - */ -const lenSq$2 = lengthSq$2; -/** - * Computes the distance between 2 points - * @param a - vector. - * @param b - vector. - * @returns distance between a and b - */ -function distance$1(a, b) { - const dx = a[0] - b[0]; - const dy = a[1] - b[1]; - const dz = a[2] - b[2]; - return Math.sqrt(dx * dx + dy * dy + dz * dz); -} -/** - * Computes the distance between 2 points (same as distance) - * @param a - vector. - * @param b - vector. - * @returns distance between a and b - */ -const dist$1 = distance$1; -/** - * Computes the square of the distance between 2 points - * @param a - vector. - * @param b - vector. - * @returns square of the distance between a and b - */ -function distanceSq$1(a, b) { - const dx = a[0] - b[0]; - const dy = a[1] - b[1]; - const dz = a[2] - b[2]; - return dx * dx + dy * dy + dz * dz; -} -/** - * Computes the square of the distance between 2 points (same as distanceSq) - * @param a - vector. - * @param b - vector. - * @returns square of the distance between a and b - */ -const distSq$1 = distanceSq$1; -/** - * Divides a vector by its Euclidean length and returns the quotient. - * @param v - The vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The normalized vector. - */ -function normalize$2(v, dst) { - dst = dst || new VecType$1(3); - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2); - if (len > 0.00001) { - dst[0] = v0 / len; - dst[1] = v1 / len; - dst[2] = v2 / len; - } - else { - dst[0] = 0; - dst[1] = 0; - dst[2] = 0; - } - return dst; -} -/** - * Negates a vector. - * @param v - The vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns -v. - */ -function negate$2(v, dst) { - dst = dst || new VecType$1(3); - dst[0] = -v[0]; - dst[1] = -v[1]; - dst[2] = -v[2]; - return dst; -} -/** - * Copies a vector. (same as {@link vec3.clone}) - * Also see {@link vec3.create} and {@link vec3.set} - * @param v - The vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A copy of v. - */ -function copy$3(v, dst) { - dst = dst || new VecType$1(3); - dst[0] = v[0]; - dst[1] = v[1]; - dst[2] = v[2]; - return dst; -} -/** - * Clones a vector. (same as {@link vec3.copy}) - * Also see {@link vec3.create} and {@link vec3.set} - * @param v - The vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns A copy of v. - */ -const clone$3 = copy$3; -/** - * Multiplies a vector by another vector (component-wise); assumes a and - * b have the same length. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The vector of products of entries of a and b. - */ -function multiply$3(a, b, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] * b[0]; - dst[1] = a[1] * b[1]; - dst[2] = a[2] * b[2]; - return dst; -} -/** - * Multiplies a vector by another vector (component-wise); assumes a and - * b have the same length. (same as mul) - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The vector of products of entries of a and b. - */ -const mul$3 = multiply$3; -/** - * Divides a vector by another vector (component-wise); assumes a and - * b have the same length. - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The vector of quotients of entries of a and b. - */ -function divide$1(a, b, dst) { - dst = dst || new VecType$1(3); - dst[0] = a[0] / b[0]; - dst[1] = a[1] / b[1]; - dst[2] = a[2] / b[2]; - return dst; -} -/** - * Divides a vector by another vector (component-wise); assumes a and - * b have the same length. (same as divide) - * @param a - Operand vector. - * @param b - Operand vector. - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The vector of quotients of entries of a and b. - */ -const div$1 = divide$1; -/** - * Creates a random vector - * @param scale - Default 1 - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The random vector. - */ -function random(scale = 1, dst) { - dst = dst || new VecType$1(3); - const angle = Math.random() * 2 * Math.PI; - const z = Math.random() * 2 - 1; - const zScale = Math.sqrt(1 - z * z) * scale; - dst[0] = Math.cos(angle) * zScale; - dst[1] = Math.sin(angle) * zScale; - dst[2] = z * scale; - return dst; -} -/** - * Zero's a vector - * @param dst - vector to hold result. If not passed in a new one is created. - * @returns The zeroed vector. - */ -function zero$1(dst) { - dst = dst || new VecType$1(3); - dst[0] = 0; - dst[1] = 0; - dst[2] = 0; - return dst; -} -/** - * transform vec3 by 4x4 matrix - * @param v - the vector - * @param m - The matrix. - * @param dst - optional vec3 to store result. If not passed a new one is created. - * @returns the transformed vector - */ -function transformMat4$1(v, m, dst) { - dst = dst || new VecType$1(3); - const x = v[0]; - const y = v[1]; - const z = v[2]; - const w = (m[3] * x + m[7] * y + m[11] * z + m[15]) || 1; - dst[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; - dst[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; - dst[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; - return dst; + * Generates a typed API for Mat3 + * */ +function getAPIImpl$4(Ctor) { + const vec2 = getAPI$5(Ctor); + /** + * Create a Mat3 from values + * + * Note: Since passing in a raw JavaScript array + * is valid in all circumstances, if you want to + * force a JavaScript array into a Mat3's specified type + * it would be faster to use + * + * ``` + * const m = mat3.clone(someJSArray); + * ``` + * + * @param v0 - value for element 0 + * @param v1 - value for element 1 + * @param v2 - value for element 2 + * @param v3 - value for element 3 + * @param v4 - value for element 4 + * @param v5 - value for element 5 + * @param v6 - value for element 6 + * @param v7 - value for element 7 + * @param v8 - value for element 8 + * @returns matrix created from values. + */ + function create(v0, v1, v2, v3, v4, v5, v6, v7, v8) { + const newDst = new Ctor(12); + // to make the array homogenous + newDst[3] = 0; + newDst[7] = 0; + newDst[11] = 0; + if (v0 !== undefined) { + newDst[0] = v0; + if (v1 !== undefined) { + newDst[1] = v1; + if (v2 !== undefined) { + newDst[2] = v2; + if (v3 !== undefined) { + newDst[4] = v3; + if (v4 !== undefined) { + newDst[5] = v4; + if (v5 !== undefined) { + newDst[6] = v5; + if (v6 !== undefined) { + newDst[8] = v6; + if (v7 !== undefined) { + newDst[9] = v7; + if (v8 !== undefined) { + newDst[10] = v8; + } + } + } + } + } + } + } + } + } + return newDst; + } + /** + * Sets the values of a Mat3 + * Also see {@link mat3.create} and {@link mat3.copy} + * + * @param v0 - value for element 0 + * @param v1 - value for element 1 + * @param v2 - value for element 2 + * @param v3 - value for element 3 + * @param v4 - value for element 4 + * @param v5 - value for element 5 + * @param v6 - value for element 6 + * @param v7 - value for element 7 + * @param v8 - value for element 8 + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns Mat3 set from values. + */ + function set(v0, v1, v2, v3, v4, v5, v6, v7, v8, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = v0; + newDst[1] = v1; + newDst[2] = v2; + newDst[3] = 0; + newDst[4] = v3; + newDst[5] = v4; + newDst[6] = v5; + newDst[7] = 0; + newDst[8] = v6; + newDst[9] = v7; + newDst[10] = v8; + newDst[11] = 0; + return newDst; + } + /** + * Creates a Mat3 from the upper left 3x3 part of a Mat4 + * @param m4 - source matrix + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns Mat3 made from m4 + */ + function fromMat4(m4, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = m4[0]; + newDst[1] = m4[1]; + newDst[2] = m4[2]; + newDst[3] = 0; + newDst[4] = m4[4]; + newDst[5] = m4[5]; + newDst[6] = m4[6]; + newDst[7] = 0; + newDst[8] = m4[8]; + newDst[9] = m4[9]; + newDst[10] = m4[10]; + newDst[11] = 0; + return newDst; + } + /** + * Creates a Mat3 rotation matrix from a quaternion + * @param q - quaternion to create matrix from + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns Mat3 made from q + */ + function fromQuat(q, dst) { + const newDst = (dst ?? new Ctor(12)); + const x = q[0]; + const y = q[1]; + const z = q[2]; + const w = q[3]; + const x2 = x + x; + const y2 = y + y; + const z2 = z + z; + const xx = x * x2; + const yx = y * x2; + const yy = y * y2; + const zx = z * x2; + const zy = z * y2; + const zz = z * z2; + const wx = w * x2; + const wy = w * y2; + const wz = w * z2; + newDst[0] = 1 - yy - zz; + newDst[1] = yx + wz; + newDst[2] = zx - wy; + newDst[3] = 0; + newDst[4] = yx - wz; + newDst[5] = 1 - xx - zz; + newDst[6] = zy + wx; + newDst[7] = 0; + newDst[8] = zx + wy; + newDst[9] = zy - wx; + newDst[10] = 1 - xx - yy; + newDst[11] = 0; + return newDst; + } + /** + * Negates a matrix. + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns -m. + */ + function negate(m, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = -m[0]; + newDst[1] = -m[1]; + newDst[2] = -m[2]; + newDst[4] = -m[4]; + newDst[5] = -m[5]; + newDst[6] = -m[6]; + newDst[8] = -m[8]; + newDst[9] = -m[9]; + newDst[10] = -m[10]; + return newDst; + } + /** + * Copies a matrix. (same as {@link mat3.clone}) + * Also see {@link mat3.create} and {@link mat3.set} + * @param m - The matrix. + * @param dst - The matrix. If not passed a new one is created. + * @returns A copy of m. + */ + function copy(m, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = m[0]; + newDst[1] = m[1]; + newDst[2] = m[2]; + newDst[4] = m[4]; + newDst[5] = m[5]; + newDst[6] = m[6]; + newDst[8] = m[8]; + newDst[9] = m[9]; + newDst[10] = m[10]; + return newDst; + } + /** + * Copies a matrix (same as {@link mat3.copy}) + * Also see {@link mat3.create} and {@link mat3.set} + * @param m - The matrix. + * @param dst - The matrix. If not passed a new one is created. + * @returns A copy of m. + */ + const clone = copy; + /** + * Check if 2 matrices are approximately equal + * @param a Operand matrix. + * @param b Operand matrix. + * @returns true if matrices are approximately equal + */ + function equalsApproximately(a, b) { + return Math.abs(a[0] - b[0]) < EPSILON && + Math.abs(a[1] - b[1]) < EPSILON && + Math.abs(a[2] - b[2]) < EPSILON && + Math.abs(a[4] - b[4]) < EPSILON && + Math.abs(a[5] - b[5]) < EPSILON && + Math.abs(a[6] - b[6]) < EPSILON && + Math.abs(a[8] - b[8]) < EPSILON && + Math.abs(a[9] - b[9]) < EPSILON && + Math.abs(a[10] - b[10]) < EPSILON; + } + /** + * Check if 2 matrices are exactly equal + * @param a Operand matrix. + * @param b Operand matrix. + * @returns true if matrices are exactly equal + */ + function equals(a, b) { + return a[0] === b[0] && + a[1] === b[1] && + a[2] === b[2] && + a[4] === b[4] && + a[5] === b[5] && + a[6] === b[6] && + a[8] === b[8] && + a[9] === b[9] && + a[10] === b[10]; + } + /** + * Creates a 3-by-3 identity matrix. + * + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns A 3-by-3 identity matrix. + */ + function identity(dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = 1; + newDst[1] = 0; + newDst[2] = 0; + newDst[4] = 0; + newDst[5] = 1; + newDst[6] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + return newDst; + } + /** + * Takes the transpose of a matrix. + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The transpose of m. + */ + function transpose(m, dst) { + const newDst = (dst ?? new Ctor(12)); + if (newDst === m) { + let t; + // 0 1 2 + // 4 5 6 + // 8 9 10 + t = m[1]; + m[1] = m[4]; + m[4] = t; + t = m[2]; + m[2] = m[8]; + m[8] = t; + t = m[6]; + m[6] = m[9]; + m[9] = t; + return newDst; + } + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + newDst[0] = m00; + newDst[1] = m10; + newDst[2] = m20; + newDst[4] = m01; + newDst[5] = m11; + newDst[6] = m21; + newDst[8] = m02; + newDst[9] = m12; + newDst[10] = m22; + return newDst; + } + /** + * Computes the inverse of a 3-by-3 matrix. + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The inverse of m. + */ + function inverse(m, dst) { + const newDst = (dst ?? new Ctor(12)); + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + const b01 = m22 * m11 - m12 * m21; + const b11 = -m22 * m10 + m12 * m20; + const b21 = m21 * m10 - m11 * m20; + const invDet = 1 / (m00 * b01 + m01 * b11 + m02 * b21); + newDst[0] = b01 * invDet; + newDst[1] = (-m22 * m01 + m02 * m21) * invDet; + newDst[2] = (m12 * m01 - m02 * m11) * invDet; + newDst[4] = b11 * invDet; + newDst[5] = (m22 * m00 - m02 * m20) * invDet; + newDst[6] = (-m12 * m00 + m02 * m10) * invDet; + newDst[8] = b21 * invDet; + newDst[9] = (-m21 * m00 + m01 * m20) * invDet; + newDst[10] = (m11 * m00 - m01 * m10) * invDet; + return newDst; + } + /** + * Compute the determinant of a matrix + * @param m - the matrix + * @returns the determinant + */ + function determinant(m) { + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + return m00 * (m11 * m22 - m21 * m12) - + m10 * (m01 * m22 - m21 * m02) + + m20 * (m01 * m12 - m11 * m02); + } + /** + * Computes the inverse of a 3-by-3 matrix. (same as inverse) + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The inverse of m. + */ + const invert = inverse; + /** + * Multiplies two 3-by-3 matrices with a on the left and b on the right + * @param a - The matrix on the left. + * @param b - The matrix on the right. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The matrix product of a and b. + */ + function multiply(a, b, dst) { + const newDst = (dst ?? new Ctor(12)); + const a00 = a[0]; + const a01 = a[1]; + const a02 = a[2]; + const a10 = a[4 + 0]; + const a11 = a[4 + 1]; + const a12 = a[4 + 2]; + const a20 = a[8 + 0]; + const a21 = a[8 + 1]; + const a22 = a[8 + 2]; + const b00 = b[0]; + const b01 = b[1]; + const b02 = b[2]; + const b10 = b[4 + 0]; + const b11 = b[4 + 1]; + const b12 = b[4 + 2]; + const b20 = b[8 + 0]; + const b21 = b[8 + 1]; + const b22 = b[8 + 2]; + newDst[0] = a00 * b00 + a10 * b01 + a20 * b02; + newDst[1] = a01 * b00 + a11 * b01 + a21 * b02; + newDst[2] = a02 * b00 + a12 * b01 + a22 * b02; + newDst[4] = a00 * b10 + a10 * b11 + a20 * b12; + newDst[5] = a01 * b10 + a11 * b11 + a21 * b12; + newDst[6] = a02 * b10 + a12 * b11 + a22 * b12; + newDst[8] = a00 * b20 + a10 * b21 + a20 * b22; + newDst[9] = a01 * b20 + a11 * b21 + a21 * b22; + newDst[10] = a02 * b20 + a12 * b21 + a22 * b22; + return newDst; + } + /** + * Multiplies two 3-by-3 matrices with a on the left and b on the right (same as multiply) + * @param a - The matrix on the left. + * @param b - The matrix on the right. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The matrix product of a and b. + */ + const mul = multiply; + /** + * Sets the translation component of a 3-by-3 matrix to the given + * vector. + * @param a - The matrix. + * @param v - The vector. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The matrix with translation set. + */ + function setTranslation(a, v, dst) { + const newDst = (dst ?? identity()); + if (a !== newDst) { + newDst[0] = a[0]; + newDst[1] = a[1]; + newDst[2] = a[2]; + newDst[4] = a[4]; + newDst[5] = a[5]; + newDst[6] = a[6]; + } + newDst[8] = v[0]; + newDst[9] = v[1]; + newDst[10] = 1; + return newDst; + } + /** + * Returns the translation component of a 3-by-3 matrix as a vector with 3 + * entries. + * @param m - The matrix. + * @param dst - vector to hold result. If not passed a new one is created. + * @returns The translation component of m. + */ + function getTranslation(m, dst) { + const newDst = (dst ?? vec2.create()); + newDst[0] = m[8]; + newDst[1] = m[9]; + return newDst; + } + /** + * Returns an axis of a 3x3 matrix as a vector with 2 entries + * @param m - The matrix. + * @param axis - The axis 0 = x, 1 = y, + * @returns The axis component of m. + */ + function getAxis(m, axis, dst) { + const newDst = (dst ?? vec2.create()); + const off = axis * 4; + newDst[0] = m[off + 0]; + newDst[1] = m[off + 1]; + return newDst; + } + /** + * Sets an axis of a 3x3 matrix as a vector with 2 entries + * @param m - The matrix. + * @param v - the axis vector + * @param axis - The axis 0 = x, 1 = y; + * @param dst - The matrix to set. If not passed a new one is created. + * @returns The matrix with axis set. + */ + function setAxis(m, v, axis, dst) { + const newDst = (dst === m ? m : copy(m, dst)); + const off = axis * 4; + newDst[off + 0] = v[0]; + newDst[off + 1] = v[1]; + return newDst; + } + ///** + // * Returns the scaling component of the matrix + // * @param m - The Matrix + // * @param dst - The vector to set. If not passed a new one is created. + // */ + function getScaling(m, dst) { + const newDst = (dst ?? vec2.create()); + const xx = m[0]; + const xy = m[1]; + const yx = m[4]; + const yy = m[5]; + newDst[0] = Math.sqrt(xx * xx + xy * xy); + newDst[1] = Math.sqrt(yx * yx + yy * yy); + return newDst; + } + /** + * Creates a 3-by-3 matrix which translates by the given vector v. + * @param v - The vector by which to translate. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The translation matrix. + */ + function translation(v, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = 1; + newDst[1] = 0; + newDst[2] = 0; + newDst[4] = 0; + newDst[5] = 1; + newDst[6] = 0; + newDst[8] = v[0]; + newDst[9] = v[1]; + newDst[10] = 1; + return newDst; + } + /** + * Translates the given 3-by-3 matrix by the given vector v. + * @param m - The matrix. + * @param v - The vector by which to translate. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The translated matrix. + */ + function translate(m, v, dst) { + const newDst = (dst ?? new Ctor(12)); + const v0 = v[0]; + const v1 = v[1]; + const m00 = m[0]; + const m01 = m[1]; + const m02 = m[2]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + if (m !== newDst) { + newDst[0] = m00; + newDst[1] = m01; + newDst[2] = m02; + newDst[4] = m10; + newDst[5] = m11; + newDst[6] = m12; + } + newDst[8] = m00 * v0 + m10 * v1 + m20; + newDst[9] = m01 * v0 + m11 * v1 + m21; + newDst[10] = m02 * v0 + m12 * v1 + m22; + return newDst; + } + /** + * Creates a 3-by-3 matrix which rotates by the given angle. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotation matrix. + */ + function rotation(angleInRadians, dst) { + const newDst = (dst ?? new Ctor(12)); + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = c; + newDst[1] = s; + newDst[2] = 0; + newDst[4] = -s; + newDst[5] = c; + newDst[6] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + return newDst; + } + /** + * Rotates the given 3-by-3 matrix by the given angle. + * @param m - The matrix. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotated matrix. + */ + function rotate(m, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(12)); + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = c * m00 + s * m10; + newDst[1] = c * m01 + s * m11; + newDst[2] = c * m02 + s * m12; + newDst[4] = c * m10 - s * m00; + newDst[5] = c * m11 - s * m01; + newDst[6] = c * m12 - s * m02; + if (m !== newDst) { + newDst[8] = m[8]; + newDst[9] = m[9]; + newDst[10] = m[10]; + } + return newDst; + } + /** + * Creates a 3-by-3 matrix which scales in each dimension by an amount given by + * the corresponding entry in the given vector; assumes the vector has three + * entries. + * @param v - A vector of + * 2 entries specifying the factor by which to scale in each dimension. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaling matrix. + */ + function scaling(v, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = v[0]; + newDst[1] = 0; + newDst[2] = 0; + newDst[4] = 0; + newDst[5] = v[1]; + newDst[6] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + return newDst; + } + /** + * Scales the given 3-by-3 matrix in each dimension by an amount + * given by the corresponding entry in the given vector; assumes the vector has + * three entries. + * @param m - The matrix to be modified. + * @param v - A vector of 2 entries specifying the + * factor by which to scale in each dimension. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaled matrix. + */ + function scale(m, v, dst) { + const newDst = (dst ?? new Ctor(12)); + const v0 = v[0]; + const v1 = v[1]; + newDst[0] = v0 * m[0 * 4 + 0]; + newDst[1] = v0 * m[0 * 4 + 1]; + newDst[2] = v0 * m[0 * 4 + 2]; + newDst[4] = v1 * m[1 * 4 + 0]; + newDst[5] = v1 * m[1 * 4 + 1]; + newDst[6] = v1 * m[1 * 4 + 2]; + if (m !== newDst) { + newDst[8] = m[8]; + newDst[9] = m[9]; + newDst[10] = m[10]; + } + return newDst; + } + /** + * Creates a 3-by-3 matrix which scales uniformly in each dimension + * @param s - Amount to scale + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaling matrix. + */ + function uniformScaling(s, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = s; + newDst[1] = 0; + newDst[2] = 0; + newDst[4] = 0; + newDst[5] = s; + newDst[6] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + return newDst; + } + /** + * Scales the given 3-by-3 matrix in each dimension by an amount + * given. + * @param m - The matrix to be modified. + * @param s - Amount to scale. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaled matrix. + */ + function uniformScale(m, s, dst) { + const newDst = (dst ?? new Ctor(12)); + newDst[0] = s * m[0 * 4 + 0]; + newDst[1] = s * m[0 * 4 + 1]; + newDst[2] = s * m[0 * 4 + 2]; + newDst[4] = s * m[1 * 4 + 0]; + newDst[5] = s * m[1 * 4 + 1]; + newDst[6] = s * m[1 * 4 + 2]; + if (m !== newDst) { + newDst[8] = m[8]; + newDst[9] = m[9]; + newDst[10] = m[10]; + } + return newDst; + } + return { + clone, + create, + set, + fromMat4, + fromQuat, + negate, + copy, + equalsApproximately, + equals, + identity, + transpose, + inverse, + invert, + determinant, + mul, + multiply, + setTranslation, + getTranslation, + getAxis, + setAxis, + getScaling, + translation, + translate, + rotation, + rotate, + scaling, + scale, + uniformScaling, + uniformScale, + }; } -/** - * Transform vec4 by upper 3x3 matrix inside 4x4 matrix. - * @param v - The direction. - * @param m - The matrix. - * @param dst - optional Vec3 to store result. If not passed a new one is created. - * @returns The transformed vector. - */ -function transformMat4Upper3x3(v, m, dst) { - dst = dst || new VecType$1(3); - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0]; - dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1]; - dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2]; - return dst; +const cache$4 = new Map(); +function getAPI$4(Ctor) { + let api = cache$4.get(Ctor); + if (!api) { + api = getAPIImpl$4(Ctor); + cache$4.set(Ctor, api); + } + return api; } -/** - * Transforms vec3 by 3x3 matrix + +/* + * Copyright 2022 Gregg Tavares * - * @param v - the vector - * @param m - The matrix. - * @param dst - optional vec3 to store result. If not passed a new one is created. - * @returns the transformed vector - */ -function transformMat3(v, m, dst) { - dst = dst || new VecType$1(3); - const x = v[0]; - const y = v[1]; - const z = v[2]; - dst[0] = x * m[0] + y * m[4] + z * m[8]; - dst[1] = x * m[1] + y * m[5] + z * m[9]; - dst[2] = x * m[2] + y * m[6] + z * m[10]; - return dst; -} -/** - * Transforms vec3 by Quaternion - * @param v - the vector to transform - * @param q - the quaternion to transform by - * @param dst - optional vec3 to store result. If not passed a new one is created. - * @returns the transformed + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -function transformQuat(v, q, dst) { - dst = dst || new VecType$1(3); - const qx = q[0]; - const qy = q[1]; - const qz = q[2]; - const w2 = q[3] * 2; - const x = v[0]; - const y = v[1]; - const z = v[2]; - const uvX = qy * z - qz * y; - const uvY = qz * x - qx * z; - const uvZ = qx * y - qy * x; - dst[0] = x + uvX * w2 + (qy * uvZ - qz * uvY) * 2; - dst[1] = y + uvY * w2 + (qz * uvX - qx * uvZ) * 2; - dst[2] = z + uvZ * w2 + (qx * uvY - qy * uvX) * 2; - return dst; -} /** - * Returns the translation component of a 4-by-4 matrix as a vector with 3 - * entries. - * @param m - The matrix. - * @param dst - vector to hold result. If not passed a new one is created. - * @returns The translation component of m. - */ -function getTranslation$1(m, dst) { - dst = dst || new VecType$1(3); - dst[0] = m[12]; - dst[1] = m[13]; - dst[2] = m[14]; - return dst; + * Generates am typed API for Vec3 + * */ +function getAPIImpl$3(Ctor) { + /** + * Creates a vec3; may be called with x, y, z to set initial values. + * @param x - Initial x value. + * @param y - Initial y value. + * @param z - Initial z value. + * @returns the created vector + */ + function create(x, y, z) { + const newDst = new Ctor(3); + if (x !== undefined) { + newDst[0] = x; + if (y !== undefined) { + newDst[1] = y; + if (z !== undefined) { + newDst[2] = z; + } + } + } + return newDst; + } + /** + * Creates a vec3; may be called with x, y, z to set initial values. (same as create) + * @param x - Initial x value. + * @param y - Initial y value. + * @param z - Initial z value. + * @returns the created vector + */ + const fromValues = create; + /** + * Sets the values of a Vec3 + * Also see {@link vec3.create} and {@link vec3.copy} + * + * @param x first value + * @param y second value + * @param z third value + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector with its elements set. + */ + function set(x, y, z, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = x; + newDst[1] = y; + newDst[2] = z; + return newDst; + } + /** + * Applies Math.ceil to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the ceil of each element of v. + */ + function ceil(v, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = Math.ceil(v[0]); + newDst[1] = Math.ceil(v[1]); + newDst[2] = Math.ceil(v[2]); + return newDst; + } + /** + * Applies Math.floor to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the floor of each element of v. + */ + function floor(v, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = Math.floor(v[0]); + newDst[1] = Math.floor(v[1]); + newDst[2] = Math.floor(v[2]); + return newDst; + } + /** + * Applies Math.round to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the round of each element of v. + */ + function round(v, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = Math.round(v[0]); + newDst[1] = Math.round(v[1]); + newDst[2] = Math.round(v[2]); + return newDst; + } + /** + * Clamp each element of vector between min and max + * @param v - Operand vector. + * @param max - Min value, default 0 + * @param min - Max value, default 1 + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that the clamped value of each element of v. + */ + function clamp(v, min = 0, max = 1, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = Math.min(max, Math.max(min, v[0])); + newDst[1] = Math.min(max, Math.max(min, v[1])); + newDst[2] = Math.min(max, Math.max(min, v[2])); + return newDst; + } + /** + * Adds two vectors; assumes a and b have the same dimension. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the sum of a and b. + */ + function add(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] + b[0]; + newDst[1] = a[1] + b[1]; + newDst[2] = a[2] + b[2]; + return newDst; + } + /** + * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension. + * @param a - Operand vector. + * @param b - Operand vector. + * @param scale - Amount to scale b + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the sum of a + b * scale. + */ + function addScaled(a, b, scale, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] + b[0] * scale; + newDst[1] = a[1] + b[1] * scale; + newDst[2] = a[2] + b[2] * scale; + return newDst; + } + /** + * Returns the angle in radians between two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @returns The angle in radians between the 2 vectors. + */ + function angle(a, b) { + const ax = a[0]; + const ay = a[1]; + const az = a[2]; + const bx = b[0]; + const by = b[1]; + const bz = b[2]; + const mag1 = Math.sqrt(ax * ax + ay * ay + az * az); + const mag2 = Math.sqrt(bx * bx + by * by + bz * bz); + const mag = mag1 * mag2; + const cosine = mag && dot(a, b) / mag; + return Math.acos(cosine); + } + /** + * Subtracts two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the difference of a and b. + */ + function subtract(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] - b[0]; + newDst[1] = a[1] - b[1]; + newDst[2] = a[2] - b[2]; + return newDst; + } + /** + * Subtracts two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the difference of a and b. + */ + const sub = subtract; + /** + * Check if 2 vectors are approximately equal + * @param a - Operand vector. + * @param b - Operand vector. + * @returns true if vectors are approximately equal + */ + function equalsApproximately(a, b) { + return Math.abs(a[0] - b[0]) < EPSILON && + Math.abs(a[1] - b[1]) < EPSILON && + Math.abs(a[2] - b[2]) < EPSILON; + } + /** + * Check if 2 vectors are exactly equal + * @param a - Operand vector. + * @param b - Operand vector. + * @returns true if vectors are exactly equal + */ + function equals(a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2]; + } + /** + * Performs linear interpolation on two vectors. + * Given vectors a and b and interpolation coefficient t, returns + * a + t * (b - a). + * @param a - Operand vector. + * @param b - Operand vector. + * @param t - Interpolation coefficient. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The linear interpolated result. + */ + function lerp(a, b, t, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] + t * (b[0] - a[0]); + newDst[1] = a[1] + t * (b[1] - a[1]); + newDst[2] = a[2] + t * (b[2] - a[2]); + return newDst; + } + /** + * Performs linear interpolation on two vectors. + * Given vectors a and b and interpolation coefficient vector t, returns + * a + t * (b - a). + * @param a - Operand vector. + * @param b - Operand vector. + * @param t - Interpolation coefficients vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns the linear interpolated result. + */ + function lerpV(a, b, t, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] + t[0] * (b[0] - a[0]); + newDst[1] = a[1] + t[1] * (b[1] - a[1]); + newDst[2] = a[2] + t[2] * (b[2] - a[2]); + return newDst; + } + /** + * Return max values of two vectors. + * Given vectors a and b returns + * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])]. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The max components vector. + */ + function max(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = Math.max(a[0], b[0]); + newDst[1] = Math.max(a[1], b[1]); + newDst[2] = Math.max(a[2], b[2]); + return newDst; + } + /** + * Return min values of two vectors. + * Given vectors a and b returns + * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])]. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The min components vector. + */ + function min(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = Math.min(a[0], b[0]); + newDst[1] = Math.min(a[1], b[1]); + newDst[2] = Math.min(a[2], b[2]); + return newDst; + } + /** + * Multiplies a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + function mulScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = v[0] * k; + newDst[1] = v[1] * k; + newDst[2] = v[2] * k; + return newDst; + } + /** + * Multiplies a vector by a scalar. (same as mulScalar) + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + const scale = mulScalar; + /** + * Divides a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + function divScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = v[0] / k; + newDst[1] = v[1] / k; + newDst[2] = v[2] / k; + return newDst; + } + /** + * Inverse a vector. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The inverted vector. + */ + function inverse(v, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = 1 / v[0]; + newDst[1] = 1 / v[1]; + newDst[2] = 1 / v[2]; + return newDst; + } + /** + * Invert a vector. (same as inverse) + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The inverted vector. + */ + const invert = inverse; + /** + * Computes the cross product of two vectors; assumes both vectors have + * three entries. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of a cross b. + */ + function cross(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + const t1 = a[2] * b[0] - a[0] * b[2]; + const t2 = a[0] * b[1] - a[1] * b[0]; + newDst[0] = a[1] * b[2] - a[2] * b[1]; + newDst[1] = t1; + newDst[2] = t2; + return newDst; + } + /** + * Computes the dot product of two vectors; assumes both vectors have + * three entries. + * @param a - Operand vector. + * @param b - Operand vector. + * @returns dot product + */ + function dot(a, b) { + return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]); + } + /** + * Computes the length of vector + * @param v - vector. + * @returns length of vector. + */ + function length(v) { + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2); + } + /** + * Computes the length of vector (same as length) + * @param v - vector. + * @returns length of vector. + */ + const len = length; + /** + * Computes the square of the length of vector + * @param v - vector. + * @returns square of the length of vector. + */ + function lengthSq(v) { + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + return v0 * v0 + v1 * v1 + v2 * v2; + } + /** + * Computes the square of the length of vector (same as lengthSq) + * @param v - vector. + * @returns square of the length of vector. + */ + const lenSq = lengthSq; + /** + * Computes the distance between 2 points + * @param a - vector. + * @param b - vector. + * @returns distance between a and b + */ + function distance(a, b) { + const dx = a[0] - b[0]; + const dy = a[1] - b[1]; + const dz = a[2] - b[2]; + return Math.sqrt(dx * dx + dy * dy + dz * dz); + } + /** + * Computes the distance between 2 points (same as distance) + * @param a - vector. + * @param b - vector. + * @returns distance between a and b + */ + const dist = distance; + /** + * Computes the square of the distance between 2 points + * @param a - vector. + * @param b - vector. + * @returns square of the distance between a and b + */ + function distanceSq(a, b) { + const dx = a[0] - b[0]; + const dy = a[1] - b[1]; + const dz = a[2] - b[2]; + return dx * dx + dy * dy + dz * dz; + } + /** + * Computes the square of the distance between 2 points (same as distanceSq) + * @param a - vector. + * @param b - vector. + * @returns square of the distance between a and b + */ + const distSq = distanceSq; + /** + * Divides a vector by its Euclidean length and returns the quotient. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The normalized vector. + */ + function normalize(v, dst) { + const newDst = (dst ?? new Ctor(3)); + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2); + if (len > 0.00001) { + newDst[0] = v0 / len; + newDst[1] = v1 / len; + newDst[2] = v2 / len; + } + else { + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + } + return newDst; + } + /** + * Negates a vector. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns -v. + */ + function negate(v, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = -v[0]; + newDst[1] = -v[1]; + newDst[2] = -v[2]; + return newDst; + } + /** + * Copies a vector. (same as {@link vec3.clone}) + * Also see {@link vec3.create} and {@link vec3.set} + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A copy of v. + */ + function copy(v, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = v[0]; + newDst[1] = v[1]; + newDst[2] = v[2]; + return newDst; + } + /** + * Clones a vector. (same as {@link vec3.copy}) + * Also see {@link vec3.create} and {@link vec3.set} + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A copy of v. + */ + const clone = copy; + /** + * Multiplies a vector by another vector (component-wise); assumes a and + * b have the same length. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of products of entries of a and b. + */ + function multiply(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] * b[0]; + newDst[1] = a[1] * b[1]; + newDst[2] = a[2] * b[2]; + return newDst; + } + /** + * Multiplies a vector by another vector (component-wise); assumes a and + * b have the same length. (same as mul) + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of products of entries of a and b. + */ + const mul = multiply; + /** + * Divides a vector by another vector (component-wise); assumes a and + * b have the same length. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of quotients of entries of a and b. + */ + function divide(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = a[0] / b[0]; + newDst[1] = a[1] / b[1]; + newDst[2] = a[2] / b[2]; + return newDst; + } + /** + * Divides a vector by another vector (component-wise); assumes a and + * b have the same length. (same as divide) + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of quotients of entries of a and b. + */ + const div = divide; + /** + * Creates a random vector + * @param scale - Default 1 + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The random vector. + */ + function random(scale = 1, dst) { + const newDst = (dst ?? new Ctor(3)); + const angle = Math.random() * 2 * Math.PI; + const z = Math.random() * 2 - 1; + const zScale = Math.sqrt(1 - z * z) * scale; + newDst[0] = Math.cos(angle) * zScale; + newDst[1] = Math.sin(angle) * zScale; + newDst[2] = z * scale; + return newDst; + } + /** + * Zero's a vector + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The zeroed vector. + */ + function zero(dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + return newDst; + } + /** + * transform vec3 by 4x4 matrix + * @param v - the vector + * @param m - The matrix. + * @param dst - optional vec3 to store result. If not passed a new one is created. + * @returns the transformed vector + */ + function transformMat4(v, m, dst) { + const newDst = (dst ?? new Ctor(3)); + const x = v[0]; + const y = v[1]; + const z = v[2]; + const w = (m[3] * x + m[7] * y + m[11] * z + m[15]) || 1; + newDst[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; + newDst[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; + newDst[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; + return newDst; + } + /** + * Transform vec3 by upper 3x3 matrix inside 4x4 matrix. + * @param v - The direction. + * @param m - The matrix. + * @param dst - optional vec3 to store result. If not passed a new one is created. + * @returns The transformed vector. + */ + function transformMat4Upper3x3(v, m, dst) { + const newDst = (dst ?? new Ctor(3)); + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + newDst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0]; + newDst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1]; + newDst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2]; + return newDst; + } + /** + * Transforms vec3 by 3x3 matrix + * + * @param v - the vector + * @param m - The matrix. + * @param dst - optional vec3 to store result. If not passed a new one is created. + * @returns the transformed vector + */ + function transformMat3(v, m, dst) { + const newDst = (dst ?? new Ctor(3)); + const x = v[0]; + const y = v[1]; + const z = v[2]; + newDst[0] = x * m[0] + y * m[4] + z * m[8]; + newDst[1] = x * m[1] + y * m[5] + z * m[9]; + newDst[2] = x * m[2] + y * m[6] + z * m[10]; + return newDst; + } + /** + * Transforms vec3 by Quaternion + * @param v - the vector to transform + * @param q - the quaternion to transform by + * @param dst - optional vec3 to store result. If not passed a new one is created. + * @returns the transformed + */ + function transformQuat(v, q, dst) { + const newDst = (dst ?? new Ctor(3)); + const qx = q[0]; + const qy = q[1]; + const qz = q[2]; + const w2 = q[3] * 2; + const x = v[0]; + const y = v[1]; + const z = v[2]; + const uvX = qy * z - qz * y; + const uvY = qz * x - qx * z; + const uvZ = qx * y - qy * x; + newDst[0] = x + uvX * w2 + (qy * uvZ - qz * uvY) * 2; + newDst[1] = y + uvY * w2 + (qz * uvX - qx * uvZ) * 2; + newDst[2] = z + uvZ * w2 + (qx * uvY - qy * uvX) * 2; + return newDst; + } + /** + * Returns the translation component of a 4-by-4 matrix as a vector with 3 + * entries. + * @param m - The matrix. + * @param dst - vector to hold result. If not passed a new one is created. + * @returns The translation component of m. + */ + function getTranslation(m, dst) { + const newDst = (dst ?? new Ctor(3)); + newDst[0] = m[12]; + newDst[1] = m[13]; + newDst[2] = m[14]; + return newDst; + } + /** + * Returns an axis of a 4x4 matrix as a vector with 3 entries + * @param m - The matrix. + * @param axis - The axis 0 = x, 1 = y, 2 = z; + * @returns The axis component of m. + */ + function getAxis(m, axis, dst) { + const newDst = (dst ?? new Ctor(3)); + const off = axis * 4; + newDst[0] = m[off + 0]; + newDst[1] = m[off + 1]; + newDst[2] = m[off + 2]; + return newDst; + } + /** + * Returns the scaling component of the matrix + * @param m - The Matrix + * @param dst - The vector to set. If not passed a new one is created. + */ + function getScaling(m, dst) { + const newDst = (dst ?? new Ctor(3)); + const xx = m[0]; + const xy = m[1]; + const xz = m[2]; + const yx = m[4]; + const yy = m[5]; + const yz = m[6]; + const zx = m[8]; + const zy = m[9]; + const zz = m[10]; + newDst[0] = Math.sqrt(xx * xx + xy * xy + xz * xz); + newDst[1] = Math.sqrt(yx * yx + yy * yy + yz * yz); + newDst[2] = Math.sqrt(zx * zx + zy * zy + zz * zz); + return newDst; + } + /** + * Rotate a 3D vector around the x-axis + * + * @param {ReadonlyVec3} a The vec3 point to rotate + * @param {ReadonlyVec3} b The origin of the rotation + * @param {Number} rad The angle of rotation in radians + * @param dst - The vector to set. If not passed a new one is created. + * @returns the rotated vector + */ + function rotateX(a, b, rad, dst) { + const newDst = (dst ?? new Ctor(3)); + const p = []; + const r = []; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + //perform rotation + r[0] = p[0]; + r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad); + r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); + //translate to correct position + newDst[0] = r[0] + b[0]; + newDst[1] = r[1] + b[1]; + newDst[2] = r[2] + b[2]; + return newDst; + } + /** + * Rotate a 3D vector around the y-axis + * + * @param {ReadonlyVec3} a The vec3 point to rotate + * @param {ReadonlyVec3} b The origin of the rotation + * @param {Number} rad The angle of rotation in radians + * @param dst - The vector to set. If not passed a new one is created. + * @returns the rotated vector + */ + function rotateY(a, b, rad, dst) { + const newDst = (dst ?? new Ctor(3)); + const p = []; + const r = []; + // translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + // perform rotation + r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad); + r[1] = p[1]; + r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); + // translate to correct position + newDst[0] = r[0] + b[0]; + newDst[1] = r[1] + b[1]; + newDst[2] = r[2] + b[2]; + return newDst; + } + /** + * Rotate a 3D vector around the z-axis + * + * @param {ReadonlyVec3} a The vec3 point to rotate + * @param {ReadonlyVec3} b The origin of the rotation + * @param {Number} rad The angle of rotation in radians + * @param dst - The vector to set. If not passed a new one is created. + * @returns {vec3} out + */ + function rotateZ(a, b, rad, dst) { + const newDst = (dst ?? new Ctor(3)); + const p = []; + const r = []; + // translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + // perform rotation + r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad); + r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad); + r[2] = p[2]; + // translate to correct position + newDst[0] = r[0] + b[0]; + newDst[1] = r[1] + b[1]; + newDst[2] = r[2] + b[2]; + return newDst; + } + /** + * Treat a 3D vector as a direction and set it's length + * + * @param a The vec3 to lengthen + * @param len The length of the resulting vector + * @returns The lengthened vector + */ + function setLength(a, len, dst) { + const newDst = (dst ?? new Ctor(3)); + normalize(a, newDst); + return mulScalar(newDst, len, newDst); + } + /** + * Ensure a vector is not longer than a max length + * + * @param a The vec3 to limit + * @param maxLen The longest length of the resulting vector + * @returns The vector, shortened to maxLen if it's too long + */ + function truncate(a, maxLen, dst) { + const newDst = (dst ?? new Ctor(3)); + if (length(a) > maxLen) { + return setLength(a, maxLen, newDst); + } + return copy(a, newDst); + } + /** + * Return the vector exactly between 2 endpoint vectors + * + * @param a Endpoint 1 + * @param b Endpoint 2 + * @returns The vector exactly residing between endpoints 1 and 2 + */ + function midpoint(a, b, dst) { + const newDst = (dst ?? new Ctor(3)); + return lerp(a, b, 0.5, newDst); + } + return { + create, + fromValues, + set, + ceil, + floor, + round, + clamp, + add, + addScaled, + angle, + subtract, + sub, + equalsApproximately, + equals, + lerp, + lerpV, + max, + min, + mulScalar, + scale, + divScalar, + inverse, + invert, + cross, + dot, + length, + len, + lengthSq, + lenSq, + distance, + dist, + distanceSq, + distSq, + normalize, + negate, + copy, + clone, + multiply, + mul, + divide, + div, + random, + zero, + transformMat4, + transformMat4Upper3x3, + transformMat3, + transformQuat, + getTranslation, + getAxis, + getScaling, + rotateX, + rotateY, + rotateZ, + setLength, + truncate, + midpoint, + }; } -/** - * Returns an axis of a 4x4 matrix as a vector with 3 entries - * @param m - The matrix. - * @param axis - The axis 0 = x, 1 = y, 2 = z; - * @returns The axis component of m. - */ -function getAxis$1(m, axis, dst) { - dst = dst || new VecType$1(3); - const off = axis * 4; - dst[0] = m[off + 0]; - dst[1] = m[off + 1]; - dst[2] = m[off + 2]; - return dst; +const cache$3 = new Map(); +function getAPI$3(Ctor) { + let api = cache$3.get(Ctor); + if (!api) { + api = getAPIImpl$3(Ctor); + cache$3.set(Ctor, api); + } + return api; } + /** - * Returns the scaling component of the matrix - * @param m - The Matrix - * @param dst - The vector to set. If not passed a new one is created. - */ -function getScaling$1(m, dst) { - dst = dst || new VecType$1(3); - const xx = m[0]; - const xy = m[1]; - const xz = m[2]; - const yx = m[4]; - const yy = m[5]; - const yz = m[6]; - const zx = m[8]; - const zy = m[9]; - const zz = m[10]; - dst[0] = Math.sqrt(xx * xx + xy * xy + xz * xz); - dst[1] = Math.sqrt(yx * yx + yy * yy + yz * yz); - dst[2] = Math.sqrt(zx * zx + zy * zy + zz * zz); - return dst; + * Generates a typed API for Mat4 + * */ +function getAPIImpl$2(Ctor) { + const vec3 = getAPI$3(Ctor); + /** + * 4x4 Matrix math math functions. + * + * Almost all functions take an optional `newDst` argument. If it is not passed in the + * functions will create a new matrix. In other words you can do this + * + * const mat = mat4.translation([1, 2, 3]); // Creates a new translation matrix + * + * or + * + * const mat = mat4.create(); + * mat4.translation([1, 2, 3], mat); // Puts translation matrix in mat. + * + * The first style is often easier but depending on where it's used it generates garbage where + * as there is almost never allocation with the second style. + * + * It is always save to pass any matrix as the destination. So for example + * + * const mat = mat4.identity(); + * const trans = mat4.translation([1, 2, 3]); + * mat4.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat. + * + */ + /** + * Create a Mat4 from values + * + * Note: Since passing in a raw JavaScript array + * is valid in all circumstances, if you want to + * force a JavaScript array into a Mat4's specified type + * it would be faster to use + * + * ``` + * const m = mat4.clone(someJSArray); + * ``` + * + * @param v0 - value for element 0 + * @param v1 - value for element 1 + * @param v2 - value for element 2 + * @param v3 - value for element 3 + * @param v4 - value for element 4 + * @param v5 - value for element 5 + * @param v6 - value for element 6 + * @param v7 - value for element 7 + * @param v8 - value for element 8 + * @param v9 - value for element 9 + * @param v10 - value for element 10 + * @param v11 - value for element 11 + * @param v12 - value for element 12 + * @param v13 - value for element 13 + * @param v14 - value for element 14 + * @param v15 - value for element 15 + * @returns created from values. + */ + function create(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) { + const newDst = new Ctor(16); + if (v0 !== undefined) { + newDst[0] = v0; + if (v1 !== undefined) { + newDst[1] = v1; + if (v2 !== undefined) { + newDst[2] = v2; + if (v3 !== undefined) { + newDst[3] = v3; + if (v4 !== undefined) { + newDst[4] = v4; + if (v5 !== undefined) { + newDst[5] = v5; + if (v6 !== undefined) { + newDst[6] = v6; + if (v7 !== undefined) { + newDst[7] = v7; + if (v8 !== undefined) { + newDst[8] = v8; + if (v9 !== undefined) { + newDst[9] = v9; + if (v10 !== undefined) { + newDst[10] = v10; + if (v11 !== undefined) { + newDst[11] = v11; + if (v12 !== undefined) { + newDst[12] = v12; + if (v13 !== undefined) { + newDst[13] = v13; + if (v14 !== undefined) { + newDst[14] = v14; + if (v15 !== undefined) { + newDst[15] = v15; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + return newDst; + } + /** + * Sets the values of a Mat4 + * Also see {@link mat4.create} and {@link mat4.copy} + * + * @param v0 - value for element 0 + * @param v1 - value for element 1 + * @param v2 - value for element 2 + * @param v3 - value for element 3 + * @param v4 - value for element 4 + * @param v5 - value for element 5 + * @param v6 - value for element 6 + * @param v7 - value for element 7 + * @param v8 - value for element 8 + * @param v9 - value for element 9 + * @param v10 - value for element 10 + * @param v11 - value for element 11 + * @param v12 - value for element 12 + * @param v13 - value for element 13 + * @param v14 - value for element 14 + * @param v15 - value for element 15 + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns Mat4 created from values. + */ + function set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = v0; + newDst[1] = v1; + newDst[2] = v2; + newDst[3] = v3; + newDst[4] = v4; + newDst[5] = v5; + newDst[6] = v6; + newDst[7] = v7; + newDst[8] = v8; + newDst[9] = v9; + newDst[10] = v10; + newDst[11] = v11; + newDst[12] = v12; + newDst[13] = v13; + newDst[14] = v14; + newDst[15] = v15; + return newDst; + } + /** + * Creates a Mat4 from a Mat3 + * @param m3 - source matrix + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns Mat4 made from m3 + */ + function fromMat3(m3, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = m3[0]; + newDst[1] = m3[1]; + newDst[2] = m3[2]; + newDst[3] = 0; + newDst[4] = m3[4]; + newDst[5] = m3[5]; + newDst[6] = m3[6]; + newDst[7] = 0; + newDst[8] = m3[8]; + newDst[9] = m3[9]; + newDst[10] = m3[10]; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Creates a Mat4 rotation matrix from a quaternion + * @param q - quaternion to create matrix from + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns Mat4 made from q + */ + function fromQuat(q, dst) { + const newDst = (dst ?? new Ctor(16)); + const x = q[0]; + const y = q[1]; + const z = q[2]; + const w = q[3]; + const x2 = x + x; + const y2 = y + y; + const z2 = z + z; + const xx = x * x2; + const yx = y * x2; + const yy = y * y2; + const zx = z * x2; + const zy = z * y2; + const zz = z * z2; + const wx = w * x2; + const wy = w * y2; + const wz = w * z2; + newDst[0] = 1 - yy - zz; + newDst[1] = yx + wz; + newDst[2] = zx - wy; + newDst[3] = 0; + newDst[4] = yx - wz; + newDst[5] = 1 - xx - zz; + newDst[6] = zy + wx; + newDst[7] = 0; + newDst[8] = zx + wy; + newDst[9] = zy - wx; + newDst[10] = 1 - xx - yy; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Negates a matrix. + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns -m. + */ + function negate(m, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = -m[0]; + newDst[1] = -m[1]; + newDst[2] = -m[2]; + newDst[3] = -m[3]; + newDst[4] = -m[4]; + newDst[5] = -m[5]; + newDst[6] = -m[6]; + newDst[7] = -m[7]; + newDst[8] = -m[8]; + newDst[9] = -m[9]; + newDst[10] = -m[10]; + newDst[11] = -m[11]; + newDst[12] = -m[12]; + newDst[13] = -m[13]; + newDst[14] = -m[14]; + newDst[15] = -m[15]; + return newDst; + } + /** + * Copies a matrix. (same as {@link mat4.clone}) + * Also see {@link mat4.create} and {@link mat4.set} + * @param m - The matrix. + * @param dst - The matrix. If not passed a new one is created. + * @returns A copy of m. + */ + function copy(m, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = m[0]; + newDst[1] = m[1]; + newDst[2] = m[2]; + newDst[3] = m[3]; + newDst[4] = m[4]; + newDst[5] = m[5]; + newDst[6] = m[6]; + newDst[7] = m[7]; + newDst[8] = m[8]; + newDst[9] = m[9]; + newDst[10] = m[10]; + newDst[11] = m[11]; + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + return newDst; + } + /** + * Copies a matrix (same as {@link mat4.copy}) + * Also see {@link mat4.create} and {@link mat4.set} + * @param m - The matrix. + * @param dst - The matrix. If not passed a new one is created. + * @returns A copy of m. + */ + const clone = copy; + /** + * Check if 2 matrices are approximately equal + * @param a - Operand matrix. + * @param b - Operand matrix. + * @returns true if matrices are approximately equal + */ + function equalsApproximately(a, b) { + return Math.abs(a[0] - b[0]) < EPSILON && + Math.abs(a[1] - b[1]) < EPSILON && + Math.abs(a[2] - b[2]) < EPSILON && + Math.abs(a[3] - b[3]) < EPSILON && + Math.abs(a[4] - b[4]) < EPSILON && + Math.abs(a[5] - b[5]) < EPSILON && + Math.abs(a[6] - b[6]) < EPSILON && + Math.abs(a[7] - b[7]) < EPSILON && + Math.abs(a[8] - b[8]) < EPSILON && + Math.abs(a[9] - b[9]) < EPSILON && + Math.abs(a[10] - b[10]) < EPSILON && + Math.abs(a[11] - b[11]) < EPSILON && + Math.abs(a[12] - b[12]) < EPSILON && + Math.abs(a[13] - b[13]) < EPSILON && + Math.abs(a[14] - b[14]) < EPSILON && + Math.abs(a[15] - b[15]) < EPSILON; + } + /** + * Check if 2 matrices are exactly equal + * @param a - Operand matrix. + * @param b - Operand matrix. + * @returns true if matrices are exactly equal + */ + function equals(a, b) { + return a[0] === b[0] && + a[1] === b[1] && + a[2] === b[2] && + a[3] === b[3] && + a[4] === b[4] && + a[5] === b[5] && + a[6] === b[6] && + a[7] === b[7] && + a[8] === b[8] && + a[9] === b[9] && + a[10] === b[10] && + a[11] === b[11] && + a[12] === b[12] && + a[13] === b[13] && + a[14] === b[14] && + a[15] === b[15]; + } + /** + * Creates a 4-by-4 identity matrix. + * + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns A 4-by-4 identity matrix. + */ + function identity(dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = 1; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = 1; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Takes the transpose of a matrix. + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The transpose of m. + */ + function transpose(m, dst) { + const newDst = (dst ?? new Ctor(16)); + if (newDst === m) { + let t; + t = m[1]; + m[1] = m[4]; + m[4] = t; + t = m[2]; + m[2] = m[8]; + m[8] = t; + t = m[3]; + m[3] = m[12]; + m[12] = t; + t = m[6]; + m[6] = m[9]; + m[9] = t; + t = m[7]; + m[7] = m[13]; + m[13] = t; + t = m[11]; + m[11] = m[14]; + m[14] = t; + return newDst; + } + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m03 = m[0 * 4 + 3]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m13 = m[1 * 4 + 3]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + const m23 = m[2 * 4 + 3]; + const m30 = m[3 * 4 + 0]; + const m31 = m[3 * 4 + 1]; + const m32 = m[3 * 4 + 2]; + const m33 = m[3 * 4 + 3]; + newDst[0] = m00; + newDst[1] = m10; + newDst[2] = m20; + newDst[3] = m30; + newDst[4] = m01; + newDst[5] = m11; + newDst[6] = m21; + newDst[7] = m31; + newDst[8] = m02; + newDst[9] = m12; + newDst[10] = m22; + newDst[11] = m32; + newDst[12] = m03; + newDst[13] = m13; + newDst[14] = m23; + newDst[15] = m33; + return newDst; + } + /** + * Computes the inverse of a 4-by-4 matrix. + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The inverse of m. + */ + function inverse(m, dst) { + const newDst = (dst ?? new Ctor(16)); + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m03 = m[0 * 4 + 3]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m13 = m[1 * 4 + 3]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + const m23 = m[2 * 4 + 3]; + const m30 = m[3 * 4 + 0]; + const m31 = m[3 * 4 + 1]; + const m32 = m[3 * 4 + 2]; + const m33 = m[3 * 4 + 3]; + const tmp0 = m22 * m33; + const tmp1 = m32 * m23; + const tmp2 = m12 * m33; + const tmp3 = m32 * m13; + const tmp4 = m12 * m23; + const tmp5 = m22 * m13; + const tmp6 = m02 * m33; + const tmp7 = m32 * m03; + const tmp8 = m02 * m23; + const tmp9 = m22 * m03; + const tmp10 = m02 * m13; + const tmp11 = m12 * m03; + const tmp12 = m20 * m31; + const tmp13 = m30 * m21; + const tmp14 = m10 * m31; + const tmp15 = m30 * m11; + const tmp16 = m10 * m21; + const tmp17 = m20 * m11; + const tmp18 = m00 * m31; + const tmp19 = m30 * m01; + const tmp20 = m00 * m21; + const tmp21 = m20 * m01; + const tmp22 = m00 * m11; + const tmp23 = m10 * m01; + const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) - + (tmp1 * m11 + tmp2 * m21 + tmp5 * m31); + const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) - + (tmp0 * m01 + tmp7 * m21 + tmp8 * m31); + const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) - + (tmp3 * m01 + tmp6 * m11 + tmp11 * m31); + const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) - + (tmp4 * m01 + tmp9 * m11 + tmp10 * m21); + const d = 1 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3); + newDst[0] = d * t0; + newDst[1] = d * t1; + newDst[2] = d * t2; + newDst[3] = d * t3; + newDst[4] = d * ((tmp1 * m10 + tmp2 * m20 + tmp5 * m30) - + (tmp0 * m10 + tmp3 * m20 + tmp4 * m30)); + newDst[5] = d * ((tmp0 * m00 + tmp7 * m20 + tmp8 * m30) - + (tmp1 * m00 + tmp6 * m20 + tmp9 * m30)); + newDst[6] = d * ((tmp3 * m00 + tmp6 * m10 + tmp11 * m30) - + (tmp2 * m00 + tmp7 * m10 + tmp10 * m30)); + newDst[7] = d * ((tmp4 * m00 + tmp9 * m10 + tmp10 * m20) - + (tmp5 * m00 + tmp8 * m10 + tmp11 * m20)); + newDst[8] = d * ((tmp12 * m13 + tmp15 * m23 + tmp16 * m33) - + (tmp13 * m13 + tmp14 * m23 + tmp17 * m33)); + newDst[9] = d * ((tmp13 * m03 + tmp18 * m23 + tmp21 * m33) - + (tmp12 * m03 + tmp19 * m23 + tmp20 * m33)); + newDst[10] = d * ((tmp14 * m03 + tmp19 * m13 + tmp22 * m33) - + (tmp15 * m03 + tmp18 * m13 + tmp23 * m33)); + newDst[11] = d * ((tmp17 * m03 + tmp20 * m13 + tmp23 * m23) - + (tmp16 * m03 + tmp21 * m13 + tmp22 * m23)); + newDst[12] = d * ((tmp14 * m22 + tmp17 * m32 + tmp13 * m12) - + (tmp16 * m32 + tmp12 * m12 + tmp15 * m22)); + newDst[13] = d * ((tmp20 * m32 + tmp12 * m02 + tmp19 * m22) - + (tmp18 * m22 + tmp21 * m32 + tmp13 * m02)); + newDst[14] = d * ((tmp18 * m12 + tmp23 * m32 + tmp15 * m02) - + (tmp22 * m32 + tmp14 * m02 + tmp19 * m12)); + newDst[15] = d * ((tmp22 * m22 + tmp16 * m02 + tmp21 * m12) - + (tmp20 * m12 + tmp23 * m22 + tmp17 * m02)); + return newDst; + } + /** + * Compute the determinant of a matrix + * @param m - the matrix + * @returns the determinant + */ + function determinant(m) { + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m03 = m[0 * 4 + 3]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m13 = m[1 * 4 + 3]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + const m23 = m[2 * 4 + 3]; + const m30 = m[3 * 4 + 0]; + const m31 = m[3 * 4 + 1]; + const m32 = m[3 * 4 + 2]; + const m33 = m[3 * 4 + 3]; + const tmp0 = m22 * m33; + const tmp1 = m32 * m23; + const tmp2 = m12 * m33; + const tmp3 = m32 * m13; + const tmp4 = m12 * m23; + const tmp5 = m22 * m13; + const tmp6 = m02 * m33; + const tmp7 = m32 * m03; + const tmp8 = m02 * m23; + const tmp9 = m22 * m03; + const tmp10 = m02 * m13; + const tmp11 = m12 * m03; + const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) - + (tmp1 * m11 + tmp2 * m21 + tmp5 * m31); + const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) - + (tmp0 * m01 + tmp7 * m21 + tmp8 * m31); + const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) - + (tmp3 * m01 + tmp6 * m11 + tmp11 * m31); + const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) - + (tmp4 * m01 + tmp9 * m11 + tmp10 * m21); + return m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3; + } + /** + * Computes the inverse of a 4-by-4 matrix. (same as inverse) + * @param m - The matrix. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The inverse of m. + */ + const invert = inverse; + /** + * Multiplies two 4-by-4 matrices with a on the left and b on the right + * @param a - The matrix on the left. + * @param b - The matrix on the right. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The matrix product of a and b. + */ + function multiply(a, b, dst) { + const newDst = (dst ?? new Ctor(16)); + const a00 = a[0]; + const a01 = a[1]; + const a02 = a[2]; + const a03 = a[3]; + const a10 = a[4 + 0]; + const a11 = a[4 + 1]; + const a12 = a[4 + 2]; + const a13 = a[4 + 3]; + const a20 = a[8 + 0]; + const a21 = a[8 + 1]; + const a22 = a[8 + 2]; + const a23 = a[8 + 3]; + const a30 = a[12 + 0]; + const a31 = a[12 + 1]; + const a32 = a[12 + 2]; + const a33 = a[12 + 3]; + const b00 = b[0]; + const b01 = b[1]; + const b02 = b[2]; + const b03 = b[3]; + const b10 = b[4 + 0]; + const b11 = b[4 + 1]; + const b12 = b[4 + 2]; + const b13 = b[4 + 3]; + const b20 = b[8 + 0]; + const b21 = b[8 + 1]; + const b22 = b[8 + 2]; + const b23 = b[8 + 3]; + const b30 = b[12 + 0]; + const b31 = b[12 + 1]; + const b32 = b[12 + 2]; + const b33 = b[12 + 3]; + newDst[0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; + newDst[1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; + newDst[2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; + newDst[3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; + newDst[4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; + newDst[5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; + newDst[6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; + newDst[7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; + newDst[8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; + newDst[9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; + newDst[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; + newDst[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; + newDst[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; + newDst[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; + newDst[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; + newDst[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; + return newDst; + } + /** + * Multiplies two 4-by-4 matrices with a on the left and b on the right (same as multiply) + * @param a - The matrix on the left. + * @param b - The matrix on the right. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The matrix product of a and b. + */ + const mul = multiply; + /** + * Sets the translation component of a 4-by-4 matrix to the given + * vector. + * @param a - The matrix. + * @param v - The vector. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The matrix with translation set. + */ + function setTranslation(a, v, dst) { + const newDst = (dst ?? identity()); + if (a !== newDst) { + newDst[0] = a[0]; + newDst[1] = a[1]; + newDst[2] = a[2]; + newDst[3] = a[3]; + newDst[4] = a[4]; + newDst[5] = a[5]; + newDst[6] = a[6]; + newDst[7] = a[7]; + newDst[8] = a[8]; + newDst[9] = a[9]; + newDst[10] = a[10]; + newDst[11] = a[11]; + } + newDst[12] = v[0]; + newDst[13] = v[1]; + newDst[14] = v[2]; + newDst[15] = 1; + return newDst; + } + ///** + // * Returns the translation component of a 4-by-4 matrix as a vector with 3 + // * entries. + // * @param m - The matrix. + // * @param dst - vector to hold result. If not passed a new one is created. + // * @returns The translation component of m. + // */ + function getTranslation(m, dst) { + const newDst = (dst ?? vec3.create()); + newDst[0] = m[12]; + newDst[1] = m[13]; + newDst[2] = m[14]; + return newDst; + } + /** + * Returns an axis of a 4x4 matrix as a vector with 3 entries + * @param m - The matrix. + * @param axis - The axis 0 = x, 1 = y, 2 = z; + * @returns The axis component of m. + */ + function getAxis(m, axis, dst) { + const newDst = (dst ?? vec3.create()); + const off = axis * 4; + newDst[0] = m[off + 0]; + newDst[1] = m[off + 1]; + newDst[2] = m[off + 2]; + return newDst; + } + /** + * Sets an axis of a 4x4 matrix as a vector with 3 entries + * @param m - The matrix. + * @param v - the axis vector + * @param axis - The axis 0 = x, 1 = y, 2 = z; + * @param dst - The matrix to set. If not passed a new one is created. + * @returns The matrix with axis set. + */ + function setAxis(m, v, axis, dst) { + const newDst = (dst === m) ? dst : copy(m, dst); + const off = axis * 4; + newDst[off + 0] = v[0]; + newDst[off + 1] = v[1]; + newDst[off + 2] = v[2]; + return newDst; + } + ///** + // * Returns the scaling component of the matrix + // * @param m - The Matrix + // * @param dst - The vector to set. If not passed a new one is created. + // */ + function getScaling(m, dst) { + const newDst = (dst ?? vec3.create()); + const xx = m[0]; + const xy = m[1]; + const xz = m[2]; + const yx = m[4]; + const yy = m[5]; + const yz = m[6]; + const zx = m[8]; + const zy = m[9]; + const zz = m[10]; + newDst[0] = Math.sqrt(xx * xx + xy * xy + xz * xz); + newDst[1] = Math.sqrt(yx * yx + yy * yy + yz * yz); + newDst[2] = Math.sqrt(zx * zx + zy * zy + zz * zz); + return newDst; + } + /** + * Computes a 4-by-4 perspective transformation matrix given the angular height + * of the frustum, the aspect ratio, and the near and far clipping planes. The + * arguments define a frustum extending in the negative z direction. The given + * angle is the vertical angle of the frustum, and the horizontal angle is + * determined to produce the given aspect ratio. The arguments near and far are + * the distances to the near and far clipping planes. Note that near and far + * are not z coordinates, but rather they are distances along the negative + * z-axis. The matrix generated sends the viewing frustum to the unit box. + * We assume a unit box extending from -1 to 1 in the x and y dimensions and + * from 0 to 1 in the z dimension. + * + * Note: If you pass `Infinity` for zFar then it will produce a projection matrix + * returns -Infinity for Z when transforming coordinates with Z <= 0 and +Infinity for Z + * otherwise. + * + * @param fieldOfViewYInRadians - The camera angle from top to bottom (in radians). + * @param aspect - The aspect ratio width / height. + * @param zNear - The depth (negative z coordinate) + * of the near clipping plane. + * @param zFar - The depth (negative z coordinate) + * of the far clipping plane. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The perspective matrix. + */ + function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) { + const newDst = (dst ?? new Ctor(16)); + const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians); + newDst[0] = f / aspect; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = f; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[11] = -1; + newDst[12] = 0; + newDst[13] = 0; + newDst[15] = 0; + if (Number.isFinite(zFar)) { + const rangeInv = 1 / (zNear - zFar); + newDst[10] = zFar * rangeInv; + newDst[14] = zFar * zNear * rangeInv; + } + else { + newDst[10] = -1; + newDst[14] = -zNear; + } + return newDst; + } + /** + * Computes a 4-by-4 reverse-z perspective transformation matrix given the angular height + * of the frustum, the aspect ratio, and the near and far clipping planes. The + * arguments define a frustum extending in the negative z direction. The given + * angle is the vertical angle of the frustum, and the horizontal angle is + * determined to produce the given aspect ratio. The arguments near and far are + * the distances to the near and far clipping planes. Note that near and far + * are not z coordinates, but rather they are distances along the negative + * z-axis. The matrix generated sends the viewing frustum to the unit box. + * We assume a unit box extending from -1 to 1 in the x and y dimensions and + * from 1 (at -zNear) to 0 (at -zFar) in the z dimension. + * + * @param fieldOfViewYInRadians - The camera angle from top to bottom (in radians). + * @param aspect - The aspect ratio width / height. + * @param zNear - The depth (negative z coordinate) + * of the near clipping plane. + * @param zFar - The depth (negative z coordinate) + * of the far clipping plane. (default = Infinity) + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The perspective matrix. + */ function perspectiveReverseZ(fieldOfViewYInRadians, aspect, zNear, zFar = Infinity, dst) { + const newDst = (dst ?? new Ctor(16)); + const f = 1 / Math.tan(fieldOfViewYInRadians * 0.5); + newDst[0] = f / aspect; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = f; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[11] = -1; + newDst[12] = 0; + newDst[13] = 0; + newDst[15] = 0; + if (zFar === Infinity) { + newDst[10] = 0; + newDst[14] = zNear; + } + else { + const rangeInv = 1 / (zFar - zNear); + newDst[10] = zNear * rangeInv; + newDst[14] = zFar * zNear * rangeInv; + } + return newDst; + } + /** + * Computes a 4-by-4 orthogonal transformation matrix that transforms from + * the given the left, right, bottom, and top dimensions to -1 +1 in x, and y + * and 0 to +1 in z. + * @param left - Left side of the near clipping plane viewport. + * @param right - Right side of the near clipping plane viewport. + * @param bottom - Bottom of the near clipping plane viewport. + * @param top - Top of the near clipping plane viewport. + * @param near - The depth (negative z coordinate) + * of the near clipping plane. + * @param far - The depth (negative z coordinate) + * of the far clipping plane. + * @param dst - Output matrix. If not passed a new one is created. + * @returns The orthographic projection matrix. + */ + function ortho(left, right, bottom, top, near, far, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = 2 / (right - left); + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = 2 / (top - bottom); + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1 / (near - far); + newDst[11] = 0; + newDst[12] = (right + left) / (left - right); + newDst[13] = (top + bottom) / (bottom - top); + newDst[14] = near / (near - far); + newDst[15] = 1; + return newDst; + } + /** + * Computes a 4-by-4 perspective transformation matrix given the left, right, + * top, bottom, near and far clipping planes. The arguments define a frustum + * extending in the negative z direction. The arguments near and far are the + * distances to the near and far clipping planes. Note that near and far are not + * z coordinates, but rather they are distances along the negative z-axis. The + * matrix generated sends the viewing frustum to the unit box. We assume a unit + * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z + * dimension. + * @param left - The x coordinate of the left plane of the box. + * @param right - The x coordinate of the right plane of the box. + * @param bottom - The y coordinate of the bottom plane of the box. + * @param top - The y coordinate of the right plane of the box. + * @param near - The negative z coordinate of the near plane of the box. + * @param far - The negative z coordinate of the far plane of the box. + * @param dst - Output matrix. If not passed a new one is created. + * @returns The perspective projection matrix. + */ + function frustum(left, right, bottom, top, near, far, dst) { + const newDst = (dst ?? new Ctor(16)); + const dx = (right - left); + const dy = (top - bottom); + const dz = (near - far); + newDst[0] = 2 * near / dx; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = 2 * near / dy; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = (left + right) / dx; + newDst[9] = (top + bottom) / dy; + newDst[10] = far / dz; + newDst[11] = -1; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = near * far / dz; + newDst[15] = 0; + return newDst; + } + /** + * Computes a 4-by-4 reverse-z perspective transformation matrix given the left, right, + * top, bottom, near and far clipping planes. The arguments define a frustum + * extending in the negative z direction. The arguments near and far are the + * distances to the near and far clipping planes. Note that near and far are not + * z coordinates, but rather they are distances along the negative z-axis. The + * matrix generated sends the viewing frustum to the unit box. We assume a unit + * box extending from -1 to 1 in the x and y dimensions and from 1 (-near) to 0 (-far) in the z + * dimension. + * @param left - The x coordinate of the left plane of the box. + * @param right - The x coordinate of the right plane of the box. + * @param bottom - The y coordinate of the bottom plane of the box. + * @param top - The y coordinate of the right plane of the box. + * @param near - The negative z coordinate of the near plane of the box. + * @param far - The negative z coordinate of the far plane of the box. + * @param dst - Output matrix. If not passed a new one is created. + * @returns The perspective projection matrix. + */ + function frustumReverseZ(left, right, bottom, top, near, far = Infinity, dst) { + const newDst = (dst ?? new Ctor(16)); + const dx = (right - left); + const dy = (top - bottom); + newDst[0] = 2 * near / dx; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = 2 * near / dy; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = (left + right) / dx; + newDst[9] = (top + bottom) / dy; + newDst[11] = -1; + newDst[12] = 0; + newDst[13] = 0; + newDst[15] = 0; + if (far === Infinity) { + newDst[10] = 0; + newDst[14] = near; + } + else { + const rangeInv = 1 / (far - near); + newDst[10] = near * rangeInv; + newDst[14] = far * near * rangeInv; + } + return newDst; + } + const xAxis = vec3.create(); + const yAxis = vec3.create(); + const zAxis = vec3.create(); + /** + * Computes a 4-by-4 aim transformation. + * + * This is a matrix which positions an object aiming down positive Z. + * toward the target. + * + * Note: this is **NOT** the inverse of lookAt as lookAt looks at negative Z. + * + * @param position - The position of the object. + * @param target - The position meant to be aimed at. + * @param up - A vector pointing up. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The aim matrix. + */ + function aim(position, target, up, dst) { + const newDst = (dst ?? new Ctor(16)); + vec3.normalize(vec3.subtract(target, position, zAxis), zAxis); + vec3.normalize(vec3.cross(up, zAxis, xAxis), xAxis); + vec3.normalize(vec3.cross(zAxis, xAxis, yAxis), yAxis); + newDst[0] = xAxis[0]; + newDst[1] = xAxis[1]; + newDst[2] = xAxis[2]; + newDst[3] = 0; + newDst[4] = yAxis[0]; + newDst[5] = yAxis[1]; + newDst[6] = yAxis[2]; + newDst[7] = 0; + newDst[8] = zAxis[0]; + newDst[9] = zAxis[1]; + newDst[10] = zAxis[2]; + newDst[11] = 0; + newDst[12] = position[0]; + newDst[13] = position[1]; + newDst[14] = position[2]; + newDst[15] = 1; + return newDst; + } + /** + * Computes a 4-by-4 camera aim transformation. + * + * This is a matrix which positions an object aiming down negative Z. + * toward the target. + * + * Note: this is the inverse of `lookAt` + * + * @param eye - The position of the object. + * @param target - The position meant to be aimed at. + * @param up - A vector pointing up. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The aim matrix. + */ + function cameraAim(eye, target, up, dst) { + const newDst = (dst ?? new Ctor(16)); + vec3.normalize(vec3.subtract(eye, target, zAxis), zAxis); + vec3.normalize(vec3.cross(up, zAxis, xAxis), xAxis); + vec3.normalize(vec3.cross(zAxis, xAxis, yAxis), yAxis); + newDst[0] = xAxis[0]; + newDst[1] = xAxis[1]; + newDst[2] = xAxis[2]; + newDst[3] = 0; + newDst[4] = yAxis[0]; + newDst[5] = yAxis[1]; + newDst[6] = yAxis[2]; + newDst[7] = 0; + newDst[8] = zAxis[0]; + newDst[9] = zAxis[1]; + newDst[10] = zAxis[2]; + newDst[11] = 0; + newDst[12] = eye[0]; + newDst[13] = eye[1]; + newDst[14] = eye[2]; + newDst[15] = 1; + return newDst; + } + /** + * Computes a 4-by-4 view transformation. + * + * This is a view matrix which transforms all other objects + * to be in the space of the view defined by the parameters. + * + * @param eye - The position of the object. + * @param target - The position meant to be aimed at. + * @param up - A vector pointing up. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The look-at matrix. + */ + function lookAt(eye, target, up, dst) { + const newDst = (dst ?? new Ctor(16)); + vec3.normalize(vec3.subtract(eye, target, zAxis), zAxis); + vec3.normalize(vec3.cross(up, zAxis, xAxis), xAxis); + vec3.normalize(vec3.cross(zAxis, xAxis, yAxis), yAxis); + newDst[0] = xAxis[0]; + newDst[1] = yAxis[0]; + newDst[2] = zAxis[0]; + newDst[3] = 0; + newDst[4] = xAxis[1]; + newDst[5] = yAxis[1]; + newDst[6] = zAxis[1]; + newDst[7] = 0; + newDst[8] = xAxis[2]; + newDst[9] = yAxis[2]; + newDst[10] = zAxis[2]; + newDst[11] = 0; + newDst[12] = -(xAxis[0] * eye[0] + xAxis[1] * eye[1] + xAxis[2] * eye[2]); + newDst[13] = -(yAxis[0] * eye[0] + yAxis[1] * eye[1] + yAxis[2] * eye[2]); + newDst[14] = -(zAxis[0] * eye[0] + zAxis[1] * eye[1] + zAxis[2] * eye[2]); + newDst[15] = 1; + return newDst; + } + /** + * Creates a 4-by-4 matrix which translates by the given vector v. + * @param v - The vector by + * which to translate. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The translation matrix. + */ + function translation(v, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = 1; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = 1; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + newDst[11] = 0; + newDst[12] = v[0]; + newDst[13] = v[1]; + newDst[14] = v[2]; + newDst[15] = 1; + return newDst; + } + /** + * Translates the given 4-by-4 matrix by the given vector v. + * @param m - The matrix. + * @param v - The vector by + * which to translate. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The translated matrix. + */ + function translate(m, v, dst) { + const newDst = (dst ?? new Ctor(16)); + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const m00 = m[0]; + const m01 = m[1]; + const m02 = m[2]; + const m03 = m[3]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m13 = m[1 * 4 + 3]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + const m23 = m[2 * 4 + 3]; + const m30 = m[3 * 4 + 0]; + const m31 = m[3 * 4 + 1]; + const m32 = m[3 * 4 + 2]; + const m33 = m[3 * 4 + 3]; + if (m !== newDst) { + newDst[0] = m00; + newDst[1] = m01; + newDst[2] = m02; + newDst[3] = m03; + newDst[4] = m10; + newDst[5] = m11; + newDst[6] = m12; + newDst[7] = m13; + newDst[8] = m20; + newDst[9] = m21; + newDst[10] = m22; + newDst[11] = m23; + } + newDst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30; + newDst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31; + newDst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32; + newDst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33; + return newDst; + } + /** + * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotation matrix. + */ + function rotationX(angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = 1; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = c; + newDst[6] = s; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = -s; + newDst[10] = c; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Rotates the given 4-by-4 matrix around the x-axis by the given + * angle. + * @param m - The matrix. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotated matrix. + */ + function rotateX(m, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + const m10 = m[4]; + const m11 = m[5]; + const m12 = m[6]; + const m13 = m[7]; + const m20 = m[8]; + const m21 = m[9]; + const m22 = m[10]; + const m23 = m[11]; + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[4] = c * m10 + s * m20; + newDst[5] = c * m11 + s * m21; + newDst[6] = c * m12 + s * m22; + newDst[7] = c * m13 + s * m23; + newDst[8] = c * m20 - s * m10; + newDst[9] = c * m21 - s * m11; + newDst[10] = c * m22 - s * m12; + newDst[11] = c * m23 - s * m13; + if (m !== newDst) { + newDst[0] = m[0]; + newDst[1] = m[1]; + newDst[2] = m[2]; + newDst[3] = m[3]; + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + } + return newDst; + } + /** + * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotation matrix. + */ + function rotationY(angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = c; + newDst[1] = 0; + newDst[2] = -s; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = 1; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = s; + newDst[9] = 0; + newDst[10] = c; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Rotates the given 4-by-4 matrix around the y-axis by the given + * angle. + * @param m - The matrix. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotated matrix. + */ + function rotateY(m, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m03 = m[0 * 4 + 3]; + const m20 = m[2 * 4 + 0]; + const m21 = m[2 * 4 + 1]; + const m22 = m[2 * 4 + 2]; + const m23 = m[2 * 4 + 3]; + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = c * m00 - s * m20; + newDst[1] = c * m01 - s * m21; + newDst[2] = c * m02 - s * m22; + newDst[3] = c * m03 - s * m23; + newDst[8] = c * m20 + s * m00; + newDst[9] = c * m21 + s * m01; + newDst[10] = c * m22 + s * m02; + newDst[11] = c * m23 + s * m03; + if (m !== newDst) { + newDst[4] = m[4]; + newDst[5] = m[5]; + newDst[6] = m[6]; + newDst[7] = m[7]; + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + } + return newDst; + } + /** + * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotation matrix. + */ + function rotationZ(angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = c; + newDst[1] = s; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = -s; + newDst[5] = c; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = 1; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Rotates the given 4-by-4 matrix around the z-axis by the given + * angle. + * @param m - The matrix. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotated matrix. + */ + function rotateZ(m, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + const m00 = m[0 * 4 + 0]; + const m01 = m[0 * 4 + 1]; + const m02 = m[0 * 4 + 2]; + const m03 = m[0 * 4 + 3]; + const m10 = m[1 * 4 + 0]; + const m11 = m[1 * 4 + 1]; + const m12 = m[1 * 4 + 2]; + const m13 = m[1 * 4 + 3]; + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + newDst[0] = c * m00 + s * m10; + newDst[1] = c * m01 + s * m11; + newDst[2] = c * m02 + s * m12; + newDst[3] = c * m03 + s * m13; + newDst[4] = c * m10 - s * m00; + newDst[5] = c * m11 - s * m01; + newDst[6] = c * m12 - s * m02; + newDst[7] = c * m13 - s * m03; + if (m !== newDst) { + newDst[8] = m[8]; + newDst[9] = m[9]; + newDst[10] = m[10]; + newDst[11] = m[11]; + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + } + return newDst; + } + /** + * Creates a 4-by-4 matrix which rotates around the given axis by the given + * angle. + * @param axis - The axis + * about which to rotate. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns A matrix which rotates angle radians + * around the axis. + */ + function axisRotation(axis, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + let x = axis[0]; + let y = axis[1]; + let z = axis[2]; + const n = Math.sqrt(x * x + y * y + z * z); + x /= n; + y /= n; + z /= n; + const xx = x * x; + const yy = y * y; + const zz = z * z; + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + const oneMinusCosine = 1 - c; + newDst[0] = xx + (1 - xx) * c; + newDst[1] = x * y * oneMinusCosine + z * s; + newDst[2] = x * z * oneMinusCosine - y * s; + newDst[3] = 0; + newDst[4] = x * y * oneMinusCosine - z * s; + newDst[5] = yy + (1 - yy) * c; + newDst[6] = y * z * oneMinusCosine + x * s; + newDst[7] = 0; + newDst[8] = x * z * oneMinusCosine + y * s; + newDst[9] = y * z * oneMinusCosine - x * s; + newDst[10] = zz + (1 - zz) * c; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Creates a 4-by-4 matrix which rotates around the given axis by the given + * angle. (same as axisRotation) + * @param axis - The axis + * about which to rotate. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns A matrix which rotates angle radians + * around the axis. + */ + const rotation = axisRotation; + /** + * Rotates the given 4-by-4 matrix around the given axis by the + * given angle. + * @param m - The matrix. + * @param axis - The axis + * about which to rotate. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotated matrix. + */ + function axisRotate(m, axis, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(16)); + let x = axis[0]; + let y = axis[1]; + let z = axis[2]; + const n = Math.sqrt(x * x + y * y + z * z); + x /= n; + y /= n; + z /= n; + const xx = x * x; + const yy = y * y; + const zz = z * z; + const c = Math.cos(angleInRadians); + const s = Math.sin(angleInRadians); + const oneMinusCosine = 1 - c; + const r00 = xx + (1 - xx) * c; + const r01 = x * y * oneMinusCosine + z * s; + const r02 = x * z * oneMinusCosine - y * s; + const r10 = x * y * oneMinusCosine - z * s; + const r11 = yy + (1 - yy) * c; + const r12 = y * z * oneMinusCosine + x * s; + const r20 = x * z * oneMinusCosine + y * s; + const r21 = y * z * oneMinusCosine - x * s; + const r22 = zz + (1 - zz) * c; + const m00 = m[0]; + const m01 = m[1]; + const m02 = m[2]; + const m03 = m[3]; + const m10 = m[4]; + const m11 = m[5]; + const m12 = m[6]; + const m13 = m[7]; + const m20 = m[8]; + const m21 = m[9]; + const m22 = m[10]; + const m23 = m[11]; + newDst[0] = r00 * m00 + r01 * m10 + r02 * m20; + newDst[1] = r00 * m01 + r01 * m11 + r02 * m21; + newDst[2] = r00 * m02 + r01 * m12 + r02 * m22; + newDst[3] = r00 * m03 + r01 * m13 + r02 * m23; + newDst[4] = r10 * m00 + r11 * m10 + r12 * m20; + newDst[5] = r10 * m01 + r11 * m11 + r12 * m21; + newDst[6] = r10 * m02 + r11 * m12 + r12 * m22; + newDst[7] = r10 * m03 + r11 * m13 + r12 * m23; + newDst[8] = r20 * m00 + r21 * m10 + r22 * m20; + newDst[9] = r20 * m01 + r21 * m11 + r22 * m21; + newDst[10] = r20 * m02 + r21 * m12 + r22 * m22; + newDst[11] = r20 * m03 + r21 * m13 + r22 * m23; + if (m !== newDst) { + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + } + return newDst; + } + /** + * Rotates the given 4-by-4 matrix around the given axis by the + * given angle. (same as rotate) + * @param m - The matrix. + * @param axis - The axis + * about which to rotate. + * @param angleInRadians - The angle by which to rotate (in radians). + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The rotated matrix. + */ + const rotate = axisRotate; + /** + * Creates a 4-by-4 matrix which scales in each dimension by an amount given by + * the corresponding entry in the given vector; assumes the vector has three + * entries. + * @param v - A vector of + * three entries specifying the factor by which to scale in each dimension. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaling matrix. + */ + function scaling(v, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = v[0]; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = v[1]; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = v[2]; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Scales the given 4-by-4 matrix in each dimension by an amount + * given by the corresponding entry in the given vector; assumes the vector has + * three entries. + * @param m - The matrix to be modified. + * @param v - A vector of three entries specifying the + * factor by which to scale in each dimension. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaled matrix. + */ + function scale(m, v, dst) { + const newDst = (dst ?? new Ctor(16)); + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + newDst[0] = v0 * m[0 * 4 + 0]; + newDst[1] = v0 * m[0 * 4 + 1]; + newDst[2] = v0 * m[0 * 4 + 2]; + newDst[3] = v0 * m[0 * 4 + 3]; + newDst[4] = v1 * m[1 * 4 + 0]; + newDst[5] = v1 * m[1 * 4 + 1]; + newDst[6] = v1 * m[1 * 4 + 2]; + newDst[7] = v1 * m[1 * 4 + 3]; + newDst[8] = v2 * m[2 * 4 + 0]; + newDst[9] = v2 * m[2 * 4 + 1]; + newDst[10] = v2 * m[2 * 4 + 2]; + newDst[11] = v2 * m[2 * 4 + 3]; + if (m !== newDst) { + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + } + return newDst; + } + /** + * Creates a 4-by-4 matrix which scales a uniform amount in each dimension. + * @param s - the amount to scale + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaling matrix. + */ + function uniformScaling(s, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = s; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + newDst[4] = 0; + newDst[5] = s; + newDst[6] = 0; + newDst[7] = 0; + newDst[8] = 0; + newDst[9] = 0; + newDst[10] = s; + newDst[11] = 0; + newDst[12] = 0; + newDst[13] = 0; + newDst[14] = 0; + newDst[15] = 1; + return newDst; + } + /** + * Scales the given 4-by-4 matrix in each dimension by a uniform scale. + * @param m - The matrix to be modified. + * @param s - The amount to scale. + * @param dst - matrix to hold result. If not passed a new one is created. + * @returns The scaled matrix. + */ + function uniformScale(m, s, dst) { + const newDst = (dst ?? new Ctor(16)); + newDst[0] = s * m[0 * 4 + 0]; + newDst[1] = s * m[0 * 4 + 1]; + newDst[2] = s * m[0 * 4 + 2]; + newDst[3] = s * m[0 * 4 + 3]; + newDst[4] = s * m[1 * 4 + 0]; + newDst[5] = s * m[1 * 4 + 1]; + newDst[6] = s * m[1 * 4 + 2]; + newDst[7] = s * m[1 * 4 + 3]; + newDst[8] = s * m[2 * 4 + 0]; + newDst[9] = s * m[2 * 4 + 1]; + newDst[10] = s * m[2 * 4 + 2]; + newDst[11] = s * m[2 * 4 + 3]; + if (m !== newDst) { + newDst[12] = m[12]; + newDst[13] = m[13]; + newDst[14] = m[14]; + newDst[15] = m[15]; + } + return newDst; + } + return { + create, + set, + fromMat3, + fromQuat, + negate, + copy, + clone, + equalsApproximately, + equals, + identity, + transpose, + inverse, + determinant, + invert, + multiply, + mul, + setTranslation, + getTranslation, + getAxis, + setAxis, + getScaling, + perspective, + perspectiveReverseZ, + ortho, + frustum, + frustumReverseZ, + aim, + cameraAim, + lookAt, + translation, + translate, + rotationX, + rotateX, + rotationY, + rotateY, + rotationZ, + rotateZ, + axisRotation, + rotation, + axisRotate, + rotate, + scaling, + scale, + uniformScaling, + uniformScale, + }; } -/** - * Rotate a 3D vector around the x-axis - * - * @param {ReadonlyVec3} a The vec3 point to rotate - * @param {ReadonlyVec3} b The origin of the rotation - * @param {Number} rad The angle of rotation in radians - * @param dst - The vector to set. If not passed a new one is created. - * @returns the rotated vector - */ -function rotateX$2(a, b, rad, dst) { - dst = dst || new VecType$1(3); - const p = []; - const r = []; - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - //perform rotation - r[0] = p[0]; - r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad); - r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); - //translate to correct position - dst[0] = r[0] + b[0]; - dst[1] = r[1] + b[1]; - dst[2] = r[2] + b[2]; - return dst; +const cache$2 = new Map(); +function getAPI$2(Ctor) { + let api = cache$2.get(Ctor); + if (!api) { + api = getAPIImpl$2(Ctor); + cache$2.set(Ctor, api); + } + return api; } -/** - * Rotate a 3D vector around the y-axis + +/* + * Copyright 2022 Gregg Tavares * - * @param {ReadonlyVec3} a The vec3 point to rotate - * @param {ReadonlyVec3} b The origin of the rotation - * @param {Number} rad The angle of rotation in radians - * @param dst - The vector to set. If not passed a new one is created. - * @returns the rotated vector - */ -function rotateY$2(a, b, rad, dst) { - dst = dst || new VecType$1(3); - const p = []; - const r = []; - // translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - // perform rotation - r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad); - r[1] = p[1]; - r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); - // translate to correct position - dst[0] = r[0] + b[0]; - dst[1] = r[1] + b[1]; - dst[2] = r[2] + b[2]; - return dst; -} -/** - * Rotate a 3D vector around the z-axis + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * @param {ReadonlyVec3} a The vec3 point to rotate - * @param {ReadonlyVec3} b The origin of the rotation - * @param {Number} rad The angle of rotation in radians - * @param dst - The vector to set. If not passed a new one is created. - * @returns {vec3} out - */ -function rotateZ$2(a, b, rad, dst) { - dst = dst || new VecType$1(3); - const p = []; - const r = []; - // translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - // perform rotation - r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad); - r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad); - r[2] = p[2]; - // translate to correct position - dst[0] = r[0] + b[0]; - dst[1] = r[1] + b[1]; - dst[2] = r[2] + b[2]; - return dst; -} -/** - * Treat a 3D vector as a direction and set it's length + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * @param a The vec3 to lengthen - * @param len The length of the resulting vector - * @returns The lengthened vector + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -function setLength$1(a, len, dst) { - dst = dst || new VecType$1(3); - normalize$2(a, dst); - return mulScalar$2(dst, len, dst); -} /** - * Ensure a vector is not longer than a max length - * - * @param a The vec3 to limit - * @param maxLen The longest length of the resulting vector - * @returns The vector, shortened to maxLen if it's too long - */ -function truncate$1(a, maxLen, dst) { - dst = dst || new VecType$1(3); - if (length$2(a) > maxLen) { - return setLength$1(a, maxLen, dst); + * Generates am typed API for Qud + * */ +function getAPIImpl$1(Ctor) { + const vec3 = getAPI$3(Ctor); + /** + * Creates a quat4; may be called with x, y, z to set initial values. + * @param x - Initial x value. + * @param y - Initial y value. + * @param z - Initial z value. + * @param w - Initial w value. + * @returns the created vector + */ + function create(x, y, z, w) { + const newDst = new Ctor(4); + if (x !== undefined) { + newDst[0] = x; + if (y !== undefined) { + newDst[1] = y; + if (z !== undefined) { + newDst[2] = z; + if (w !== undefined) { + newDst[3] = w; + } + } + } + } + return newDst; + } + /** + * Creates a Quat; may be called with x, y, z to set initial values. (same as create) + * @param x - Initial x value. + * @param y - Initial y value. + * @param z - Initial z value. + * @param z - Initial w value. + * @returns the created vector + */ + const fromValues = create; + /** + * Sets the values of a Quat + * Also see {@link quat.create} and {@link quat.copy} + * + * @param x first value + * @param y second value + * @param z third value + * @param w fourth value + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector with its elements set. + */ + function set(x, y, z, w, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = x; + newDst[1] = y; + newDst[2] = z; + newDst[3] = w; + return newDst; + } + /** + * Sets a quaternion from the given angle and axis, + * then returns it. + * + * @param axis - the axis to rotate around + * @param angleInRadians - the angle + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The quaternion that represents the given axis and angle + **/ + function fromAxisAngle(axis, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(4)); + const halfAngle = angleInRadians * 0.5; + const s = Math.sin(halfAngle); + newDst[0] = s * axis[0]; + newDst[1] = s * axis[1]; + newDst[2] = s * axis[2]; + newDst[3] = Math.cos(halfAngle); + return newDst; + } + /** + * Gets the rotation axis and angle + * @param q - quaternion to compute from + * @param dst - Vec3 to hold result. If not passed in a new one is created. + * @return angle and axis + */ + function toAxisAngle(q, dst) { + const newDst = (dst ?? vec3.create(3)); + const angle = Math.acos(q[3]) * 2; + const s = Math.sin(angle * 0.5); + if (s > EPSILON) { + newDst[0] = q[0] / s; + newDst[1] = q[1] / s; + newDst[2] = q[2] / s; + } + else { + newDst[0] = 1; + newDst[1] = 0; + newDst[2] = 0; + } + return { angle, axis: newDst }; + } + /** + * Returns the angle in degrees between two rotations a and b. + * @param a - quaternion a + * @param b - quaternion b + * @return angle in radians between the two quaternions + */ + function angle(a, b) { + const d = dot(a, b); + return Math.acos(2 * d * d - 1); + } + /** + * Multiplies two quaternions + * + * @param a - the first quaternion + * @param b - the second quaternion + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the result of a * b + */ + function multiply(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + const ax = a[0]; + const ay = a[1]; + const az = a[2]; + const aw = a[3]; + const bx = b[0]; + const by = b[1]; + const bz = b[2]; + const bw = b[3]; + newDst[0] = ax * bw + aw * bx + ay * bz - az * by; + newDst[1] = ay * bw + aw * by + az * bx - ax * bz; + newDst[2] = az * bw + aw * bz + ax * by - ay * bx; + newDst[3] = aw * bw - ax * bx - ay * by - az * bz; + return newDst; + } + /** + * Multiplies two quaternions + * + * @param a - the first quaternion + * @param b - the second quaternion + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the result of a * b + */ + const mul = multiply; + /** + * Rotates the given quaternion around the X axis by the given angle. + * @param q - quaternion to rotate + * @param angleInRadians - The angle by which to rotate + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the result of a * b + */ + function rotateX(q, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(4)); + const halfAngle = angleInRadians * 0.5; + const qx = q[0]; + const qy = q[1]; + const qz = q[2]; + const qw = q[3]; + const bx = Math.sin(halfAngle); + const bw = Math.cos(halfAngle); + newDst[0] = qx * bw + qw * bx; + newDst[1] = qy * bw + qz * bx; + newDst[2] = qz * bw - qy * bx; + newDst[3] = qw * bw - qx * bx; + return newDst; + } + /** + * Rotates the given quaternion around the Y axis by the given angle. + * @param q - quaternion to rotate + * @param angleInRadians - The angle by which to rotate + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the result of a * b + */ + function rotateY(q, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(4)); + const halfAngle = angleInRadians * 0.5; + const qx = q[0]; + const qy = q[1]; + const qz = q[2]; + const qw = q[3]; + const by = Math.sin(halfAngle); + const bw = Math.cos(halfAngle); + newDst[0] = qx * bw - qz * by; + newDst[1] = qy * bw + qw * by; + newDst[2] = qz * bw + qx * by; + newDst[3] = qw * bw - qy * by; + return newDst; + } + /** + * Rotates the given quaternion around the Z axis by the given angle. + * @param q - quaternion to rotate + * @param angleInRadians - The angle by which to rotate + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the result of a * b + */ + function rotateZ(q, angleInRadians, dst) { + const newDst = (dst ?? new Ctor(4)); + const halfAngle = angleInRadians * 0.5; + const qx = q[0]; + const qy = q[1]; + const qz = q[2]; + const qw = q[3]; + const bz = Math.sin(halfAngle); + const bw = Math.cos(halfAngle); + newDst[0] = qx * bw + qy * bz; + newDst[1] = qy * bw - qx * bz; + newDst[2] = qz * bw + qw * bz; + newDst[3] = qw * bw - qz * bz; + return newDst; + } + /** + * Spherically linear interpolate between two quaternions + * + * @param a - starting value + * @param b - ending value + * @param t - value where 0 = a and 1 = b + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the result of a * b + */ + function slerp(a, b, t, dst) { + const newDst = (dst ?? new Ctor(4)); + const ax = a[0]; + const ay = a[1]; + const az = a[2]; + const aw = a[3]; + let bx = b[0]; + let by = b[1]; + let bz = b[2]; + let bw = b[3]; + let cosOmega = ax * bx + ay * by + az * bz + aw * bw; + if (cosOmega < 0) { + cosOmega = -cosOmega; + bx = -bx; + by = -by; + bz = -bz; + bw = -bw; + } + let scale0; + let scale1; + if (1.0 - cosOmega > EPSILON) { + const omega = Math.acos(cosOmega); + const sinOmega = Math.sin(omega); + scale0 = Math.sin((1 - t) * omega) / sinOmega; + scale1 = Math.sin(t * omega) / sinOmega; + } + else { + scale0 = 1.0 - t; + scale1 = t; + } + newDst[0] = scale0 * ax + scale1 * bx; + newDst[1] = scale0 * ay + scale1 * by; + newDst[2] = scale0 * az + scale1 * bz; + newDst[3] = scale0 * aw + scale1 * bw; + return newDst; + } + /** + * Compute the inverse of a quaternion + * + * @param q - quaternion to compute the inverse of + * @returns A quaternion that is the result of a * b + */ + function inverse(q, dst) { + const newDst = (dst ?? new Ctor(4)); + const a0 = q[0]; + const a1 = q[1]; + const a2 = q[2]; + const a3 = q[3]; + const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3; + const invDot = dot ? 1 / dot : 0; + newDst[0] = -a0 * invDot; + newDst[1] = -a1 * invDot; + newDst[2] = -a2 * invDot; + newDst[3] = a3 * invDot; + return newDst; + } + /** + * Compute the conjugate of a quaternion + * For quaternions with a magnitude of 1 (a unit quaternion) + * this returns the same as the inverse but is faster to calculate. + * + * @param q - quaternion to compute the conjugate of. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The conjugate of q + */ + function conjugate(q, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = -q[0]; + newDst[1] = -q[1]; + newDst[2] = -q[2]; + newDst[3] = q[3]; + return newDst; + } + /** + * Creates a quaternion from the given rotation matrix. + * + * The created quaternion is not normalized. + * + * @param m - rotation matrix + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns the result + */ + function fromMat(m, dst) { + const newDst = (dst ?? new Ctor(4)); + /* + 0 1 2 + 3 4 5 + 6 7 8 + + 0 1 2 + 4 5 6 + 8 9 10 + */ + // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes + // article "Quaternion Calculus and Fast Animation". + const trace = m[0] + m[5] + m[10]; + if (trace > 0.0) { + // |w| > 1/2, may as well choose w > 1/2 + const root = Math.sqrt(trace + 1); // 2w + newDst[3] = 0.5 * root; + const invRoot = 0.5 / root; // 1/(4w) + newDst[0] = (m[6] - m[9]) * invRoot; + newDst[1] = (m[8] - m[2]) * invRoot; + newDst[2] = (m[1] - m[4]) * invRoot; + } + else { + // |w| <= 1/2 + let i = 0; + if (m[5] > m[0]) { + i = 1; + } + if (m[10] > m[i * 4 + i]) { + i = 2; + } + const j = (i + 1) % 3; + const k = (i + 2) % 3; + const root = Math.sqrt(m[i * 4 + i] - m[j * 4 + j] - m[k * 4 + k] + 1.0); + newDst[i] = 0.5 * root; + const invRoot = 0.5 / root; + newDst[3] = (m[j * 4 + k] - m[k * 4 + j]) * invRoot; + newDst[j] = (m[j * 4 + i] + m[i * 4 + j]) * invRoot; + newDst[k] = (m[k * 4 + i] + m[i * 4 + k]) * invRoot; + } + return newDst; + } + /** + * Creates a quaternion from the given euler angle x, y, z using the provided intrinsic order for the conversion. + * + * @param xAngleInRadians - angle to rotate around X axis in radians. + * @param yAngleInRadians - angle to rotate around Y axis in radians. + * @param zAngleInRadians - angle to rotate around Z axis in radians. + * @param order - order to apply euler angles + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion representing the same rotation as the euler angles applied in the given order + */ + function fromEuler(xAngleInRadians, yAngleInRadians, zAngleInRadians, order, dst) { + const newDst = (dst ?? new Ctor(4)); + const xHalfAngle = xAngleInRadians * 0.5; + const yHalfAngle = yAngleInRadians * 0.5; + const zHalfAngle = zAngleInRadians * 0.5; + const sx = Math.sin(xHalfAngle); + const cx = Math.cos(xHalfAngle); + const sy = Math.sin(yHalfAngle); + const cy = Math.cos(yHalfAngle); + const sz = Math.sin(zHalfAngle); + const cz = Math.cos(zHalfAngle); + switch (order) { + case 'xyz': + newDst[0] = sx * cy * cz + cx * sy * sz; + newDst[1] = cx * sy * cz - sx * cy * sz; + newDst[2] = cx * cy * sz + sx * sy * cz; + newDst[3] = cx * cy * cz - sx * sy * sz; + break; + case 'xzy': + newDst[0] = sx * cy * cz - cx * sy * sz; + newDst[1] = cx * sy * cz - sx * cy * sz; + newDst[2] = cx * cy * sz + sx * sy * cz; + newDst[3] = cx * cy * cz + sx * sy * sz; + break; + case 'yxz': + newDst[0] = sx * cy * cz + cx * sy * sz; + newDst[1] = cx * sy * cz - sx * cy * sz; + newDst[2] = cx * cy * sz - sx * sy * cz; + newDst[3] = cx * cy * cz + sx * sy * sz; + break; + case 'yzx': + newDst[0] = sx * cy * cz + cx * sy * sz; + newDst[1] = cx * sy * cz + sx * cy * sz; + newDst[2] = cx * cy * sz - sx * sy * cz; + newDst[3] = cx * cy * cz - sx * sy * sz; + break; + case 'zxy': + newDst[0] = sx * cy * cz - cx * sy * sz; + newDst[1] = cx * sy * cz + sx * cy * sz; + newDst[2] = cx * cy * sz + sx * sy * cz; + newDst[3] = cx * cy * cz - sx * sy * sz; + break; + case 'zyx': + newDst[0] = sx * cy * cz - cx * sy * sz; + newDst[1] = cx * sy * cz + sx * cy * sz; + newDst[2] = cx * cy * sz - sx * sy * cz; + newDst[3] = cx * cy * cz + sx * sy * sz; + break; + default: + throw new Error(`Unknown rotation order: ${order}`); + } + return newDst; + } + /** + * Copies a quaternion. (same as {@link quat.clone}) + * Also see {@link quat.create} and {@link quat.set} + * @param q - The quaternion. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is a copy of q + */ + function copy(q, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = q[0]; + newDst[1] = q[1]; + newDst[2] = q[2]; + newDst[3] = q[3]; + return newDst; + } + /** + * Clones a quaternion. (same as {@link quat.copy}) + * Also see {@link quat.create} and {@link quat.set} + * @param q - The quaternion. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A copy of q. + */ + const clone = copy; + /** + * Adds two quaternions; assumes a and b have the same dimension. + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the sum of a and b. + */ + function add(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] + b[0]; + newDst[1] = a[1] + b[1]; + newDst[2] = a[2] + b[2]; + newDst[3] = a[3] + b[3]; + return newDst; + } + /** + * Subtracts two quaternions. + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the difference of a and b. + */ + function subtract(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] - b[0]; + newDst[1] = a[1] - b[1]; + newDst[2] = a[2] - b[2]; + newDst[3] = a[3] - b[3]; + return newDst; + } + /** + * Subtracts two quaternions. + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns A quaternion that is the difference of a and b. + */ + const sub = subtract; + /** + * Multiplies a quaternion by a scalar. + * @param v - The quaternion. + * @param k - The scalar. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The scaled quaternion. + */ + function mulScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = v[0] * k; + newDst[1] = v[1] * k; + newDst[2] = v[2] * k; + newDst[3] = v[3] * k; + return newDst; + } + /** + * Multiplies a quaternion by a scalar. (same as mulScalar) + * @param v - The quaternion. + * @param k - The scalar. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The scaled quaternion. + */ + const scale = mulScalar; + /** + * Divides a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The scaled quaternion. + */ + function divScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = v[0] / k; + newDst[1] = v[1] / k; + newDst[2] = v[2] / k; + newDst[3] = v[3] / k; + return newDst; + } + /** + * Computes the dot product of two quaternions + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @returns dot product + */ + function dot(a, b) { + return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]); + } + /** + * Performs linear interpolation on two quaternions. + * Given quaternions a and b and interpolation coefficient t, returns + * a + t * (b - a). + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @param t - Interpolation coefficient. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The linear interpolated result. + */ + function lerp(a, b, t, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] + t * (b[0] - a[0]); + newDst[1] = a[1] + t * (b[1] - a[1]); + newDst[2] = a[2] + t * (b[2] - a[2]); + newDst[3] = a[3] + t * (b[3] - a[3]); + return newDst; + } + /** + * Computes the length of quaternion + * @param v - quaternion. + * @returns length of quaternion. + */ + function length(v) { + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const v3 = v[3]; + return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3); + } + /** + * Computes the length of quaternion (same as length) + * @param v - quaternion. + * @returns length of quaternion. + */ + const len = length; + /** + * Computes the square of the length of quaternion + * @param v - quaternion. + * @returns square of the length of quaternion. + */ + function lengthSq(v) { + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const v3 = v[3]; + return v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3; + } + /** + * Computes the square of the length of quaternion (same as lengthSq) + * @param v - quaternion. + * @returns square of the length of quaternion. + */ + const lenSq = lengthSq; + /** + * Divides a quaternion by its Euclidean length and returns the quotient. + * @param v - The quaternion. + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns The normalized quaternion. + */ + function normalize(v, dst) { + const newDst = (dst ?? new Ctor(4)); + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const v3 = v[3]; + const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3); + if (len > 0.00001) { + newDst[0] = v0 / len; + newDst[1] = v1 / len; + newDst[2] = v2 / len; + newDst[3] = v3 / len; + } + else { + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + } + return newDst; + } + /** + * Check if 2 quaternions are approximately equal + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @returns true if quaternions are approximately equal + */ + function equalsApproximately(a, b) { + return Math.abs(a[0] - b[0]) < EPSILON && + Math.abs(a[1] - b[1]) < EPSILON && + Math.abs(a[2] - b[2]) < EPSILON && + Math.abs(a[3] - b[3]) < EPSILON; + } + /** + * Check if 2 quaternions are exactly equal + * @param a - Operand quaternion. + * @param b - Operand quaternion. + * @returns true if quaternions are exactly equal + */ + function equals(a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3]; + } + /** + * Creates an identity quaternion + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns an identity quaternion + */ + function identity(dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 1; + return newDst; + } + const tempVec3 = vec3.create(); + const xUnitVec3 = vec3.create(); + const yUnitVec3 = vec3.create(); + /** + * Computes a quaternion to represent the shortest rotation from one vector to another. + * + * @param aUnit - the start vector + * @param bUnit - the end vector + * @param dst - quaternion to hold result. If not passed in a new one is created. + * @returns the result + */ + function rotationTo(aUnit, bUnit, dst) { + const newDst = (dst ?? new Ctor(4)); + const dot = vec3.dot(aUnit, bUnit); + if (dot < -0.999999) { + vec3.cross(xUnitVec3, aUnit, tempVec3); + if (vec3.len(tempVec3) < 0.000001) { + vec3.cross(yUnitVec3, aUnit, tempVec3); + } + vec3.normalize(tempVec3, tempVec3); + fromAxisAngle(tempVec3, Math.PI, newDst); + return newDst; + } + else if (dot > 0.999999) { + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 1; + return newDst; + } + else { + vec3.cross(aUnit, bUnit, tempVec3); + newDst[0] = tempVec3[0]; + newDst[1] = tempVec3[1]; + newDst[2] = tempVec3[2]; + newDst[3] = 1 + dot; + return normalize(newDst, newDst); + } } - return copy$3(a, dst); + const tempQuat1 = new Ctor(4); + const tempQuat2 = new Ctor(4); + /** + * Performs a spherical linear interpolation with two control points + * + * @param a - the first quaternion + * @param b - the second quaternion + * @param c - the third quaternion + * @param d - the fourth quaternion + * @param t - Interpolation coefficient 0 to 1 + * @returns result + */ + function sqlerp(a, b, c, d, t, dst) { + const newDst = (dst ?? new Ctor(4)); + slerp(a, d, t, tempQuat1); + slerp(b, c, t, tempQuat2); + slerp(tempQuat1, tempQuat2, 2 * t * (1 - t), newDst); + return newDst; + } + return { + create, + fromValues, + set, + fromAxisAngle, + toAxisAngle, + angle, + multiply, + mul, + rotateX, + rotateY, + rotateZ, + slerp, + inverse, + conjugate, + fromMat, + fromEuler, + copy, + clone, + add, + subtract, + sub, + mulScalar, + scale, + divScalar, + dot, + lerp, + length, + len, + lengthSq, + lenSq, + normalize, + equalsApproximately, + equals, + identity, + rotationTo, + sqlerp, + }; } +const cache$1 = new Map(); /** - * Return the vector exactly between 2 endpoint vectors * - * @param a Endpoint 1 - * @param b Endpoint 2 - * @returns The vector exactly residing between endpoints 1 and 2 - */ -function midpoint$1(a, b, dst) { - dst = dst || new VecType$1(3); - return lerp$2(a, b, 0.5, dst); -} - -var vec3Impl = /*#__PURE__*/Object.freeze({ - __proto__: null, - add: add$2, - addScaled: addScaled$1, - angle: angle$1, - ceil: ceil$1, - clamp: clamp$1, - clone: clone$3, - copy: copy$3, - create: create$4, - cross: cross, - dist: dist$1, - distSq: distSq$1, - distance: distance$1, - distanceSq: distanceSq$1, - div: div$1, - divScalar: divScalar$2, - divide: divide$1, - dot: dot$2, - equals: equals$3, - equalsApproximately: equalsApproximately$3, - floor: floor$1, - fromValues: fromValues$2, - getAxis: getAxis$1, - getScaling: getScaling$1, - getTranslation: getTranslation$1, - inverse: inverse$3, - invert: invert$2, - len: len$2, - lenSq: lenSq$2, - length: length$2, - lengthSq: lengthSq$2, - lerp: lerp$2, - lerpV: lerpV$1, - max: max$1, - midpoint: midpoint$1, - min: min$1, - mul: mul$3, - mulScalar: mulScalar$2, - multiply: multiply$3, - negate: negate$2, - normalize: normalize$2, - random: random, - rotateX: rotateX$2, - rotateY: rotateY$2, - rotateZ: rotateZ$2, - round: round$1, - scale: scale$3, - set: set$3, - setDefaultType: setDefaultType$5, - setLength: setLength$1, - sub: sub$2, - subtract: subtract$2, - transformMat3: transformMat3, - transformMat4: transformMat4$1, - transformMat4Upper3x3: transformMat4Upper3x3, - transformQuat: transformQuat, - truncate: truncate$1, - zero: zero$1 -}); - -/** - * 4x4 Matrix math math functions. + * Quat4 math functions. * - * Almost all functions take an optional `dst` argument. If it is not passed in the - * functions will create a new matrix. In other words you can do this + * Almost all functions take an optional `newDst` argument. If it is not passed in the + * functions will create a new `Quat4`. In other words you can do this * - * const mat = mat4.translation([1, 2, 3]); // Creates a new translation matrix + * const v = quat4.cross(v1, v2); // Creates a new Quat4 with the cross product of v1 x v2. * * or * - * const mat = mat4.create(); - * mat4.translation([1, 2, 3], mat); // Puts translation matrix in mat. + * const v = quat4.create(); + * quat4.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v * * The first style is often easier but depending on where it's used it generates garbage where * as there is almost never allocation with the second style. * - * It is always save to pass any matrix as the destination. So for example + * It is always safe to pass any vector as the destination. So for example * - * const mat = mat4.identity(); - * const trans = mat4.translation([1, 2, 3]); - * mat4.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat. + * quat4.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1 * */ -let MatType = Float32Array; -/** - * Sets the type this library creates for a Mat4 - * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array` - * @returns previous constructor for Mat4 - */ -function setDefaultType$3(ctor) { - const oldType = MatType; - MatType = ctor; - return oldType; +function getAPI$1(Ctor) { + let api = cache$1.get(Ctor); + if (!api) { + api = getAPIImpl$1(Ctor); + cache$1.set(Ctor, api); + } + return api; } -/** - * Create a Mat4 from values - * - * Note: Since passing in a raw JavaScript array - * is valid in all circumstances, if you want to - * force a JavaScript array into a Mat4's specified type - * it would be faster to use - * - * ``` - * const m = mat4.clone(someJSArray); - * ``` + +/* + * Copyright 2022 Gregg Tavares * - * Note: a consequence of the implementation is if your Mat4Type = `Array` - * instead of `Float32Array` or `Float64Array` then any values you - * don't pass in will be undefined. Usually this is not an issue since - * (a) using `Array` is rare and (b) using `mat4.create` is usually used - * to create a Mat4 to be filled out as in + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * ``` - * const m = mat4.create(); - * mat4.perspective(fov, aspect, near, far, m); - * ``` + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * @param v0 - value for element 0 - * @param v1 - value for element 1 - * @param v2 - value for element 2 - * @param v3 - value for element 3 - * @param v4 - value for element 4 - * @param v5 - value for element 5 - * @param v6 - value for element 6 - * @param v7 - value for element 7 - * @param v8 - value for element 8 - * @param v9 - value for element 9 - * @param v10 - value for element 10 - * @param v11 - value for element 11 - * @param v12 - value for element 12 - * @param v13 - value for element 13 - * @param v14 - value for element 14 - * @param v15 - value for element 15 - * @returns created from values. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -function create$2(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) { - const dst = new MatType(16); - if (v0 !== undefined) { - dst[0] = v0; - if (v1 !== undefined) { - dst[1] = v1; - if (v2 !== undefined) { - dst[2] = v2; - if (v3 !== undefined) { - dst[3] = v3; - if (v4 !== undefined) { - dst[4] = v4; - if (v5 !== undefined) { - dst[5] = v5; - if (v6 !== undefined) { - dst[6] = v6; - if (v7 !== undefined) { - dst[7] = v7; - if (v8 !== undefined) { - dst[8] = v8; - if (v9 !== undefined) { - dst[9] = v9; - if (v10 !== undefined) { - dst[10] = v10; - if (v11 !== undefined) { - dst[11] = v11; - if (v12 !== undefined) { - dst[12] = v12; - if (v13 !== undefined) { - dst[13] = v13; - if (v14 !== undefined) { - dst[14] = v14; - if (v15 !== undefined) { - dst[15] = v15; - } - } - } - } - } - } - } - } - } - } - } +/** + * Generates am typed API for Vec4 + * */ +function getAPIImpl(Ctor) { + /** + * Creates a vec4; may be called with x, y, z to set initial values. + * @param x - Initial x value. + * @param y - Initial y value. + * @param z - Initial z value. + * @param w - Initial w value. + * @returns the created vector + */ + function create(x, y, z, w) { + const newDst = new Ctor(4); + if (x !== undefined) { + newDst[0] = x; + if (y !== undefined) { + newDst[1] = y; + if (z !== undefined) { + newDst[2] = z; + if (w !== undefined) { + newDst[3] = w; } } } } + return newDst; + } + /** + * Creates a vec4; may be called with x, y, z to set initial values. (same as create) + * @param x - Initial x value. + * @param y - Initial y value. + * @param z - Initial z value. + * @param z - Initial w value. + * @returns the created vector + */ + const fromValues = create; + /** + * Sets the values of a Vec4 + * Also see {@link vec4.create} and {@link vec4.copy} + * + * @param x first value + * @param y second value + * @param z third value + * @param w fourth value + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector with its elements set. + */ + function set(x, y, z, w, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = x; + newDst[1] = y; + newDst[2] = z; + newDst[3] = w; + return newDst; + } + /** + * Applies Math.ceil to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the ceil of each element of v. + */ + function ceil(v, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = Math.ceil(v[0]); + newDst[1] = Math.ceil(v[1]); + newDst[2] = Math.ceil(v[2]); + newDst[3] = Math.ceil(v[3]); + return newDst; + } + /** + * Applies Math.floor to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the floor of each element of v. + */ + function floor(v, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = Math.floor(v[0]); + newDst[1] = Math.floor(v[1]); + newDst[2] = Math.floor(v[2]); + newDst[3] = Math.floor(v[3]); + return newDst; + } + /** + * Applies Math.round to each element of vector + * @param v - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the round of each element of v. + */ + function round(v, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = Math.round(v[0]); + newDst[1] = Math.round(v[1]); + newDst[2] = Math.round(v[2]); + newDst[3] = Math.round(v[3]); + return newDst; + } + /** + * Clamp each element of vector between min and max + * @param v - Operand vector. + * @param max - Min value, default 0 + * @param min - Max value, default 1 + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that the clamped value of each element of v. + */ + function clamp(v, min = 0, max = 1, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = Math.min(max, Math.max(min, v[0])); + newDst[1] = Math.min(max, Math.max(min, v[1])); + newDst[2] = Math.min(max, Math.max(min, v[2])); + newDst[3] = Math.min(max, Math.max(min, v[3])); + return newDst; + } + /** + * Adds two vectors; assumes a and b have the same dimension. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the sum of a and b. + */ + function add(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] + b[0]; + newDst[1] = a[1] + b[1]; + newDst[2] = a[2] + b[2]; + newDst[3] = a[3] + b[3]; + return newDst; + } + /** + * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension. + * @param a - Operand vector. + * @param b - Operand vector. + * @param scale - Amount to scale b + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the sum of a + b * scale. + */ + function addScaled(a, b, scale, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] + b[0] * scale; + newDst[1] = a[1] + b[1] * scale; + newDst[2] = a[2] + b[2] * scale; + newDst[3] = a[3] + b[3] * scale; + return newDst; + } + /** + * Subtracts two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the difference of a and b. + */ + function subtract(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] - b[0]; + newDst[1] = a[1] - b[1]; + newDst[2] = a[2] - b[2]; + newDst[3] = a[3] - b[3]; + return newDst; + } + /** + * Subtracts two vectors. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A vector that is the difference of a and b. + */ + const sub = subtract; + /** + * Check if 2 vectors are approximately equal + * @param a - Operand vector. + * @param b - Operand vector. + * @returns true if vectors are approximately equal + */ + function equalsApproximately(a, b) { + return Math.abs(a[0] - b[0]) < EPSILON && + Math.abs(a[1] - b[1]) < EPSILON && + Math.abs(a[2] - b[2]) < EPSILON && + Math.abs(a[3] - b[3]) < EPSILON; + } + /** + * Check if 2 vectors are exactly equal + * @param a - Operand vector. + * @param b - Operand vector. + * @returns true if vectors are exactly equal + */ + function equals(a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3]; + } + /** + * Performs linear interpolation on two vectors. + * Given vectors a and b and interpolation coefficient t, returns + * a + t * (b - a). + * @param a - Operand vector. + * @param b - Operand vector. + * @param t - Interpolation coefficient. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The linear interpolated result. + */ + function lerp(a, b, t, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] + t * (b[0] - a[0]); + newDst[1] = a[1] + t * (b[1] - a[1]); + newDst[2] = a[2] + t * (b[2] - a[2]); + newDst[3] = a[3] + t * (b[3] - a[3]); + return newDst; + } + /** + * Performs linear interpolation on two vectors. + * Given vectors a and b and interpolation coefficient vector t, returns + * a + t * (b - a). + * @param a - Operand vector. + * @param b - Operand vector. + * @param t - Interpolation coefficients vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns the linear interpolated result. + */ + function lerpV(a, b, t, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] + t[0] * (b[0] - a[0]); + newDst[1] = a[1] + t[1] * (b[1] - a[1]); + newDst[2] = a[2] + t[2] * (b[2] - a[2]); + newDst[3] = a[3] + t[3] * (b[3] - a[3]); + return newDst; + } + /** + * Return max values of two vectors. + * Given vectors a and b returns + * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])]. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The max components vector. + */ + function max(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = Math.max(a[0], b[0]); + newDst[1] = Math.max(a[1], b[1]); + newDst[2] = Math.max(a[2], b[2]); + newDst[3] = Math.max(a[3], b[3]); + return newDst; + } + /** + * Return min values of two vectors. + * Given vectors a and b returns + * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])]. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The min components vector. + */ + function min(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = Math.min(a[0], b[0]); + newDst[1] = Math.min(a[1], b[1]); + newDst[2] = Math.min(a[2], b[2]); + newDst[3] = Math.min(a[3], b[3]); + return newDst; + } + /** + * Multiplies a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + function mulScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = v[0] * k; + newDst[1] = v[1] * k; + newDst[2] = v[2] * k; + newDst[3] = v[3] * k; + return newDst; + } + /** + * Multiplies a vector by a scalar. (same as mulScalar) + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + const scale = mulScalar; + /** + * Divides a vector by a scalar. + * @param v - The vector. + * @param k - The scalar. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The scaled vector. + */ + function divScalar(v, k, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = v[0] / k; + newDst[1] = v[1] / k; + newDst[2] = v[2] / k; + newDst[3] = v[3] / k; + return newDst; + } + /** + * Inverse a vector. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The inverted vector. + */ + function inverse(v, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = 1 / v[0]; + newDst[1] = 1 / v[1]; + newDst[2] = 1 / v[2]; + newDst[3] = 1 / v[3]; + return newDst; + } + /** + * Invert a vector. (same as inverse) + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The inverted vector. + */ + const invert = inverse; + /** + * Computes the dot product of two vectors + * @param a - Operand vector. + * @param b - Operand vector. + * @returns dot product + */ + function dot(a, b) { + return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]); + } + /** + * Computes the length of vector + * @param v - vector. + * @returns length of vector. + */ + function length(v) { + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const v3 = v[3]; + return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3); + } + /** + * Computes the length of vector (same as length) + * @param v - vector. + * @returns length of vector. + */ + const len = length; + /** + * Computes the square of the length of vector + * @param v - vector. + * @returns square of the length of vector. + */ + function lengthSq(v) { + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const v3 = v[3]; + return v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3; + } + /** + * Computes the square of the length of vector (same as lengthSq) + * @param v - vector. + * @returns square of the length of vector. + */ + const lenSq = lengthSq; + /** + * Computes the distance between 2 points + * @param a - vector. + * @param b - vector. + * @returns distance between a and b + */ + function distance(a, b) { + const dx = a[0] - b[0]; + const dy = a[1] - b[1]; + const dz = a[2] - b[2]; + const dw = a[3] - b[3]; + return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw); + } + /** + * Computes the distance between 2 points (same as distance) + * @param a - vector. + * @param b - vector. + * @returns distance between a and b + */ + const dist = distance; + /** + * Computes the square of the distance between 2 points + * @param a - vector. + * @param b - vector. + * @returns square of the distance between a and b + */ + function distanceSq(a, b) { + const dx = a[0] - b[0]; + const dy = a[1] - b[1]; + const dz = a[2] - b[2]; + const dw = a[3] - b[3]; + return dx * dx + dy * dy + dz * dz + dw * dw; + } + /** + * Computes the square of the distance between 2 points (same as distanceSq) + * @param a - vector. + * @param b - vector. + * @returns square of the distance between a and b + */ + const distSq = distanceSq; + /** + * Divides a vector by its Euclidean length and returns the quotient. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The normalized vector. + */ + function normalize(v, dst) { + const newDst = (dst ?? new Ctor(4)); + const v0 = v[0]; + const v1 = v[1]; + const v2 = v[2]; + const v3 = v[3]; + const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3); + if (len > 0.00001) { + newDst[0] = v0 / len; + newDst[1] = v1 / len; + newDst[2] = v2 / len; + newDst[3] = v3 / len; + } + else { + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + } + return newDst; + } + /** + * Negates a vector. + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns -v. + */ + function negate(v, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = -v[0]; + newDst[1] = -v[1]; + newDst[2] = -v[2]; + newDst[3] = -v[3]; + return newDst; + } + /** + * Copies a vector. (same as {@link vec4.clone}) + * Also see {@link vec4.create} and {@link vec4.set} + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A copy of v. + */ + function copy(v, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = v[0]; + newDst[1] = v[1]; + newDst[2] = v[2]; + newDst[3] = v[3]; + return newDst; + } + /** + * Clones a vector. (same as {@link vec4.copy}) + * Also see {@link vec4.create} and {@link vec4.set} + * @param v - The vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns A copy of v. + */ + const clone = copy; + /** + * Multiplies a vector by another vector (component-wise); assumes a and + * b have the same length. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of products of entries of a and b. + */ + function multiply(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] * b[0]; + newDst[1] = a[1] * b[1]; + newDst[2] = a[2] * b[2]; + newDst[3] = a[3] * b[3]; + return newDst; + } + /** + * Multiplies a vector by another vector (component-wise); assumes a and + * b have the same length. (same as mul) + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of products of entries of a and b. + */ + const mul = multiply; + /** + * Divides a vector by another vector (component-wise); assumes a and + * b have the same length. + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of quotients of entries of a and b. + */ + function divide(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = a[0] / b[0]; + newDst[1] = a[1] / b[1]; + newDst[2] = a[2] / b[2]; + newDst[3] = a[3] / b[3]; + return newDst; + } + /** + * Divides a vector by another vector (component-wise); assumes a and + * b have the same length. (same as divide) + * @param a - Operand vector. + * @param b - Operand vector. + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The vector of quotients of entries of a and b. + */ + const div = divide; + /** + * Zero's a vector + * @param dst - vector to hold result. If not passed in a new one is created. + * @returns The zeroed vector. + */ + function zero(dst) { + const newDst = (dst ?? new Ctor(4)); + newDst[0] = 0; + newDst[1] = 0; + newDst[2] = 0; + newDst[3] = 0; + return newDst; + } + /** + * transform vec4 by 4x4 matrix + * @param v - the vector + * @param m - The matrix. + * @param dst - optional vec4 to store result. If not passed a new one is created. + * @returns the transformed vector + */ + function transformMat4(v, m, dst) { + const newDst = (dst ?? new Ctor(4)); + const x = v[0]; + const y = v[1]; + const z = v[2]; + const w = v[3]; + newDst[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; + newDst[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; + newDst[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; + newDst[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; + return newDst; + } + /** + * Treat a 4D vector as a direction and set it's length + * + * @param a The vec4 to lengthen + * @param len The length of the resulting vector + * @returns The lengthened vector + */ + function setLength(a, len, dst) { + const newDst = (dst ?? new Ctor(4)); + normalize(a, newDst); + return mulScalar(newDst, len, newDst); + } + /** + * Ensure a vector is not longer than a max length + * + * @param a The vec4 to limit + * @param maxLen The longest length of the resulting vector + * @returns The vector, shortened to maxLen if it's too long + */ + function truncate(a, maxLen, dst) { + const newDst = (dst ?? new Ctor(4)); + if (length(a) > maxLen) { + return setLength(a, maxLen, newDst); + } + return copy(a, newDst); + } + /** + * Return the vector exactly between 2 endpoint vectors + * + * @param a Endpoint 1 + * @param b Endpoint 2 + * @returns The vector exactly residing between endpoints 1 and 2 + */ + function midpoint(a, b, dst) { + const newDst = (dst ?? new Ctor(4)); + return lerp(a, b, 0.5, newDst); } - return dst; -} -/** - * Sets the values of a Mat4 - * Also see {@link mat4.create} and {@link mat4.copy} - * - * @param v0 - value for element 0 - * @param v1 - value for element 1 - * @param v2 - value for element 2 - * @param v3 - value for element 3 - * @param v4 - value for element 4 - * @param v5 - value for element 5 - * @param v6 - value for element 6 - * @param v7 - value for element 7 - * @param v8 - value for element 8 - * @param v9 - value for element 9 - * @param v10 - value for element 10 - * @param v11 - value for element 11 - * @param v12 - value for element 12 - * @param v13 - value for element 13 - * @param v14 - value for element 14 - * @param v15 - value for element 15 - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns Mat4 created from values. - */ -function set$2(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, dst) { - dst = dst || new MatType(16); - dst[0] = v0; - dst[1] = v1; - dst[2] = v2; - dst[3] = v3; - dst[4] = v4; - dst[5] = v5; - dst[6] = v6; - dst[7] = v7; - dst[8] = v8; - dst[9] = v9; - dst[10] = v10; - dst[11] = v11; - dst[12] = v12; - dst[13] = v13; - dst[14] = v14; - dst[15] = v15; - return dst; -} -/** - * Creates a Mat4 from a Mat3 - * @param m3 - source matrix - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns Mat4 made from m3 - */ -function fromMat3(m3, dst) { - dst = dst || new MatType(16); - dst[0] = m3[0]; - dst[1] = m3[1]; - dst[2] = m3[2]; - dst[3] = 0; - dst[4] = m3[4]; - dst[5] = m3[5]; - dst[6] = m3[6]; - dst[7] = 0; - dst[8] = m3[8]; - dst[9] = m3[9]; - dst[10] = m3[10]; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Creates a Mat4 rotation matrix from a quaternion - * @param q - quaternion to create matrix from - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns Mat4 made from q - */ -function fromQuat(q, dst) { - dst = dst || new MatType(16); - const x = q[0]; - const y = q[1]; - const z = q[2]; - const w = q[3]; - const x2 = x + x; - const y2 = y + y; - const z2 = z + z; - const xx = x * x2; - const yx = y * x2; - const yy = y * y2; - const zx = z * x2; - const zy = z * y2; - const zz = z * z2; - const wx = w * x2; - const wy = w * y2; - const wz = w * z2; - dst[0] = 1 - yy - zz; - dst[1] = yx + wz; - dst[2] = zx - wy; - dst[3] = 0; - dst[4] = yx - wz; - dst[5] = 1 - xx - zz; - dst[6] = zy + wx; - dst[7] = 0; - dst[8] = zx + wy; - dst[9] = zy - wx; - dst[10] = 1 - xx - yy; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Negates a matrix. - * @param m - The matrix. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns -m. - */ -function negate$1(m, dst) { - dst = dst || new MatType(16); - dst[0] = -m[0]; - dst[1] = -m[1]; - dst[2] = -m[2]; - dst[3] = -m[3]; - dst[4] = -m[4]; - dst[5] = -m[5]; - dst[6] = -m[6]; - dst[7] = -m[7]; - dst[8] = -m[8]; - dst[9] = -m[9]; - dst[10] = -m[10]; - dst[11] = -m[11]; - dst[12] = -m[12]; - dst[13] = -m[13]; - dst[14] = -m[14]; - dst[15] = -m[15]; - return dst; -} -/** - * Copies a matrix. (same as {@link mat4.clone}) - * Also see {@link mat4.create} and {@link mat4.set} - * @param m - The matrix. - * @param dst - The matrix. If not passed a new one is created. - * @returns A copy of m. - */ -function copy$2(m, dst) { - dst = dst || new MatType(16); - dst[0] = m[0]; - dst[1] = m[1]; - dst[2] = m[2]; - dst[3] = m[3]; - dst[4] = m[4]; - dst[5] = m[5]; - dst[6] = m[6]; - dst[7] = m[7]; - dst[8] = m[8]; - dst[9] = m[9]; - dst[10] = m[10]; - dst[11] = m[11]; - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - return dst; -} -/** - * Copies a matrix (same as {@link mat4.copy}) - * Also see {@link mat4.create} and {@link mat4.set} - * @param m - The matrix. - * @param dst - The matrix. If not passed a new one is created. - * @returns A copy of m. - */ -const clone$2 = copy$2; -/** - * Check if 2 matrices are approximately equal - * @param a - Operand matrix. - * @param b - Operand matrix. - * @returns true if matrices are approximately equal - */ -function equalsApproximately$2(a, b) { - return Math.abs(a[0] - b[0]) < EPSILON && - Math.abs(a[1] - b[1]) < EPSILON && - Math.abs(a[2] - b[2]) < EPSILON && - Math.abs(a[3] - b[3]) < EPSILON && - Math.abs(a[4] - b[4]) < EPSILON && - Math.abs(a[5] - b[5]) < EPSILON && - Math.abs(a[6] - b[6]) < EPSILON && - Math.abs(a[7] - b[7]) < EPSILON && - Math.abs(a[8] - b[8]) < EPSILON && - Math.abs(a[9] - b[9]) < EPSILON && - Math.abs(a[10] - b[10]) < EPSILON && - Math.abs(a[11] - b[11]) < EPSILON && - Math.abs(a[12] - b[12]) < EPSILON && - Math.abs(a[13] - b[13]) < EPSILON && - Math.abs(a[14] - b[14]) < EPSILON && - Math.abs(a[15] - b[15]) < EPSILON; -} -/** - * Check if 2 matrices are exactly equal - * @param a - Operand matrix. - * @param b - Operand matrix. - * @returns true if matrices are exactly equal - */ -function equals$2(a, b) { - return a[0] === b[0] && - a[1] === b[1] && - a[2] === b[2] && - a[3] === b[3] && - a[4] === b[4] && - a[5] === b[5] && - a[6] === b[6] && - a[7] === b[7] && - a[8] === b[8] && - a[9] === b[9] && - a[10] === b[10] && - a[11] === b[11] && - a[12] === b[12] && - a[13] === b[13] && - a[14] === b[14] && - a[15] === b[15]; -} -/** - * Creates a 4-by-4 identity matrix. - * - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns A 4-by-4 identity matrix. - */ -function identity$1(dst) { - dst = dst || new MatType(16); - dst[0] = 1; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = 1; - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[10] = 1; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Takes the transpose of a matrix. - * @param m - The matrix. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The transpose of m. - */ -function transpose(m, dst) { - dst = dst || new MatType(16); - if (dst === m) { - let t; - t = m[1]; - m[1] = m[4]; - m[4] = t; - t = m[2]; - m[2] = m[8]; - m[8] = t; - t = m[3]; - m[3] = m[12]; - m[12] = t; - t = m[6]; - m[6] = m[9]; - m[9] = t; - t = m[7]; - m[7] = m[13]; - m[13] = t; - t = m[11]; - m[11] = m[14]; - m[14] = t; - return dst; - } - const m00 = m[0 * 4 + 0]; - const m01 = m[0 * 4 + 1]; - const m02 = m[0 * 4 + 2]; - const m03 = m[0 * 4 + 3]; - const m10 = m[1 * 4 + 0]; - const m11 = m[1 * 4 + 1]; - const m12 = m[1 * 4 + 2]; - const m13 = m[1 * 4 + 3]; - const m20 = m[2 * 4 + 0]; - const m21 = m[2 * 4 + 1]; - const m22 = m[2 * 4 + 2]; - const m23 = m[2 * 4 + 3]; - const m30 = m[3 * 4 + 0]; - const m31 = m[3 * 4 + 1]; - const m32 = m[3 * 4 + 2]; - const m33 = m[3 * 4 + 3]; - dst[0] = m00; - dst[1] = m10; - dst[2] = m20; - dst[3] = m30; - dst[4] = m01; - dst[5] = m11; - dst[6] = m21; - dst[7] = m31; - dst[8] = m02; - dst[9] = m12; - dst[10] = m22; - dst[11] = m32; - dst[12] = m03; - dst[13] = m13; - dst[14] = m23; - dst[15] = m33; - return dst; -} -/** - * Computes the inverse of a 4-by-4 matrix. - * @param m - The matrix. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The inverse of m. - */ -function inverse$2(m, dst) { - dst = dst || new MatType(16); - const m00 = m[0 * 4 + 0]; - const m01 = m[0 * 4 + 1]; - const m02 = m[0 * 4 + 2]; - const m03 = m[0 * 4 + 3]; - const m10 = m[1 * 4 + 0]; - const m11 = m[1 * 4 + 1]; - const m12 = m[1 * 4 + 2]; - const m13 = m[1 * 4 + 3]; - const m20 = m[2 * 4 + 0]; - const m21 = m[2 * 4 + 1]; - const m22 = m[2 * 4 + 2]; - const m23 = m[2 * 4 + 3]; - const m30 = m[3 * 4 + 0]; - const m31 = m[3 * 4 + 1]; - const m32 = m[3 * 4 + 2]; - const m33 = m[3 * 4 + 3]; - const tmp0 = m22 * m33; - const tmp1 = m32 * m23; - const tmp2 = m12 * m33; - const tmp3 = m32 * m13; - const tmp4 = m12 * m23; - const tmp5 = m22 * m13; - const tmp6 = m02 * m33; - const tmp7 = m32 * m03; - const tmp8 = m02 * m23; - const tmp9 = m22 * m03; - const tmp10 = m02 * m13; - const tmp11 = m12 * m03; - const tmp12 = m20 * m31; - const tmp13 = m30 * m21; - const tmp14 = m10 * m31; - const tmp15 = m30 * m11; - const tmp16 = m10 * m21; - const tmp17 = m20 * m11; - const tmp18 = m00 * m31; - const tmp19 = m30 * m01; - const tmp20 = m00 * m21; - const tmp21 = m20 * m01; - const tmp22 = m00 * m11; - const tmp23 = m10 * m01; - const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) - - (tmp1 * m11 + tmp2 * m21 + tmp5 * m31); - const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) - - (tmp0 * m01 + tmp7 * m21 + tmp8 * m31); - const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) - - (tmp3 * m01 + tmp6 * m11 + tmp11 * m31); - const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) - - (tmp4 * m01 + tmp9 * m11 + tmp10 * m21); - const d = 1 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3); - dst[0] = d * t0; - dst[1] = d * t1; - dst[2] = d * t2; - dst[3] = d * t3; - dst[4] = d * ((tmp1 * m10 + tmp2 * m20 + tmp5 * m30) - - (tmp0 * m10 + tmp3 * m20 + tmp4 * m30)); - dst[5] = d * ((tmp0 * m00 + tmp7 * m20 + tmp8 * m30) - - (tmp1 * m00 + tmp6 * m20 + tmp9 * m30)); - dst[6] = d * ((tmp3 * m00 + tmp6 * m10 + tmp11 * m30) - - (tmp2 * m00 + tmp7 * m10 + tmp10 * m30)); - dst[7] = d * ((tmp4 * m00 + tmp9 * m10 + tmp10 * m20) - - (tmp5 * m00 + tmp8 * m10 + tmp11 * m20)); - dst[8] = d * ((tmp12 * m13 + tmp15 * m23 + tmp16 * m33) - - (tmp13 * m13 + tmp14 * m23 + tmp17 * m33)); - dst[9] = d * ((tmp13 * m03 + tmp18 * m23 + tmp21 * m33) - - (tmp12 * m03 + tmp19 * m23 + tmp20 * m33)); - dst[10] = d * ((tmp14 * m03 + tmp19 * m13 + tmp22 * m33) - - (tmp15 * m03 + tmp18 * m13 + tmp23 * m33)); - dst[11] = d * ((tmp17 * m03 + tmp20 * m13 + tmp23 * m23) - - (tmp16 * m03 + tmp21 * m13 + tmp22 * m23)); - dst[12] = d * ((tmp14 * m22 + tmp17 * m32 + tmp13 * m12) - - (tmp16 * m32 + tmp12 * m12 + tmp15 * m22)); - dst[13] = d * ((tmp20 * m32 + tmp12 * m02 + tmp19 * m22) - - (tmp18 * m22 + tmp21 * m32 + tmp13 * m02)); - dst[14] = d * ((tmp18 * m12 + tmp23 * m32 + tmp15 * m02) - - (tmp22 * m32 + tmp14 * m02 + tmp19 * m12)); - dst[15] = d * ((tmp22 * m22 + tmp16 * m02 + tmp21 * m12) - - (tmp20 * m12 + tmp23 * m22 + tmp17 * m02)); - return dst; -} -/** - * Compute the determinant of a matrix - * @param m - the matrix - * @returns the determinant - */ -function determinant(m) { - const m00 = m[0 * 4 + 0]; - const m01 = m[0 * 4 + 1]; - const m02 = m[0 * 4 + 2]; - const m03 = m[0 * 4 + 3]; - const m10 = m[1 * 4 + 0]; - const m11 = m[1 * 4 + 1]; - const m12 = m[1 * 4 + 2]; - const m13 = m[1 * 4 + 3]; - const m20 = m[2 * 4 + 0]; - const m21 = m[2 * 4 + 1]; - const m22 = m[2 * 4 + 2]; - const m23 = m[2 * 4 + 3]; - const m30 = m[3 * 4 + 0]; - const m31 = m[3 * 4 + 1]; - const m32 = m[3 * 4 + 2]; - const m33 = m[3 * 4 + 3]; - const tmp0 = m22 * m33; - const tmp1 = m32 * m23; - const tmp2 = m12 * m33; - const tmp3 = m32 * m13; - const tmp4 = m12 * m23; - const tmp5 = m22 * m13; - const tmp6 = m02 * m33; - const tmp7 = m32 * m03; - const tmp8 = m02 * m23; - const tmp9 = m22 * m03; - const tmp10 = m02 * m13; - const tmp11 = m12 * m03; - const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) - - (tmp1 * m11 + tmp2 * m21 + tmp5 * m31); - const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) - - (tmp0 * m01 + tmp7 * m21 + tmp8 * m31); - const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) - - (tmp3 * m01 + tmp6 * m11 + tmp11 * m31); - const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) - - (tmp4 * m01 + tmp9 * m11 + tmp10 * m21); - return m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3; -} -/** - * Computes the inverse of a 4-by-4 matrix. (same as inverse) - * @param m - The matrix. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The inverse of m. - */ -const invert$1 = inverse$2; -/** - * Multiplies two 4-by-4 matrices with a on the left and b on the right - * @param a - The matrix on the left. - * @param b - The matrix on the right. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The matrix product of a and b. - */ -function multiply$2(a, b, dst) { - dst = dst || new MatType(16); - const a00 = a[0]; - const a01 = a[1]; - const a02 = a[2]; - const a03 = a[3]; - const a10 = a[4 + 0]; - const a11 = a[4 + 1]; - const a12 = a[4 + 2]; - const a13 = a[4 + 3]; - const a20 = a[8 + 0]; - const a21 = a[8 + 1]; - const a22 = a[8 + 2]; - const a23 = a[8 + 3]; - const a30 = a[12 + 0]; - const a31 = a[12 + 1]; - const a32 = a[12 + 2]; - const a33 = a[12 + 3]; - const b00 = b[0]; - const b01 = b[1]; - const b02 = b[2]; - const b03 = b[3]; - const b10 = b[4 + 0]; - const b11 = b[4 + 1]; - const b12 = b[4 + 2]; - const b13 = b[4 + 3]; - const b20 = b[8 + 0]; - const b21 = b[8 + 1]; - const b22 = b[8 + 2]; - const b23 = b[8 + 3]; - const b30 = b[12 + 0]; - const b31 = b[12 + 1]; - const b32 = b[12 + 2]; - const b33 = b[12 + 3]; - dst[0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; - dst[1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; - dst[2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; - dst[3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; - dst[4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; - dst[5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; - dst[6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; - dst[7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; - dst[8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; - dst[9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; - dst[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; - dst[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; - dst[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; - dst[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; - dst[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; - dst[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; - return dst; -} -/** - * Multiplies two 4-by-4 matrices with a on the left and b on the right (same as multiply) - * @param a - The matrix on the left. - * @param b - The matrix on the right. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The matrix product of a and b. - */ -const mul$2 = multiply$2; -/** - * Sets the translation component of a 4-by-4 matrix to the given - * vector. - * @param a - The matrix. - * @param v - The vector. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The matrix with translation set. - */ -function setTranslation(a, v, dst) { - dst = dst || identity$1(); - if (a !== dst) { - dst[0] = a[0]; - dst[1] = a[1]; - dst[2] = a[2]; - dst[3] = a[3]; - dst[4] = a[4]; - dst[5] = a[5]; - dst[6] = a[6]; - dst[7] = a[7]; - dst[8] = a[8]; - dst[9] = a[9]; - dst[10] = a[10]; - dst[11] = a[11]; - } - dst[12] = v[0]; - dst[13] = v[1]; - dst[14] = v[2]; - dst[15] = 1; - return dst; -} -/** - * Returns the translation component of a 4-by-4 matrix as a vector with 3 - * entries. - * @param m - The matrix. - * @param dst - vector to hold result. If not passed a new one is created. - * @returns The translation component of m. - */ -function getTranslation(m, dst) { - dst = dst || create$4(); - dst[0] = m[12]; - dst[1] = m[13]; - dst[2] = m[14]; - return dst; -} -/** - * Returns an axis of a 4x4 matrix as a vector with 3 entries - * @param m - The matrix. - * @param axis - The axis 0 = x, 1 = y, 2 = z; - * @returns The axis component of m. - */ -function getAxis(m, axis, dst) { - dst = dst || create$4(); - const off = axis * 4; - dst[0] = m[off + 0]; - dst[1] = m[off + 1]; - dst[2] = m[off + 2]; - return dst; -} -/** - * Sets an axis of a 4x4 matrix as a vector with 3 entries - * @param m - The matrix. - * @param v - the axis vector - * @param axis - The axis 0 = x, 1 = y, 2 = z; - * @param dst - The matrix to set. If not passed a new one is created. - * @returns The matrix with axis set. - */ -function setAxis(a, v, axis, dst) { - if (dst !== a) { - dst = copy$2(a, dst); - } - const off = axis * 4; - dst[off + 0] = v[0]; - dst[off + 1] = v[1]; - dst[off + 2] = v[2]; - return dst; -} -/** - * Returns the scaling component of the matrix - * @param m - The Matrix - * @param dst - The vector to set. If not passed a new one is created. - */ -function getScaling(m, dst) { - dst = dst || create$4(); - const xx = m[0]; - const xy = m[1]; - const xz = m[2]; - const yx = m[4]; - const yy = m[5]; - const yz = m[6]; - const zx = m[8]; - const zy = m[9]; - const zz = m[10]; - dst[0] = Math.sqrt(xx * xx + xy * xy + xz * xz); - dst[1] = Math.sqrt(yx * yx + yy * yy + yz * yz); - dst[2] = Math.sqrt(zx * zx + zy * zy + zz * zz); - return dst; + return { + create, + fromValues, + set, + ceil, + floor, + round, + clamp, + add, + addScaled, + subtract, + sub, + equalsApproximately, + equals, + lerp, + lerpV, + max, + min, + mulScalar, + scale, + divScalar, + inverse, + invert, + dot, + length, + len, + lengthSq, + lenSq, + distance, + dist, + distanceSq, + distSq, + normalize, + negate, + copy, + clone, + multiply, + mul, + divide, + div, + zero, + transformMat4, + setLength, + truncate, + midpoint, + }; } +const cache = new Map(); /** - * Computes a 4-by-4 perspective transformation matrix given the angular height - * of the frustum, the aspect ratio, and the near and far clipping planes. The - * arguments define a frustum extending in the negative z direction. The given - * angle is the vertical angle of the frustum, and the horizontal angle is - * determined to produce the given aspect ratio. The arguments near and far are - * the distances to the near and far clipping planes. Note that near and far - * are not z coordinates, but rather they are distances along the negative - * z-axis. The matrix generated sends the viewing frustum to the unit box. - * We assume a unit box extending from -1 to 1 in the x and y dimensions and - * from 0 to 1 in the z dimension. - * - * Note: If you pass `Infinity` for zFar then it will produce a projection matrix - * returns -Infinity for Z when transforming coordinates with Z <= 0 and +Infinity for Z - * otherwise. * - * @param fieldOfViewYInRadians - The camera angle from top to bottom (in radians). - * @param aspect - The aspect ratio width / height. - * @param zNear - The depth (negative z coordinate) - * of the near clipping plane. - * @param zFar - The depth (negative z coordinate) - * of the far clipping plane. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The perspective matrix. - */ -function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) { - dst = dst || new MatType(16); - const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians); - dst[0] = f / aspect; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = f; - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[11] = -1; - dst[12] = 0; - dst[13] = 0; - dst[15] = 0; - if (zFar === Infinity) { - dst[10] = -1; - dst[14] = -zNear; - } - else { - const rangeInv = 1 / (zNear - zFar); - dst[10] = zFar * rangeInv; - dst[14] = zFar * zNear * rangeInv; - } - return dst; -} -/** - * Computes a 4-by-4 orthogonal transformation matrix that transforms from - * the given the left, right, bottom, and top dimensions to -1 +1 in x, and y - * and 0 to +1 in z. - * @param left - Left side of the near clipping plane viewport. - * @param right - Right side of the near clipping plane viewport. - * @param bottom - Bottom of the near clipping plane viewport. - * @param top - Top of the near clipping plane viewport. - * @param near - The depth (negative z coordinate) - * of the near clipping plane. - * @param far - The depth (negative z coordinate) - * of the far clipping plane. - * @param dst - Output matrix. If not passed a new one is created. - * @returns The orthographic projection matrix. - */ -function ortho(left, right, bottom, top, near, far, dst) { - dst = dst || new MatType(16); - dst[0] = 2 / (right - left); - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = 2 / (top - bottom); - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[10] = 1 / (near - far); - dst[11] = 0; - dst[12] = (right + left) / (left - right); - dst[13] = (top + bottom) / (bottom - top); - dst[14] = near / (near - far); - dst[15] = 1; - return dst; -} -/** - * Computes a 4-by-4 perspective transformation matrix given the left, right, - * top, bottom, near and far clipping planes. The arguments define a frustum - * extending in the negative z direction. The arguments near and far are the - * distances to the near and far clipping planes. Note that near and far are not - * z coordinates, but rather they are distances along the negative z-axis. The - * matrix generated sends the viewing frustum to the unit box. We assume a unit - * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z - * dimension. - * @param left - The x coordinate of the left plane of the box. - * @param right - The x coordinate of the right plane of the box. - * @param bottom - The y coordinate of the bottom plane of the box. - * @param top - The y coordinate of the right plane of the box. - * @param near - The negative z coordinate of the near plane of the box. - * @param far - The negative z coordinate of the far plane of the box. - * @param dst - Output matrix. If not passed a new one is created. - * @returns The perspective projection matrix. - */ -function frustum(left, right, bottom, top, near, far, dst) { - dst = dst || new MatType(16); - const dx = (right - left); - const dy = (top - bottom); - const dz = (near - far); - dst[0] = 2 * near / dx; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = 2 * near / dy; - dst[6] = 0; - dst[7] = 0; - dst[8] = (left + right) / dx; - dst[9] = (top + bottom) / dy; - dst[10] = far / dz; - dst[11] = -1; - dst[12] = 0; - dst[13] = 0; - dst[14] = near * far / dz; - dst[15] = 0; - return dst; -} -let xAxis; -let yAxis; -let zAxis; -/** - * Computes a 4-by-4 aim transformation. + * Vec4 math functions. * - * This is a matrix which positions an object aiming down positive Z. - * toward the target. + * Almost all functions take an optional `newDst` argument. If it is not passed in the + * functions will create a new `Vec4`. In other words you can do this * - * Note: this is **NOT** the inverse of lookAt as lookAt looks at negative Z. + * const v = vec4.cross(v1, v2); // Creates a new Vec4 with the cross product of v1 x v2. * - * @param position - The position of the object. - * @param target - The position meant to be aimed at. - * @param up - A vector pointing up. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The aim matrix. - */ -function aim(position, target, up, dst) { - dst = dst || new MatType(16); - xAxis = xAxis || create$4(); - yAxis = yAxis || create$4(); - zAxis = zAxis || create$4(); - normalize$2(subtract$2(target, position, zAxis), zAxis); - normalize$2(cross(up, zAxis, xAxis), xAxis); - normalize$2(cross(zAxis, xAxis, yAxis), yAxis); - dst[0] = xAxis[0]; - dst[1] = xAxis[1]; - dst[2] = xAxis[2]; - dst[3] = 0; - dst[4] = yAxis[0]; - dst[5] = yAxis[1]; - dst[6] = yAxis[2]; - dst[7] = 0; - dst[8] = zAxis[0]; - dst[9] = zAxis[1]; - dst[10] = zAxis[2]; - dst[11] = 0; - dst[12] = position[0]; - dst[13] = position[1]; - dst[14] = position[2]; - dst[15] = 1; - return dst; -} -/** - * Computes a 4-by-4 camera aim transformation. + * or * - * This is a matrix which positions an object aiming down negative Z. - * toward the target. + * const v = vec4.create(); + * vec4.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v * - * Note: this is the inverse of `lookAt` + * The first style is often easier but depending on where it's used it generates garbage where + * as there is almost never allocation with the second style. * - * @param eye - The position of the object. - * @param target - The position meant to be aimed at. - * @param up - A vector pointing up. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The aim matrix. - */ -function cameraAim(eye, target, up, dst) { - dst = dst || new MatType(16); - xAxis = xAxis || create$4(); - yAxis = yAxis || create$4(); - zAxis = zAxis || create$4(); - normalize$2(subtract$2(eye, target, zAxis), zAxis); - normalize$2(cross(up, zAxis, xAxis), xAxis); - normalize$2(cross(zAxis, xAxis, yAxis), yAxis); - dst[0] = xAxis[0]; - dst[1] = xAxis[1]; - dst[2] = xAxis[2]; - dst[3] = 0; - dst[4] = yAxis[0]; - dst[5] = yAxis[1]; - dst[6] = yAxis[2]; - dst[7] = 0; - dst[8] = zAxis[0]; - dst[9] = zAxis[1]; - dst[10] = zAxis[2]; - dst[11] = 0; - dst[12] = eye[0]; - dst[13] = eye[1]; - dst[14] = eye[2]; - dst[15] = 1; - return dst; -} -/** - * Computes a 4-by-4 view transformation. + * It is always safe to pass any vector as the destination. So for example * - * This is a view matrix which transforms all other objects - * to be in the space of the view defined by the parameters. + * vec4.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1 * - * @param eye - The position of the object. - * @param target - The position meant to be aimed at. - * @param up - A vector pointing up. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The look-at matrix. - */ -function lookAt(eye, target, up, dst) { - dst = dst || new MatType(16); - xAxis = xAxis || create$4(); - yAxis = yAxis || create$4(); - zAxis = zAxis || create$4(); - normalize$2(subtract$2(eye, target, zAxis), zAxis); - normalize$2(cross(up, zAxis, xAxis), xAxis); - normalize$2(cross(zAxis, xAxis, yAxis), yAxis); - dst[0] = xAxis[0]; - dst[1] = yAxis[0]; - dst[2] = zAxis[0]; - dst[3] = 0; - dst[4] = xAxis[1]; - dst[5] = yAxis[1]; - dst[6] = zAxis[1]; - dst[7] = 0; - dst[8] = xAxis[2]; - dst[9] = yAxis[2]; - dst[10] = zAxis[2]; - dst[11] = 0; - dst[12] = -(xAxis[0] * eye[0] + xAxis[1] * eye[1] + xAxis[2] * eye[2]); - dst[13] = -(yAxis[0] * eye[0] + yAxis[1] * eye[1] + yAxis[2] * eye[2]); - dst[14] = -(zAxis[0] * eye[0] + zAxis[1] * eye[1] + zAxis[2] * eye[2]); - dst[15] = 1; - return dst; -} -/** - * Creates a 4-by-4 matrix which translates by the given vector v. - * @param v - The vector by - * which to translate. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The translation matrix. - */ -function translation(v, dst) { - dst = dst || new MatType(16); - dst[0] = 1; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = 1; - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[10] = 1; - dst[11] = 0; - dst[12] = v[0]; - dst[13] = v[1]; - dst[14] = v[2]; - dst[15] = 1; - return dst; -} -/** - * Translates the given 4-by-4 matrix by the given vector v. - * @param m - The matrix. - * @param v - The vector by - * which to translate. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The translated matrix. - */ -function translate(m, v, dst) { - dst = dst || new MatType(16); - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - const m00 = m[0]; - const m01 = m[1]; - const m02 = m[2]; - const m03 = m[3]; - const m10 = m[1 * 4 + 0]; - const m11 = m[1 * 4 + 1]; - const m12 = m[1 * 4 + 2]; - const m13 = m[1 * 4 + 3]; - const m20 = m[2 * 4 + 0]; - const m21 = m[2 * 4 + 1]; - const m22 = m[2 * 4 + 2]; - const m23 = m[2 * 4 + 3]; - const m30 = m[3 * 4 + 0]; - const m31 = m[3 * 4 + 1]; - const m32 = m[3 * 4 + 2]; - const m33 = m[3 * 4 + 3]; - if (m !== dst) { - dst[0] = m00; - dst[1] = m01; - dst[2] = m02; - dst[3] = m03; - dst[4] = m10; - dst[5] = m11; - dst[6] = m12; - dst[7] = m13; - dst[8] = m20; - dst[9] = m21; - dst[10] = m22; - dst[11] = m23; - } - dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30; - dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31; - dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32; - dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33; - return dst; -} -/** - * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotation matrix. - */ -function rotationX(angleInRadians, dst) { - dst = dst || new MatType(16); - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - dst[0] = 1; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = c; - dst[6] = s; - dst[7] = 0; - dst[8] = 0; - dst[9] = -s; - dst[10] = c; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Rotates the given 4-by-4 matrix around the x-axis by the given - * angle. - * @param m - The matrix. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotated matrix. - */ -function rotateX$1(m, angleInRadians, dst) { - dst = dst || new MatType(16); - const m10 = m[4]; - const m11 = m[5]; - const m12 = m[6]; - const m13 = m[7]; - const m20 = m[8]; - const m21 = m[9]; - const m22 = m[10]; - const m23 = m[11]; - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - dst[4] = c * m10 + s * m20; - dst[5] = c * m11 + s * m21; - dst[6] = c * m12 + s * m22; - dst[7] = c * m13 + s * m23; - dst[8] = c * m20 - s * m10; - dst[9] = c * m21 - s * m11; - dst[10] = c * m22 - s * m12; - dst[11] = c * m23 - s * m13; - if (m !== dst) { - dst[0] = m[0]; - dst[1] = m[1]; - dst[2] = m[2]; - dst[3] = m[3]; - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - } - return dst; -} -/** - * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotation matrix. - */ -function rotationY(angleInRadians, dst) { - dst = dst || new MatType(16); - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - dst[0] = c; - dst[1] = 0; - dst[2] = -s; - dst[3] = 0; - dst[4] = 0; - dst[5] = 1; - dst[6] = 0; - dst[7] = 0; - dst[8] = s; - dst[9] = 0; - dst[10] = c; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Rotates the given 4-by-4 matrix around the y-axis by the given - * angle. - * @param m - The matrix. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotated matrix. - */ -function rotateY$1(m, angleInRadians, dst) { - dst = dst || new MatType(16); - const m00 = m[0 * 4 + 0]; - const m01 = m[0 * 4 + 1]; - const m02 = m[0 * 4 + 2]; - const m03 = m[0 * 4 + 3]; - const m20 = m[2 * 4 + 0]; - const m21 = m[2 * 4 + 1]; - const m22 = m[2 * 4 + 2]; - const m23 = m[2 * 4 + 3]; - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - dst[0] = c * m00 - s * m20; - dst[1] = c * m01 - s * m21; - dst[2] = c * m02 - s * m22; - dst[3] = c * m03 - s * m23; - dst[8] = c * m20 + s * m00; - dst[9] = c * m21 + s * m01; - dst[10] = c * m22 + s * m02; - dst[11] = c * m23 + s * m03; - if (m !== dst) { - dst[4] = m[4]; - dst[5] = m[5]; - dst[6] = m[6]; - dst[7] = m[7]; - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - } - return dst; -} -/** - * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotation matrix. - */ -function rotationZ(angleInRadians, dst) { - dst = dst || new MatType(16); - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - dst[0] = c; - dst[1] = s; - dst[2] = 0; - dst[3] = 0; - dst[4] = -s; - dst[5] = c; - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[10] = 1; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Rotates the given 4-by-4 matrix around the z-axis by the given - * angle. - * @param m - The matrix. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotated matrix. - */ -function rotateZ$1(m, angleInRadians, dst) { - dst = dst || new MatType(16); - const m00 = m[0 * 4 + 0]; - const m01 = m[0 * 4 + 1]; - const m02 = m[0 * 4 + 2]; - const m03 = m[0 * 4 + 3]; - const m10 = m[1 * 4 + 0]; - const m11 = m[1 * 4 + 1]; - const m12 = m[1 * 4 + 2]; - const m13 = m[1 * 4 + 3]; - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - dst[0] = c * m00 + s * m10; - dst[1] = c * m01 + s * m11; - dst[2] = c * m02 + s * m12; - dst[3] = c * m03 + s * m13; - dst[4] = c * m10 - s * m00; - dst[5] = c * m11 - s * m01; - dst[6] = c * m12 - s * m02; - dst[7] = c * m13 - s * m03; - if (m !== dst) { - dst[8] = m[8]; - dst[9] = m[9]; - dst[10] = m[10]; - dst[11] = m[11]; - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - } - return dst; -} -/** - * Creates a 4-by-4 matrix which rotates around the given axis by the given - * angle. - * @param axis - The axis - * about which to rotate. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns A matrix which rotates angle radians - * around the axis. - */ -function axisRotation(axis, angleInRadians, dst) { - dst = dst || new MatType(16); - let x = axis[0]; - let y = axis[1]; - let z = axis[2]; - const n = Math.sqrt(x * x + y * y + z * z); - x /= n; - y /= n; - z /= n; - const xx = x * x; - const yy = y * y; - const zz = z * z; - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - const oneMinusCosine = 1 - c; - dst[0] = xx + (1 - xx) * c; - dst[1] = x * y * oneMinusCosine + z * s; - dst[2] = x * z * oneMinusCosine - y * s; - dst[3] = 0; - dst[4] = x * y * oneMinusCosine - z * s; - dst[5] = yy + (1 - yy) * c; - dst[6] = y * z * oneMinusCosine + x * s; - dst[7] = 0; - dst[8] = x * z * oneMinusCosine + y * s; - dst[9] = y * z * oneMinusCosine - x * s; - dst[10] = zz + (1 - zz) * c; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Creates a 4-by-4 matrix which rotates around the given axis by the given - * angle. (same as axisRotation) - * @param axis - The axis - * about which to rotate. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns A matrix which rotates angle radians - * around the axis. - */ -const rotation = axisRotation; -/** - * Rotates the given 4-by-4 matrix around the given axis by the - * given angle. - * @param m - The matrix. - * @param axis - The axis - * about which to rotate. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotated matrix. - */ -function axisRotate(m, axis, angleInRadians, dst) { - dst = dst || new MatType(16); - let x = axis[0]; - let y = axis[1]; - let z = axis[2]; - const n = Math.sqrt(x * x + y * y + z * z); - x /= n; - y /= n; - z /= n; - const xx = x * x; - const yy = y * y; - const zz = z * z; - const c = Math.cos(angleInRadians); - const s = Math.sin(angleInRadians); - const oneMinusCosine = 1 - c; - const r00 = xx + (1 - xx) * c; - const r01 = x * y * oneMinusCosine + z * s; - const r02 = x * z * oneMinusCosine - y * s; - const r10 = x * y * oneMinusCosine - z * s; - const r11 = yy + (1 - yy) * c; - const r12 = y * z * oneMinusCosine + x * s; - const r20 = x * z * oneMinusCosine + y * s; - const r21 = y * z * oneMinusCosine - x * s; - const r22 = zz + (1 - zz) * c; - const m00 = m[0]; - const m01 = m[1]; - const m02 = m[2]; - const m03 = m[3]; - const m10 = m[4]; - const m11 = m[5]; - const m12 = m[6]; - const m13 = m[7]; - const m20 = m[8]; - const m21 = m[9]; - const m22 = m[10]; - const m23 = m[11]; - dst[0] = r00 * m00 + r01 * m10 + r02 * m20; - dst[1] = r00 * m01 + r01 * m11 + r02 * m21; - dst[2] = r00 * m02 + r01 * m12 + r02 * m22; - dst[3] = r00 * m03 + r01 * m13 + r02 * m23; - dst[4] = r10 * m00 + r11 * m10 + r12 * m20; - dst[5] = r10 * m01 + r11 * m11 + r12 * m21; - dst[6] = r10 * m02 + r11 * m12 + r12 * m22; - dst[7] = r10 * m03 + r11 * m13 + r12 * m23; - dst[8] = r20 * m00 + r21 * m10 + r22 * m20; - dst[9] = r20 * m01 + r21 * m11 + r22 * m21; - dst[10] = r20 * m02 + r21 * m12 + r22 * m22; - dst[11] = r20 * m03 + r21 * m13 + r22 * m23; - if (m !== dst) { - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - } - return dst; -} -/** - * Rotates the given 4-by-4 matrix around the given axis by the - * given angle. (same as rotate) - * @param m - The matrix. - * @param axis - The axis - * about which to rotate. - * @param angleInRadians - The angle by which to rotate (in radians). - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The rotated matrix. */ -const rotate = axisRotate; -/** - * Creates a 4-by-4 matrix which scales in each dimension by an amount given by - * the corresponding entry in the given vector; assumes the vector has three - * entries. - * @param v - A vector of - * three entries specifying the factor by which to scale in each dimension. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The scaling matrix. - */ -function scaling(v, dst) { - dst = dst || new MatType(16); - dst[0] = v[0]; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = v[1]; - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[10] = v[2]; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; -} -/** - * Scales the given 4-by-4 matrix in each dimension by an amount - * given by the corresponding entry in the given vector; assumes the vector has - * three entries. - * @param m - The matrix to be modified. - * @param v - A vector of three entries specifying the - * factor by which to scale in each dimension. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The scaled matrix. - */ -function scale$2(m, v, dst) { - dst = dst || new MatType(16); - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - dst[0] = v0 * m[0 * 4 + 0]; - dst[1] = v0 * m[0 * 4 + 1]; - dst[2] = v0 * m[0 * 4 + 2]; - dst[3] = v0 * m[0 * 4 + 3]; - dst[4] = v1 * m[1 * 4 + 0]; - dst[5] = v1 * m[1 * 4 + 1]; - dst[6] = v1 * m[1 * 4 + 2]; - dst[7] = v1 * m[1 * 4 + 3]; - dst[8] = v2 * m[2 * 4 + 0]; - dst[9] = v2 * m[2 * 4 + 1]; - dst[10] = v2 * m[2 * 4 + 2]; - dst[11] = v2 * m[2 * 4 + 3]; - if (m !== dst) { - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - } - return dst; -} -/** - * Creates a 4-by-4 matrix which scales a uniform amount in each dimension. - * @param s - the amount to scale - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The scaling matrix. - */ -function uniformScaling(s, dst) { - dst = dst || new MatType(16); - dst[0] = s; - dst[1] = 0; - dst[2] = 0; - dst[3] = 0; - dst[4] = 0; - dst[5] = s; - dst[6] = 0; - dst[7] = 0; - dst[8] = 0; - dst[9] = 0; - dst[10] = s; - dst[11] = 0; - dst[12] = 0; - dst[13] = 0; - dst[14] = 0; - dst[15] = 1; - return dst; +function getAPI(Ctor) { + let api = cache.get(Ctor); + if (!api) { + api = getAPIImpl(Ctor); + cache.set(Ctor, api); + } + return api; } + /** - * Scales the given 4-by-4 matrix in each dimension by a uniform scale. - * @param m - The matrix to be modified. - * @param s - The amount to scale. - * @param dst - matrix to hold result. If not passed a new one is created. - * @returns The scaled matrix. + * Generate wgpu-matrix API for type */ -function uniformScale(m, s, dst) { - dst = dst || new MatType(16); - dst[0] = s * m[0 * 4 + 0]; - dst[1] = s * m[0 * 4 + 1]; - dst[2] = s * m[0 * 4 + 2]; - dst[3] = s * m[0 * 4 + 3]; - dst[4] = s * m[1 * 4 + 0]; - dst[5] = s * m[1 * 4 + 1]; - dst[6] = s * m[1 * 4 + 2]; - dst[7] = s * m[1 * 4 + 3]; - dst[8] = s * m[2 * 4 + 0]; - dst[9] = s * m[2 * 4 + 1]; - dst[10] = s * m[2 * 4 + 2]; - dst[11] = s * m[2 * 4 + 3]; - if (m !== dst) { - dst[12] = m[12]; - dst[13] = m[13]; - dst[14] = m[14]; - dst[15] = m[15]; - } - return dst; +function wgpuMatrixAPI(Mat3Ctor, Mat4Ctor, QuatCtor, Vec2Ctor, Vec3Ctor, Vec4Ctor) { + return { + /** @namespace mat4 */ + mat4: getAPI$2(Mat3Ctor), + /** @namespace mat3 */ + mat3: getAPI$4(Mat4Ctor), + /** @namespace quat */ + quat: getAPI$1(QuatCtor), + /** @namespace vec2 */ + vec2: getAPI$5(Vec2Ctor), + /** @namespace vec3 */ + vec3: getAPI$3(Vec3Ctor), + /** @namespace vec4 */ + vec4: getAPI(Vec4Ctor), + }; } - -var mat4Impl = /*#__PURE__*/Object.freeze({ - __proto__: null, - aim: aim, - axisRotate: axisRotate, - axisRotation: axisRotation, - cameraAim: cameraAim, - clone: clone$2, - copy: copy$2, - create: create$2, - determinant: determinant, - equals: equals$2, - equalsApproximately: equalsApproximately$2, - fromMat3: fromMat3, - fromQuat: fromQuat, - frustum: frustum, - getAxis: getAxis, - getScaling: getScaling, - getTranslation: getTranslation, - identity: identity$1, - inverse: inverse$2, - invert: invert$1, - lookAt: lookAt, - mul: mul$2, - multiply: multiply$2, - negate: negate$1, - ortho: ortho, - perspective: perspective, - rotate: rotate, - rotateX: rotateX$1, - rotateY: rotateY$1, - rotateZ: rotateZ$1, - rotation: rotation, - rotationX: rotationX, - rotationY: rotationY, - rotationZ: rotationZ, - scale: scale$2, - scaling: scaling, - set: set$2, - setAxis: setAxis, - setDefaultType: setDefaultType$3, - setTranslation: setTranslation, - translate: translate, - translation: translation, - transpose: transpose, - uniformScale: uniformScale, - uniformScaling: uniformScaling -}); +const { +/** @namespace */ +mat4, +/** @namespace */ +mat3, +/** @namespace */ +quat, +/** @namespace */ +vec2, +/** @namespace */ +vec3, +/** @namespace */ +vec4, } = wgpuMatrixAPI(Float32Array, Float32Array, Float32Array, Float32Array, Float32Array, Float32Array); +wgpuMatrixAPI(Float64Array, Float64Array, Float64Array, Float64Array, Float64Array, Float64Array); +wgpuMatrixAPI(ZeroArray, Array, Array, Array, Array, Array); /** * dat-gui JavaScript Controller Library @@ -5035,19 +7995,19 @@ function computeSurfaceNormals(positions, triangles) { const p0 = positions[i0]; const p1 = positions[i1]; const p2 = positions[i2]; - const v0 = vec3Impl.subtract(p1, p0); - const v1 = vec3Impl.subtract(p2, p0); - vec3Impl.normalize(v0, v0); - vec3Impl.normalize(v1, v1); - const norm = vec3Impl.cross(v0, v1); + const v0 = vec3.subtract(p1, p0); + const v1 = vec3.subtract(p2, p0); + vec3.normalize(v0, v0); + vec3.normalize(v1, v1); + const norm = vec3.cross(v0, v1); // Accumulate the normals. - vec3Impl.add(normals[i0], norm, normals[i0]); - vec3Impl.add(normals[i1], norm, normals[i1]); - vec3Impl.add(normals[i2], norm, normals[i2]); + vec3.add(normals[i0], norm, normals[i0]); + vec3.add(normals[i1], norm, normals[i1]); + vec3.add(normals[i2], norm, normals[i2]); }); normals.forEach((n) => { // Normalize accumulated normals. - vec3Impl.normalize(n, n); + vec3.normalize(n, n); }); return normals; } @@ -5754,15 +8714,15 @@ const configure = () => { // Rotates the camera around the origin based on time. function getCameraViewProjMatrix() { const aspect = canvas.width / canvas.height; - const projectionMatrix = mat4Impl.perspective((2 * Math.PI) / 5, aspect, 1, 2000.0); - const upVector = vec3Impl.fromValues(0, 1, 0); - const origin = vec3Impl.fromValues(0, 0, 0); - const eyePosition = vec3Impl.fromValues(0, 5, -100); + const projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 2000.0); + const upVector = vec3.fromValues(0, 1, 0); + const origin = vec3.fromValues(0, 0, 0); + const eyePosition = vec3.fromValues(0, 5, -100); const rad = Math.PI * (Date.now() / 5000); - const rotation = mat4Impl.rotateY(mat4Impl.translation(origin), rad); - vec3Impl.transformMat4(eyePosition, rotation, eyePosition); - const viewMatrix = mat4Impl.lookAt(eyePosition, origin, upVector); - const viewProjMatrix = mat4Impl.multiply(projectionMatrix, viewMatrix); + const rotation = mat4.rotateY(mat4.translation(origin), rad); + vec3.transformMat4(eyePosition, rotation, eyePosition); + const viewMatrix = mat4.lookAt(eyePosition, origin, upVector); + const viewProjMatrix = mat4.multiply(projectionMatrix, viewMatrix); return viewProjMatrix; } return function doDraw() { diff --git a/sample/a-buffer/main.js.map b/sample/a-buffer/main.js.map index 905fadd9..e814de74 100644 --- a/sample/a-buffer/main.js.map +++ b/sample/a-buffer/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sources":["../../../node_modules/wgpu-matrix/dist/2.x/wgpu-matrix.module.js","../../../node_modules/dat.gui/build/dat.gui.module.js","../../../node_modules/teapot/teapot.js","../../../../../meshes/utils.ts","../../../../../meshes/teapot.ts","../../../../../sample/a-buffer/main.ts"],"sourcesContent":["/* wgpu-matrix@2.8.0, license MIT */\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\nlet EPSILON = 0.000001;\n/**\n * Set the value for EPSILON for various checks\n * @param v - Value to use for EPSILON.\n * @returns previous value of EPSILON;\n */\nfunction setEpsilon(v) {\n const old = EPSILON;\n EPSILON = v;\n return old;\n}\n/**\n * Convert degrees to radians\n * @param degrees - Angle in degrees\n * @returns angle converted to radians\n */\nfunction degToRad(degrees) {\n return degrees * Math.PI / 180;\n}\n/**\n * Convert radians to degrees\n * @param radians - Angle in radians\n * @returns angle converted to degrees\n */\nfunction radToDeg(radians) {\n return radians * 180 / Math.PI;\n}\n/**\n * Lerps between a and b via t\n * @param a - starting value\n * @param b - ending value\n * @param t - value where 0 = a and 1 = b\n * @returns a + (b - a) * t\n */\nfunction lerp$4(a, b, t) {\n return a + (b - a) * t;\n}\n/**\n * Compute the opposite of lerp. Given a and b and a value between\n * a and b returns a value between 0 and 1. 0 if a, 1 if b.\n * Note: no clamping is done.\n * @param a - start value\n * @param b - end value\n * @param v - value between a and b\n * @returns (v - a) / (b - a)\n */\nfunction inverseLerp(a, b, v) {\n const d = b - a;\n return (Math.abs(b - a) < EPSILON)\n ? a\n : (v - a) / d;\n}\n/**\n * Compute the euclidean modulo\n *\n * ```\n * // table for n / 3\n * -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 <- n\n * ------------------------------------\n * -2 -1 -0 -2 -1 0, 1, 2, 0, 1, 2 <- n % 3\n * 1 2 0 1 2 0, 1, 2, 0, 1, 2 <- euclideanModule(n, 3)\n * ```\n *\n * @param n - dividend\n * @param m - divisor\n * @returns the euclidean modulo of n / m\n */\nfunction euclideanModulo(n, m) {\n return ((n % m) + m) % m;\n}\n\nvar utils = /*#__PURE__*/Object.freeze({\n __proto__: null,\n get EPSILON () { return EPSILON; },\n degToRad: degToRad,\n euclideanModulo: euclideanModulo,\n inverseLerp: inverseLerp,\n lerp: lerp$4,\n radToDeg: radToDeg,\n setEpsilon: setEpsilon\n});\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n *\n * Vec2 math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new Vec2. In other words you can do this\n *\n * const v = vec2.cross(v1, v2); // Creates a new Vec2 with the cross product of v1 x v2.\n *\n * or\n *\n * const v = vec2.create();\n * vec2.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always safe to pass any vector as the destination. So for example\n *\n * vec2.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1\n *\n */\nlet VecType$2 = Float32Array;\n/**\n * Sets the type this library creates for a Vec2\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n * @returns previous constructor for Vec2\n */\nfunction setDefaultType$6(ctor) {\n const oldType = VecType$2;\n VecType$2 = ctor;\n return oldType;\n}\n/**\n * Creates a Vec2; may be called with x, y, z to set initial values.\n *\n * Note: Since passing in a raw JavaScript array\n * is valid in all circumstances, if you want to\n * force a JavaScript array into a Vec2's specified type\n * it would be faster to use\n *\n * ```\n * const v = vec2.clone(someJSArray);\n * ```\n *\n * Note: a consequence of the implementation is if your Vec2Type = `Array`\n * instead of `Float32Array` or `Float64Array` then any values you\n * don't pass in will be undefined. Usually this is not an issue since\n * (a) using `Array` is rare and (b) using `vec2.create` is usually used\n * to create a Vec2 to be filled out as in\n *\n * ```\n * const sum = vec2.create();\n * vec2.add(v1, v2, sum);\n * ```\n *\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @returns the created vector\n */\nfunction create$5(x = 0, y = 0) {\n const dst = new VecType$2(2);\n if (x !== undefined) {\n dst[0] = x;\n if (y !== undefined) {\n dst[1] = y;\n }\n }\n return dst;\n}\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n *\n * Vec3 math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new `Vec3`. In other words you can do this\n *\n * const v = vec3.cross(v1, v2); // Creates a new Vec3 with the cross product of v1 x v2.\n *\n * or\n *\n * const v = vec3.create();\n * vec3.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always safe to pass any vector as the destination. So for example\n *\n * vec3.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1\n *\n */\nlet VecType$1 = Float32Array;\n/**\n * Sets the type this library creates for a Vec3\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n * @returns previous constructor for Vec3\n */\nfunction setDefaultType$5(ctor) {\n const oldType = VecType$1;\n VecType$1 = ctor;\n return oldType;\n}\n/**\n * Creates a vec3; may be called with x, y, z to set initial values.\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @param z - Initial z value.\n * @returns the created vector\n */\nfunction create$4(x, y, z) {\n const dst = new VecType$1(3);\n if (x !== undefined) {\n dst[0] = x;\n if (y !== undefined) {\n dst[1] = y;\n if (z !== undefined) {\n dst[2] = z;\n }\n }\n }\n return dst;\n}\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n * Creates a Vec2; may be called with x, y, z to set initial values. (same as create)\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @returns the created vector\n */\nconst fromValues$3 = create$5;\n/**\n * Sets the values of a Vec2\n * Also see {@link vec2.create} and {@link vec2.copy}\n *\n * @param x first value\n * @param y second value\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector with its elements set.\n */\nfunction set$5(x, y, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = x;\n dst[1] = y;\n return dst;\n}\n/**\n * Applies Math.ceil to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the ceil of each element of v.\n */\nfunction ceil$2(v, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = Math.ceil(v[0]);\n dst[1] = Math.ceil(v[1]);\n return dst;\n}\n/**\n * Applies Math.floor to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the floor of each element of v.\n */\nfunction floor$2(v, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = Math.floor(v[0]);\n dst[1] = Math.floor(v[1]);\n return dst;\n}\n/**\n * Applies Math.round to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the round of each element of v.\n */\nfunction round$2(v, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = Math.round(v[0]);\n dst[1] = Math.round(v[1]);\n return dst;\n}\n/**\n * Clamp each element of vector between min and max\n * @param v - Operand vector.\n * @param max - Min value, default 0\n * @param min - Max value, default 1\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that the clamped value of each element of v.\n */\nfunction clamp$2(v, min = 0, max = 1, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = Math.min(max, Math.max(min, v[0]));\n dst[1] = Math.min(max, Math.max(min, v[1]));\n return dst;\n}\n/**\n * Adds two vectors; assumes a and b have the same dimension.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the sum of a and b.\n */\nfunction add$3(a, b, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] + b[0];\n dst[1] = a[1] + b[1];\n return dst;\n}\n/**\n * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param scale - Amount to scale b\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the sum of a + b * scale.\n */\nfunction addScaled$2(a, b, scale, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] + b[0] * scale;\n dst[1] = a[1] + b[1] * scale;\n return dst;\n}\n/**\n * Returns the angle in radians between two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns The angle in radians between the 2 vectors.\n */\nfunction angle$2(a, b) {\n const ax = a[0];\n const ay = a[1];\n const bx = a[0];\n const by = a[1];\n const mag1 = Math.sqrt(ax * ax + ay * ay);\n const mag2 = Math.sqrt(bx * bx + by * by);\n const mag = mag1 * mag2;\n const cosine = mag && dot$3(a, b) / mag;\n return Math.acos(cosine);\n}\n/**\n * Subtracts two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the difference of a and b.\n */\nfunction subtract$3(a, b, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] - b[0];\n dst[1] = a[1] - b[1];\n return dst;\n}\n/**\n * Subtracts two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the difference of a and b.\n */\nconst sub$3 = subtract$3;\n/**\n * Check if 2 vectors are approximately equal\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns true if vectors are approximately equal\n */\nfunction equalsApproximately$5(a, b) {\n return Math.abs(a[0] - b[0]) < EPSILON &&\n Math.abs(a[1] - b[1]) < EPSILON;\n}\n/**\n * Check if 2 vectors are exactly equal\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns true if vectors are exactly equal\n */\nfunction equals$5(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient t, returns\n * a + t * (b - a).\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param t - Interpolation coefficient.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The linear interpolated result.\n */\nfunction lerp$3(a, b, t, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] + t * (b[0] - a[0]);\n dst[1] = a[1] + t * (b[1] - a[1]);\n return dst;\n}\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient vector t, returns\n * a + t * (b - a).\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param t - Interpolation coefficients vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns the linear interpolated result.\n */\nfunction lerpV$2(a, b, t, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] + t[0] * (b[0] - a[0]);\n dst[1] = a[1] + t[1] * (b[1] - a[1]);\n return dst;\n}\n/**\n * Return max values of two vectors.\n * Given vectors a and b returns\n * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The max components vector.\n */\nfunction max$2(a, b, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = Math.max(a[0], b[0]);\n dst[1] = Math.max(a[1], b[1]);\n return dst;\n}\n/**\n * Return min values of two vectors.\n * Given vectors a and b returns\n * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The min components vector.\n */\nfunction min$2(a, b, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = Math.min(a[0], b[0]);\n dst[1] = Math.min(a[1], b[1]);\n return dst;\n}\n/**\n * Multiplies a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nfunction mulScalar$3(v, k, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = v[0] * k;\n dst[1] = v[1] * k;\n return dst;\n}\n/**\n * Multiplies a vector by a scalar. (same as mulScalar)\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nconst scale$5 = mulScalar$3;\n/**\n * Divides a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nfunction divScalar$3(v, k, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = v[0] / k;\n dst[1] = v[1] / k;\n return dst;\n}\n/**\n * Inverse a vector.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The inverted vector.\n */\nfunction inverse$5(v, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = 1 / v[0];\n dst[1] = 1 / v[1];\n return dst;\n}\n/**\n * Invert a vector. (same as inverse)\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The inverted vector.\n */\nconst invert$4 = inverse$5;\n/**\n * Computes the cross product of two vectors; assumes both vectors have\n * three entries.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of a cross b.\n */\nfunction cross$1(a, b, dst) {\n dst = dst || new VecType$1(3);\n const z = a[0] * b[1] - a[1] * b[0];\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = z;\n return dst;\n}\n/**\n * Computes the dot product of two vectors; assumes both vectors have\n * three entries.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns dot product\n */\nfunction dot$3(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the length of vector\n * @param v - vector.\n * @returns length of vector.\n */\nfunction length$3(v) {\n const v0 = v[0];\n const v1 = v[1];\n return Math.sqrt(v0 * v0 + v1 * v1);\n}\n/**\n * Computes the length of vector (same as length)\n * @param v - vector.\n * @returns length of vector.\n */\nconst len$3 = length$3;\n/**\n * Computes the square of the length of vector\n * @param v - vector.\n * @returns square of the length of vector.\n */\nfunction lengthSq$3(v) {\n const v0 = v[0];\n const v1 = v[1];\n return v0 * v0 + v1 * v1;\n}\n/**\n * Computes the square of the length of vector (same as lengthSq)\n * @param v - vector.\n * @returns square of the length of vector.\n */\nconst lenSq$3 = lengthSq$3;\n/**\n * Computes the distance between 2 points\n * @param a - vector.\n * @param b - vector.\n * @returns distance between a and b\n */\nfunction distance$2(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n return Math.sqrt(dx * dx + dy * dy);\n}\n/**\n * Computes the distance between 2 points (same as distance)\n * @param a - vector.\n * @param b - vector.\n * @returns distance between a and b\n */\nconst dist$2 = distance$2;\n/**\n * Computes the square of the distance between 2 points\n * @param a - vector.\n * @param b - vector.\n * @returns square of the distance between a and b\n */\nfunction distanceSq$2(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n return dx * dx + dy * dy;\n}\n/**\n * Computes the square of the distance between 2 points (same as distanceSq)\n * @param a - vector.\n * @param b - vector.\n * @returns square of the distance between a and b\n */\nconst distSq$2 = distanceSq$2;\n/**\n * Divides a vector by its Euclidean length and returns the quotient.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The normalized vector.\n */\nfunction normalize$3(v, dst) {\n dst = dst || new VecType$2(2);\n const v0 = v[0];\n const v1 = v[1];\n const len = Math.sqrt(v0 * v0 + v1 * v1);\n if (len > 0.00001) {\n dst[0] = v0 / len;\n dst[1] = v1 / len;\n }\n else {\n dst[0] = 0;\n dst[1] = 0;\n }\n return dst;\n}\n/**\n * Negates a vector.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns -v.\n */\nfunction negate$4(v, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = -v[0];\n dst[1] = -v[1];\n return dst;\n}\n/**\n * Copies a vector. (same as {@link vec2.clone})\n * Also see {@link vec2.create} and {@link vec2.set}\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A copy of v.\n */\nfunction copy$5(v, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = v[0];\n dst[1] = v[1];\n return dst;\n}\n/**\n * Clones a vector. (same as {@link vec2.copy})\n * Also see {@link vec2.create} and {@link vec2.set}\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A copy of v.\n */\nconst clone$5 = copy$5;\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of products of entries of a and b.\n */\nfunction multiply$5(a, b, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] * b[0];\n dst[1] = a[1] * b[1];\n return dst;\n}\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length. (same as mul)\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of products of entries of a and b.\n */\nconst mul$5 = multiply$5;\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of quotients of entries of a and b.\n */\nfunction divide$2(a, b, dst) {\n dst = dst || new VecType$2(2);\n dst[0] = a[0] / b[0];\n dst[1] = a[1] / b[1];\n return dst;\n}\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length. (same as divide)\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of quotients of entries of a and b.\n */\nconst div$2 = divide$2;\n/**\n * Creates a random unit vector * scale\n * @param scale - Default 1\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The random vector.\n */\nfunction random$1(scale = 1, dst) {\n dst = dst || new VecType$2(2);\n const angle = Math.random() * 2 * Math.PI;\n dst[0] = Math.cos(angle) * scale;\n dst[1] = Math.sin(angle) * scale;\n return dst;\n}\n/**\n * Zero's a vector\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The zeroed vector.\n */\nfunction zero$2(dst) {\n dst = dst || new VecType$2(2);\n dst[0] = 0;\n dst[1] = 0;\n return dst;\n}\n/**\n * transform Vec2 by 4x4 matrix\n * @param v - the vector\n * @param m - The matrix.\n * @param dst - optional Vec2 to store result. If not passed a new one is created.\n * @returns the transformed vector\n */\nfunction transformMat4$2(v, m, dst) {\n dst = dst || new VecType$2(2);\n const x = v[0];\n const y = v[1];\n dst[0] = x * m[0] + y * m[4] + m[12];\n dst[1] = x * m[1] + y * m[5] + m[13];\n return dst;\n}\n/**\n * Transforms vec4 by 3x3 matrix\n *\n * @param v - the vector\n * @param m - The matrix.\n * @param dst - optional Vec2 to store result. If not passed a new one is created.\n * @returns the transformed vector\n */\nfunction transformMat3$1(v, m, dst) {\n dst = dst || new VecType$2(2);\n const x = v[0];\n const y = v[1];\n dst[0] = m[0] * x + m[4] * y + m[8];\n dst[1] = m[1] * x + m[5] * y + m[9];\n return dst;\n}\n/**\n * Rotate a 2D vector\n *\n * @param a The vec2 point to rotate\n * @param b The origin of the rotation\n * @param rad The angle of rotation in radians\n * @returns the rotated vector\n */\nfunction rotate$2(a, b, rad, dst) {\n dst = dst || new VecType$2(2);\n // Translate point to the origin\n const p0 = a[0] - b[0];\n const p1 = a[1] - b[1];\n const sinC = Math.sin(rad);\n const cosC = Math.cos(rad);\n //perform rotation and translate to correct position\n dst[0] = p0 * cosC - p1 * sinC + b[0];\n dst[1] = p0 * sinC + p1 * cosC + b[1];\n return dst;\n}\n/**\n * Treat a 2D vector as a direction and set it's length\n *\n * @param a The vec2 to lengthen\n * @param len The length of the resulting vector\n * @returns The lengthened vector\n */\nfunction setLength$2(a, len, dst) {\n dst = dst || new VecType$2(2);\n normalize$3(a, dst);\n return mulScalar$3(dst, len, dst);\n}\n/**\n * Ensure a vector is not longer than a max length\n *\n * @param a The vec2 to limit\n * @param maxLen The longest length of the resulting vector\n * @returns The vector, shortened to maxLen if it's too long\n */\nfunction truncate$2(a, maxLen, dst) {\n dst = dst || new VecType$2(2);\n if (length$3(a) > maxLen) {\n return setLength$2(a, maxLen, dst);\n }\n return copy$5(a, dst);\n}\n/**\n * Return the vector exactly between 2 endpoint vectors\n *\n * @param a Endpoint 1\n * @param b Endpoint 2\n * @returns The vector exactly residing between endpoints 1 and 2\n */\nfunction midpoint$2(a, b, dst) {\n dst = dst || new VecType$2(2);\n return lerp$3(a, b, 0.5, dst);\n}\n\nvar vec2Impl = /*#__PURE__*/Object.freeze({\n __proto__: null,\n add: add$3,\n addScaled: addScaled$2,\n angle: angle$2,\n ceil: ceil$2,\n clamp: clamp$2,\n clone: clone$5,\n copy: copy$5,\n create: create$5,\n cross: cross$1,\n dist: dist$2,\n distSq: distSq$2,\n distance: distance$2,\n distanceSq: distanceSq$2,\n div: div$2,\n divScalar: divScalar$3,\n divide: divide$2,\n dot: dot$3,\n equals: equals$5,\n equalsApproximately: equalsApproximately$5,\n floor: floor$2,\n fromValues: fromValues$3,\n inverse: inverse$5,\n invert: invert$4,\n len: len$3,\n lenSq: lenSq$3,\n length: length$3,\n lengthSq: lengthSq$3,\n lerp: lerp$3,\n lerpV: lerpV$2,\n max: max$2,\n midpoint: midpoint$2,\n min: min$2,\n mul: mul$5,\n mulScalar: mulScalar$3,\n multiply: multiply$5,\n negate: negate$4,\n normalize: normalize$3,\n random: random$1,\n rotate: rotate$2,\n round: round$2,\n scale: scale$5,\n set: set$5,\n setDefaultType: setDefaultType$6,\n setLength: setLength$2,\n sub: sub$3,\n subtract: subtract$3,\n transformMat3: transformMat3$1,\n transformMat4: transformMat4$2,\n truncate: truncate$2,\n zero: zero$2\n});\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n * 3x3 Matrix math math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new matrix. In other words you can do this\n *\n * const mat = mat3.translation([1, 2, 3]); // Creates a new translation matrix\n *\n * or\n *\n * const mat = mat3.create();\n * mat3.translation([1, 2, 3], mat); // Puts translation matrix in mat.\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always save to pass any matrix as the destination. So for example\n *\n * const mat = mat3.identity();\n * const trans = mat3.translation([1, 2, 3]);\n * mat3.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat.\n *\n */\nlet MatType$1 = Float32Array;\n// This mess is because with Mat3 we have 3 unused elements.\n// For Float32Array and Float64Array that's not an issue\n// but for Array it's troublesome\nconst ctorMap = new Map([\n [Float32Array, () => new Float32Array(12)],\n [Float64Array, () => new Float64Array(12)],\n [Array, () => new Array(12).fill(0)],\n]);\nlet newMat3 = ctorMap.get(Float32Array);\n/**\n * Sets the type this library creates for a Mat3\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n * @returns previous constructor for Mat3\n */\nfunction setDefaultType$4(ctor) {\n const oldType = MatType$1;\n MatType$1 = ctor;\n newMat3 = ctorMap.get(ctor);\n return oldType;\n}\n/**\n * Create a Mat3 from values\n *\n * Note: Since passing in a raw JavaScript array\n * is valid in all circumstances, if you want to\n * force a JavaScript array into a Mat3's specified type\n * it would be faster to use\n *\n * ```\n * const m = mat3.clone(someJSArray);\n * ```\n *\n * Note: a consequence of the implementation is if your Mat3Type = `Array`\n * instead of `Float32Array` or `Float64Array` then any values you\n * don't pass in will be undefined. Usually this is not an issue since\n * (a) using `Array` is rare and (b) using `mat3.create` is usually used\n * to create a Mat3 to be filled out as in\n *\n * ```\n * const m = mat3.create();\n * mat3.perspective(fov, aspect, near, far, m);\n * ```\n *\n * @param v0 - value for element 0\n * @param v1 - value for element 1\n * @param v2 - value for element 2\n * @param v3 - value for element 3\n * @param v4 - value for element 4\n * @param v5 - value for element 5\n * @param v6 - value for element 6\n * @param v7 - value for element 7\n * @param v8 - value for element 8\n * @returns matrix created from values.\n */\nfunction create$3(v0, v1, v2, v3, v4, v5, v6, v7, v8) {\n const dst = newMat3();\n // to make the array homogenous\n dst[3] = 0;\n dst[7] = 0;\n dst[11] = 0;\n if (v0 !== undefined) {\n dst[0] = v0;\n if (v1 !== undefined) {\n dst[1] = v1;\n if (v2 !== undefined) {\n dst[2] = v2;\n if (v3 !== undefined) {\n dst[4] = v3;\n if (v4 !== undefined) {\n dst[5] = v4;\n if (v5 !== undefined) {\n dst[6] = v5;\n if (v6 !== undefined) {\n dst[8] = v6;\n if (v7 !== undefined) {\n dst[9] = v7;\n if (v8 !== undefined) {\n dst[10] = v8;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return dst;\n}\n/**\n * Sets the values of a Mat3\n * Also see {@link mat3.create} and {@link mat3.copy}\n *\n * @param v0 - value for element 0\n * @param v1 - value for element 1\n * @param v2 - value for element 2\n * @param v3 - value for element 3\n * @param v4 - value for element 4\n * @param v5 - value for element 5\n * @param v6 - value for element 6\n * @param v7 - value for element 7\n * @param v8 - value for element 8\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns Mat3 set from values.\n */\nfunction set$4(v0, v1, v2, v3, v4, v5, v6, v7, v8, dst) {\n dst = dst || newMat3();\n dst[0] = v0;\n dst[1] = v1;\n dst[2] = v2;\n dst[3] = 0;\n dst[4] = v3;\n dst[5] = v4;\n dst[6] = v5;\n dst[7] = 0;\n dst[8] = v6;\n dst[9] = v7;\n dst[10] = v8;\n dst[11] = 0;\n return dst;\n}\n/**\n * Creates a Mat3 from the upper left 3x3 part of a Mat4\n * @param m4 - source matrix\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns Mat3 made from m4\n */\nfunction fromMat4(m4, dst) {\n dst = dst || newMat3();\n dst[0] = m4[0];\n dst[1] = m4[1];\n dst[2] = m4[2];\n dst[3] = 0;\n dst[4] = m4[4];\n dst[5] = m4[5];\n dst[6] = m4[6];\n dst[7] = 0;\n dst[8] = m4[8];\n dst[9] = m4[9];\n dst[10] = m4[10];\n dst[11] = 0;\n return dst;\n}\n/**\n * Creates a Mat3 rotation matrix from a quaternion\n * @param q - quaternion to create matrix from\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns Mat3 made from q\n */\nfunction fromQuat$1(q, dst) {\n dst = dst || newMat3();\n const x = q[0];\n const y = q[1];\n const z = q[2];\n const w = q[3];\n const x2 = x + x;\n const y2 = y + y;\n const z2 = z + z;\n const xx = x * x2;\n const yx = y * x2;\n const yy = y * y2;\n const zx = z * x2;\n const zy = z * y2;\n const zz = z * z2;\n const wx = w * x2;\n const wy = w * y2;\n const wz = w * z2;\n dst[0] = 1 - yy - zz;\n dst[1] = yx + wz;\n dst[2] = zx - wy;\n dst[3] = 0;\n dst[4] = yx - wz;\n dst[5] = 1 - xx - zz;\n dst[6] = zy + wx;\n dst[7] = 0;\n dst[8] = zx + wy;\n dst[9] = zy - wx;\n dst[10] = 1 - xx - yy;\n dst[11] = 0;\n return dst;\n}\n/**\n * Negates a matrix.\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns -m.\n */\nfunction negate$3(m, dst) {\n dst = dst || newMat3();\n dst[0] = -m[0];\n dst[1] = -m[1];\n dst[2] = -m[2];\n dst[4] = -m[4];\n dst[5] = -m[5];\n dst[6] = -m[6];\n dst[8] = -m[8];\n dst[9] = -m[9];\n dst[10] = -m[10];\n return dst;\n}\n/**\n * Copies a matrix. (same as {@link mat3.clone})\n * Also see {@link mat3.create} and {@link mat3.set}\n * @param m - The matrix.\n * @param dst - The matrix. If not passed a new one is created.\n * @returns A copy of m.\n */\nfunction copy$4(m, dst) {\n dst = dst || newMat3();\n dst[0] = m[0];\n dst[1] = m[1];\n dst[2] = m[2];\n dst[4] = m[4];\n dst[5] = m[5];\n dst[6] = m[6];\n dst[8] = m[8];\n dst[9] = m[9];\n dst[10] = m[10];\n return dst;\n}\n/**\n * Copies a matrix (same as {@link mat3.copy})\n * Also see {@link mat3.create} and {@link mat3.set}\n * @param m - The matrix.\n * @param dst - The matrix. If not passed a new one is created.\n * @returns A copy of m.\n */\nconst clone$4 = copy$4;\n/**\n * Check if 2 matrices are approximately equal\n * @param a Operand matrix.\n * @param b Operand matrix.\n * @returns true if matrices are approximately equal\n */\nfunction equalsApproximately$4(a, b) {\n return Math.abs(a[0] - b[0]) < EPSILON &&\n Math.abs(a[1] - b[1]) < EPSILON &&\n Math.abs(a[2] - b[2]) < EPSILON &&\n Math.abs(a[4] - b[4]) < EPSILON &&\n Math.abs(a[5] - b[5]) < EPSILON &&\n Math.abs(a[6] - b[6]) < EPSILON &&\n Math.abs(a[8] - b[8]) < EPSILON &&\n Math.abs(a[9] - b[9]) < EPSILON &&\n Math.abs(a[10] - b[10]) < EPSILON;\n}\n/**\n * Check if 2 matrices are exactly equal\n * @param a Operand matrix.\n * @param b Operand matrix.\n * @returns true if matrices are exactly equal\n */\nfunction equals$4(a, b) {\n return a[0] === b[0] &&\n a[1] === b[1] &&\n a[2] === b[2] &&\n a[4] === b[4] &&\n a[5] === b[5] &&\n a[6] === b[6] &&\n a[8] === b[8] &&\n a[9] === b[9] &&\n a[10] === b[10];\n}\n/**\n * Creates a 3-by-3 identity matrix.\n *\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns A 3-by-3 identity matrix.\n */\nfunction identity$2(dst) {\n dst = dst || newMat3();\n dst[0] = 1;\n dst[1] = 0;\n dst[2] = 0;\n dst[4] = 0;\n dst[5] = 1;\n dst[6] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n return dst;\n}\n/**\n * Takes the transpose of a matrix.\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The transpose of m.\n */\nfunction transpose$1(m, dst) {\n dst = dst || newMat3();\n if (dst === m) {\n let t;\n // 0 1 2\n // 4 5 6\n // 8 9 10\n t = m[1];\n m[1] = m[4];\n m[4] = t;\n t = m[2];\n m[2] = m[8];\n m[8] = t;\n t = m[6];\n m[6] = m[9];\n m[9] = t;\n return dst;\n }\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n dst[0] = m00;\n dst[1] = m10;\n dst[2] = m20;\n dst[4] = m01;\n dst[5] = m11;\n dst[6] = m21;\n dst[8] = m02;\n dst[9] = m12;\n dst[10] = m22;\n return dst;\n}\n/**\n * Computes the inverse of a 3-by-3 matrix.\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The inverse of m.\n */\nfunction inverse$4(m, dst) {\n dst = dst || newMat3();\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const b01 = m22 * m11 - m12 * m21;\n const b11 = -m22 * m10 + m12 * m20;\n const b21 = m21 * m10 - m11 * m20;\n const invDet = 1 / (m00 * b01 + m01 * b11 + m02 * b21);\n dst[0] = b01 * invDet;\n dst[1] = (-m22 * m01 + m02 * m21) * invDet;\n dst[2] = (m12 * m01 - m02 * m11) * invDet;\n dst[4] = b11 * invDet;\n dst[5] = (m22 * m00 - m02 * m20) * invDet;\n dst[6] = (-m12 * m00 + m02 * m10) * invDet;\n dst[8] = b21 * invDet;\n dst[9] = (-m21 * m00 + m01 * m20) * invDet;\n dst[10] = (m11 * m00 - m01 * m10) * invDet;\n return dst;\n}\n/**\n * Compute the determinant of a matrix\n * @param m - the matrix\n * @returns the determinant\n */\nfunction determinant$1(m) {\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n return m00 * (m11 * m22 - m21 * m12) -\n m10 * (m01 * m22 - m21 * m02) +\n m20 * (m01 * m12 - m11 * m02);\n}\n/**\n * Computes the inverse of a 3-by-3 matrix. (same as inverse)\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The inverse of m.\n */\nconst invert$3 = inverse$4;\n/**\n * Multiplies two 3-by-3 matrices with a on the left and b on the right\n * @param a - The matrix on the left.\n * @param b - The matrix on the right.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The matrix product of a and b.\n */\nfunction multiply$4(a, b, dst) {\n dst = dst || newMat3();\n const a00 = a[0];\n const a01 = a[1];\n const a02 = a[2];\n const a10 = a[4 + 0];\n const a11 = a[4 + 1];\n const a12 = a[4 + 2];\n const a20 = a[8 + 0];\n const a21 = a[8 + 1];\n const a22 = a[8 + 2];\n const b00 = b[0];\n const b01 = b[1];\n const b02 = b[2];\n const b10 = b[4 + 0];\n const b11 = b[4 + 1];\n const b12 = b[4 + 2];\n const b20 = b[8 + 0];\n const b21 = b[8 + 1];\n const b22 = b[8 + 2];\n dst[0] = a00 * b00 + a10 * b01 + a20 * b02;\n dst[1] = a01 * b00 + a11 * b01 + a21 * b02;\n dst[2] = a02 * b00 + a12 * b01 + a22 * b02;\n dst[4] = a00 * b10 + a10 * b11 + a20 * b12;\n dst[5] = a01 * b10 + a11 * b11 + a21 * b12;\n dst[6] = a02 * b10 + a12 * b11 + a22 * b12;\n dst[8] = a00 * b20 + a10 * b21 + a20 * b22;\n dst[9] = a01 * b20 + a11 * b21 + a21 * b22;\n dst[10] = a02 * b20 + a12 * b21 + a22 * b22;\n return dst;\n}\n/**\n * Multiplies two 3-by-3 matrices with a on the left and b on the right (same as multiply)\n * @param a - The matrix on the left.\n * @param b - The matrix on the right.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The matrix product of a and b.\n */\nconst mul$4 = multiply$4;\n/**\n * Sets the translation component of a 3-by-3 matrix to the given\n * vector.\n * @param a - The matrix.\n * @param v - The vector.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The matrix with translation set.\n */\nfunction setTranslation$1(a, v, dst) {\n dst = dst || identity$2();\n if (a !== dst) {\n dst[0] = a[0];\n dst[1] = a[1];\n dst[2] = a[2];\n dst[4] = a[4];\n dst[5] = a[5];\n dst[6] = a[6];\n }\n dst[8] = v[0];\n dst[9] = v[1];\n dst[10] = 1;\n return dst;\n}\n/**\n * Returns the translation component of a 3-by-3 matrix as a vector with 3\n * entries.\n * @param m - The matrix.\n * @param dst - vector to hold result. If not passed a new one is created.\n * @returns The translation component of m.\n */\nfunction getTranslation$2(m, dst) {\n dst = dst || create$5();\n dst[0] = m[8];\n dst[1] = m[9];\n return dst;\n}\n/**\n * Returns an axis of a 3x3 matrix as a vector with 2 entries\n * @param m - The matrix.\n * @param axis - The axis 0 = x, 1 = y,\n * @returns The axis component of m.\n */\nfunction getAxis$2(m, axis, dst) {\n dst = dst || create$5();\n const off = axis * 4;\n dst[0] = m[off + 0];\n dst[1] = m[off + 1];\n return dst;\n}\n/**\n * Sets an axis of a 3x3 matrix as a vector with 2 entries\n * @param m - The matrix.\n * @param v - the axis vector\n * @param axis - The axis 0 = x, 1 = y;\n * @param dst - The matrix to set. If not passed a new one is created.\n * @returns The matrix with axis set.\n */\nfunction setAxis$1(m, v, axis, dst) {\n if (dst !== m) {\n dst = copy$4(m, dst);\n }\n const off = axis * 4;\n dst[off + 0] = v[0];\n dst[off + 1] = v[1];\n return dst;\n}\n/**\n * Returns the scaling component of the matrix\n * @param m - The Matrix\n * @param dst - The vector to set. If not passed a new one is created.\n */\nfunction getScaling$2(m, dst) {\n dst = dst || create$5();\n const xx = m[0];\n const xy = m[1];\n const yx = m[4];\n const yy = m[5];\n dst[0] = Math.sqrt(xx * xx + xy * xy);\n dst[1] = Math.sqrt(yx * yx + yy * yy);\n return dst;\n}\n/**\n * Creates a 3-by-3 matrix which translates by the given vector v.\n * @param v - The vector by which to translate.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The translation matrix.\n */\nfunction translation$1(v, dst) {\n dst = dst || newMat3();\n dst[0] = 1;\n dst[1] = 0;\n dst[2] = 0;\n dst[4] = 0;\n dst[5] = 1;\n dst[6] = 0;\n dst[8] = v[0];\n dst[9] = v[1];\n dst[10] = 1;\n return dst;\n}\n/**\n * Translates the given 3-by-3 matrix by the given vector v.\n * @param m - The matrix.\n * @param v - The vector by which to translate.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The translated matrix.\n */\nfunction translate$1(m, v, dst) {\n dst = dst || newMat3();\n const v0 = v[0];\n const v1 = v[1];\n const m00 = m[0];\n const m01 = m[1];\n const m02 = m[2];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n if (m !== dst) {\n dst[0] = m00;\n dst[1] = m01;\n dst[2] = m02;\n dst[4] = m10;\n dst[5] = m11;\n dst[6] = m12;\n }\n dst[8] = m00 * v0 + m10 * v1 + m20;\n dst[9] = m01 * v0 + m11 * v1 + m21;\n dst[10] = m02 * v0 + m12 * v1 + m22;\n return dst;\n}\n/**\n * Creates a 3-by-3 matrix which rotates by the given angle.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotation matrix.\n */\nfunction rotation$1(angleInRadians, dst) {\n dst = dst || newMat3();\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = c;\n dst[1] = s;\n dst[2] = 0;\n dst[4] = -s;\n dst[5] = c;\n dst[6] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n return dst;\n}\n/**\n * Rotates the given 3-by-3 matrix by the given angle.\n * @param m - The matrix.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotated matrix.\n */\nfunction rotate$1(m, angleInRadians, dst) {\n dst = dst || newMat3();\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = c * m00 + s * m10;\n dst[1] = c * m01 + s * m11;\n dst[2] = c * m02 + s * m12;\n dst[4] = c * m10 - s * m00;\n dst[5] = c * m11 - s * m01;\n dst[6] = c * m12 - s * m02;\n if (m !== dst) {\n dst[8] = m[8];\n dst[9] = m[9];\n dst[10] = m[10];\n }\n return dst;\n}\n/**\n * Creates a 3-by-3 matrix which scales in each dimension by an amount given by\n * the corresponding entry in the given vector; assumes the vector has three\n * entries.\n * @param v - A vector of\n * 2 entries specifying the factor by which to scale in each dimension.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaling matrix.\n */\nfunction scaling$1(v, dst) {\n dst = dst || newMat3();\n dst[0] = v[0];\n dst[1] = 0;\n dst[2] = 0;\n dst[4] = 0;\n dst[5] = v[1];\n dst[6] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n return dst;\n}\n/**\n * Scales the given 3-by-3 matrix in each dimension by an amount\n * given by the corresponding entry in the given vector; assumes the vector has\n * three entries.\n * @param m - The matrix to be modified.\n * @param v - A vector of 2 entries specifying the\n * factor by which to scale in each dimension.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaled matrix.\n */\nfunction scale$4(m, v, dst) {\n dst = dst || newMat3();\n const v0 = v[0];\n const v1 = v[1];\n dst[0] = v0 * m[0 * 4 + 0];\n dst[1] = v0 * m[0 * 4 + 1];\n dst[2] = v0 * m[0 * 4 + 2];\n dst[4] = v1 * m[1 * 4 + 0];\n dst[5] = v1 * m[1 * 4 + 1];\n dst[6] = v1 * m[1 * 4 + 2];\n if (m !== dst) {\n dst[8] = m[8];\n dst[9] = m[9];\n dst[10] = m[10];\n }\n return dst;\n}\n/**\n * Creates a 3-by-3 matrix which scales uniformly in each dimension\n * @param s - Amount to scale\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaling matrix.\n */\nfunction uniformScaling$1(s, dst) {\n dst = dst || newMat3();\n dst[0] = s;\n dst[1] = 0;\n dst[2] = 0;\n dst[4] = 0;\n dst[5] = s;\n dst[6] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n return dst;\n}\n/**\n * Scales the given 3-by-3 matrix in each dimension by an amount\n * given.\n * @param m - The matrix to be modified.\n * @param s - Amount to scale.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaled matrix.\n */\nfunction uniformScale$1(m, s, dst) {\n dst = dst || newMat3();\n dst[0] = s * m[0 * 4 + 0];\n dst[1] = s * m[0 * 4 + 1];\n dst[2] = s * m[0 * 4 + 2];\n dst[4] = s * m[1 * 4 + 0];\n dst[5] = s * m[1 * 4 + 1];\n dst[6] = s * m[1 * 4 + 2];\n if (m !== dst) {\n dst[8] = m[8];\n dst[9] = m[9];\n dst[10] = m[10];\n }\n return dst;\n}\n\nvar mat3Impl = /*#__PURE__*/Object.freeze({\n __proto__: null,\n clone: clone$4,\n copy: copy$4,\n create: create$3,\n determinant: determinant$1,\n equals: equals$4,\n equalsApproximately: equalsApproximately$4,\n fromMat4: fromMat4,\n fromQuat: fromQuat$1,\n getAxis: getAxis$2,\n getScaling: getScaling$2,\n getTranslation: getTranslation$2,\n identity: identity$2,\n inverse: inverse$4,\n invert: invert$3,\n mul: mul$4,\n multiply: multiply$4,\n negate: negate$3,\n rotate: rotate$1,\n rotation: rotation$1,\n scale: scale$4,\n scaling: scaling$1,\n set: set$4,\n setAxis: setAxis$1,\n setDefaultType: setDefaultType$4,\n setTranslation: setTranslation$1,\n translate: translate$1,\n translation: translation$1,\n transpose: transpose$1,\n uniformScale: uniformScale$1,\n uniformScaling: uniformScaling$1\n});\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n * Creates a vec3; may be called with x, y, z to set initial values. (same as create)\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @param z - Initial z value.\n * @returns the created vector\n */\nconst fromValues$2 = create$4;\n/**\n * Sets the values of a Vec3\n * Also see {@link vec3.create} and {@link vec3.copy}\n *\n * @param x first value\n * @param y second value\n * @param z third value\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector with its elements set.\n */\nfunction set$3(x, y, z, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = x;\n dst[1] = y;\n dst[2] = z;\n return dst;\n}\n/**\n * Applies Math.ceil to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the ceil of each element of v.\n */\nfunction ceil$1(v, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = Math.ceil(v[0]);\n dst[1] = Math.ceil(v[1]);\n dst[2] = Math.ceil(v[2]);\n return dst;\n}\n/**\n * Applies Math.floor to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the floor of each element of v.\n */\nfunction floor$1(v, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = Math.floor(v[0]);\n dst[1] = Math.floor(v[1]);\n dst[2] = Math.floor(v[2]);\n return dst;\n}\n/**\n * Applies Math.round to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the round of each element of v.\n */\nfunction round$1(v, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = Math.round(v[0]);\n dst[1] = Math.round(v[1]);\n dst[2] = Math.round(v[2]);\n return dst;\n}\n/**\n * Clamp each element of vector between min and max\n * @param v - Operand vector.\n * @param max - Min value, default 0\n * @param min - Max value, default 1\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that the clamped value of each element of v.\n */\nfunction clamp$1(v, min = 0, max = 1, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = Math.min(max, Math.max(min, v[0]));\n dst[1] = Math.min(max, Math.max(min, v[1]));\n dst[2] = Math.min(max, Math.max(min, v[2]));\n return dst;\n}\n/**\n * Adds two vectors; assumes a and b have the same dimension.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the sum of a and b.\n */\nfunction add$2(a, b, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] + b[0];\n dst[1] = a[1] + b[1];\n dst[2] = a[2] + b[2];\n return dst;\n}\n/**\n * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param scale - Amount to scale b\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the sum of a + b * scale.\n */\nfunction addScaled$1(a, b, scale, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] + b[0] * scale;\n dst[1] = a[1] + b[1] * scale;\n dst[2] = a[2] + b[2] * scale;\n return dst;\n}\n/**\n * Returns the angle in radians between two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns The angle in radians between the 2 vectors.\n */\nfunction angle$1(a, b) {\n const ax = a[0];\n const ay = a[1];\n const az = a[2];\n const bx = a[0];\n const by = a[1];\n const bz = a[2];\n const mag1 = Math.sqrt(ax * ax + ay * ay + az * az);\n const mag2 = Math.sqrt(bx * bx + by * by + bz * bz);\n const mag = mag1 * mag2;\n const cosine = mag && dot$2(a, b) / mag;\n return Math.acos(cosine);\n}\n/**\n * Subtracts two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the difference of a and b.\n */\nfunction subtract$2(a, b, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] - b[0];\n dst[1] = a[1] - b[1];\n dst[2] = a[2] - b[2];\n return dst;\n}\n/**\n * Subtracts two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the difference of a and b.\n */\nconst sub$2 = subtract$2;\n/**\n * Check if 2 vectors are approximately equal\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns true if vectors are approximately equal\n */\nfunction equalsApproximately$3(a, b) {\n return Math.abs(a[0] - b[0]) < EPSILON &&\n Math.abs(a[1] - b[1]) < EPSILON &&\n Math.abs(a[2] - b[2]) < EPSILON;\n}\n/**\n * Check if 2 vectors are exactly equal\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns true if vectors are exactly equal\n */\nfunction equals$3(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];\n}\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient t, returns\n * a + t * (b - a).\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param t - Interpolation coefficient.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The linear interpolated result.\n */\nfunction lerp$2(a, b, t, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] + t * (b[0] - a[0]);\n dst[1] = a[1] + t * (b[1] - a[1]);\n dst[2] = a[2] + t * (b[2] - a[2]);\n return dst;\n}\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient vector t, returns\n * a + t * (b - a).\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param t - Interpolation coefficients vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns the linear interpolated result.\n */\nfunction lerpV$1(a, b, t, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] + t[0] * (b[0] - a[0]);\n dst[1] = a[1] + t[1] * (b[1] - a[1]);\n dst[2] = a[2] + t[2] * (b[2] - a[2]);\n return dst;\n}\n/**\n * Return max values of two vectors.\n * Given vectors a and b returns\n * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The max components vector.\n */\nfunction max$1(a, b, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = Math.max(a[0], b[0]);\n dst[1] = Math.max(a[1], b[1]);\n dst[2] = Math.max(a[2], b[2]);\n return dst;\n}\n/**\n * Return min values of two vectors.\n * Given vectors a and b returns\n * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The min components vector.\n */\nfunction min$1(a, b, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = Math.min(a[0], b[0]);\n dst[1] = Math.min(a[1], b[1]);\n dst[2] = Math.min(a[2], b[2]);\n return dst;\n}\n/**\n * Multiplies a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nfunction mulScalar$2(v, k, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = v[0] * k;\n dst[1] = v[1] * k;\n dst[2] = v[2] * k;\n return dst;\n}\n/**\n * Multiplies a vector by a scalar. (same as mulScalar)\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nconst scale$3 = mulScalar$2;\n/**\n * Divides a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nfunction divScalar$2(v, k, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = v[0] / k;\n dst[1] = v[1] / k;\n dst[2] = v[2] / k;\n return dst;\n}\n/**\n * Inverse a vector.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The inverted vector.\n */\nfunction inverse$3(v, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = 1 / v[0];\n dst[1] = 1 / v[1];\n dst[2] = 1 / v[2];\n return dst;\n}\n/**\n * Invert a vector. (same as inverse)\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The inverted vector.\n */\nconst invert$2 = inverse$3;\n/**\n * Computes the cross product of two vectors; assumes both vectors have\n * three entries.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of a cross b.\n */\nfunction cross(a, b, dst) {\n dst = dst || new VecType$1(3);\n const t1 = a[2] * b[0] - a[0] * b[2];\n const t2 = a[0] * b[1] - a[1] * b[0];\n dst[0] = a[1] * b[2] - a[2] * b[1];\n dst[1] = t1;\n dst[2] = t2;\n return dst;\n}\n/**\n * Computes the dot product of two vectors; assumes both vectors have\n * three entries.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns dot product\n */\nfunction dot$2(a, b) {\n return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]);\n}\n/**\n * Computes the length of vector\n * @param v - vector.\n * @returns length of vector.\n */\nfunction length$2(v) {\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2);\n}\n/**\n * Computes the length of vector (same as length)\n * @param v - vector.\n * @returns length of vector.\n */\nconst len$2 = length$2;\n/**\n * Computes the square of the length of vector\n * @param v - vector.\n * @returns square of the length of vector.\n */\nfunction lengthSq$2(v) {\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n return v0 * v0 + v1 * v1 + v2 * v2;\n}\n/**\n * Computes the square of the length of vector (same as lengthSq)\n * @param v - vector.\n * @returns square of the length of vector.\n */\nconst lenSq$2 = lengthSq$2;\n/**\n * Computes the distance between 2 points\n * @param a - vector.\n * @param b - vector.\n * @returns distance between a and b\n */\nfunction distance$1(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n const dz = a[2] - b[2];\n return Math.sqrt(dx * dx + dy * dy + dz * dz);\n}\n/**\n * Computes the distance between 2 points (same as distance)\n * @param a - vector.\n * @param b - vector.\n * @returns distance between a and b\n */\nconst dist$1 = distance$1;\n/**\n * Computes the square of the distance between 2 points\n * @param a - vector.\n * @param b - vector.\n * @returns square of the distance between a and b\n */\nfunction distanceSq$1(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n const dz = a[2] - b[2];\n return dx * dx + dy * dy + dz * dz;\n}\n/**\n * Computes the square of the distance between 2 points (same as distanceSq)\n * @param a - vector.\n * @param b - vector.\n * @returns square of the distance between a and b\n */\nconst distSq$1 = distanceSq$1;\n/**\n * Divides a vector by its Euclidean length and returns the quotient.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The normalized vector.\n */\nfunction normalize$2(v, dst) {\n dst = dst || new VecType$1(3);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2);\n if (len > 0.00001) {\n dst[0] = v0 / len;\n dst[1] = v1 / len;\n dst[2] = v2 / len;\n }\n else {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n }\n return dst;\n}\n/**\n * Negates a vector.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns -v.\n */\nfunction negate$2(v, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = -v[0];\n dst[1] = -v[1];\n dst[2] = -v[2];\n return dst;\n}\n/**\n * Copies a vector. (same as {@link vec3.clone})\n * Also see {@link vec3.create} and {@link vec3.set}\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A copy of v.\n */\nfunction copy$3(v, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = v[0];\n dst[1] = v[1];\n dst[2] = v[2];\n return dst;\n}\n/**\n * Clones a vector. (same as {@link vec3.copy})\n * Also see {@link vec3.create} and {@link vec3.set}\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A copy of v.\n */\nconst clone$3 = copy$3;\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of products of entries of a and b.\n */\nfunction multiply$3(a, b, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] * b[0];\n dst[1] = a[1] * b[1];\n dst[2] = a[2] * b[2];\n return dst;\n}\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length. (same as mul)\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of products of entries of a and b.\n */\nconst mul$3 = multiply$3;\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of quotients of entries of a and b.\n */\nfunction divide$1(a, b, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = a[0] / b[0];\n dst[1] = a[1] / b[1];\n dst[2] = a[2] / b[2];\n return dst;\n}\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length. (same as divide)\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of quotients of entries of a and b.\n */\nconst div$1 = divide$1;\n/**\n * Creates a random vector\n * @param scale - Default 1\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The random vector.\n */\nfunction random(scale = 1, dst) {\n dst = dst || new VecType$1(3);\n const angle = Math.random() * 2 * Math.PI;\n const z = Math.random() * 2 - 1;\n const zScale = Math.sqrt(1 - z * z) * scale;\n dst[0] = Math.cos(angle) * zScale;\n dst[1] = Math.sin(angle) * zScale;\n dst[2] = z * scale;\n return dst;\n}\n/**\n * Zero's a vector\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The zeroed vector.\n */\nfunction zero$1(dst) {\n dst = dst || new VecType$1(3);\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n return dst;\n}\n/**\n * transform vec3 by 4x4 matrix\n * @param v - the vector\n * @param m - The matrix.\n * @param dst - optional vec3 to store result. If not passed a new one is created.\n * @returns the transformed vector\n */\nfunction transformMat4$1(v, m, dst) {\n dst = dst || new VecType$1(3);\n const x = v[0];\n const y = v[1];\n const z = v[2];\n const w = (m[3] * x + m[7] * y + m[11] * z + m[15]) || 1;\n dst[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;\n dst[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;\n dst[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;\n return dst;\n}\n/**\n * Transform vec4 by upper 3x3 matrix inside 4x4 matrix.\n * @param v - The direction.\n * @param m - The matrix.\n * @param dst - optional Vec3 to store result. If not passed a new one is created.\n * @returns The transformed vector.\n */\nfunction transformMat4Upper3x3(v, m, dst) {\n dst = dst || new VecType$1(3);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];\n dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];\n dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];\n return dst;\n}\n/**\n * Transforms vec3 by 3x3 matrix\n *\n * @param v - the vector\n * @param m - The matrix.\n * @param dst - optional vec3 to store result. If not passed a new one is created.\n * @returns the transformed vector\n */\nfunction transformMat3(v, m, dst) {\n dst = dst || new VecType$1(3);\n const x = v[0];\n const y = v[1];\n const z = v[2];\n dst[0] = x * m[0] + y * m[4] + z * m[8];\n dst[1] = x * m[1] + y * m[5] + z * m[9];\n dst[2] = x * m[2] + y * m[6] + z * m[10];\n return dst;\n}\n/**\n * Transforms vec3 by Quaternion\n * @param v - the vector to transform\n * @param q - the quaternion to transform by\n * @param dst - optional vec3 to store result. If not passed a new one is created.\n * @returns the transformed\n */\nfunction transformQuat(v, q, dst) {\n dst = dst || new VecType$1(3);\n const qx = q[0];\n const qy = q[1];\n const qz = q[2];\n const w2 = q[3] * 2;\n const x = v[0];\n const y = v[1];\n const z = v[2];\n const uvX = qy * z - qz * y;\n const uvY = qz * x - qx * z;\n const uvZ = qx * y - qy * x;\n dst[0] = x + uvX * w2 + (qy * uvZ - qz * uvY) * 2;\n dst[1] = y + uvY * w2 + (qz * uvX - qx * uvZ) * 2;\n dst[2] = z + uvZ * w2 + (qx * uvY - qy * uvX) * 2;\n return dst;\n}\n/**\n * Returns the translation component of a 4-by-4 matrix as a vector with 3\n * entries.\n * @param m - The matrix.\n * @param dst - vector to hold result. If not passed a new one is created.\n * @returns The translation component of m.\n */\nfunction getTranslation$1(m, dst) {\n dst = dst || new VecType$1(3);\n dst[0] = m[12];\n dst[1] = m[13];\n dst[2] = m[14];\n return dst;\n}\n/**\n * Returns an axis of a 4x4 matrix as a vector with 3 entries\n * @param m - The matrix.\n * @param axis - The axis 0 = x, 1 = y, 2 = z;\n * @returns The axis component of m.\n */\nfunction getAxis$1(m, axis, dst) {\n dst = dst || new VecType$1(3);\n const off = axis * 4;\n dst[0] = m[off + 0];\n dst[1] = m[off + 1];\n dst[2] = m[off + 2];\n return dst;\n}\n/**\n * Returns the scaling component of the matrix\n * @param m - The Matrix\n * @param dst - The vector to set. If not passed a new one is created.\n */\nfunction getScaling$1(m, dst) {\n dst = dst || new VecType$1(3);\n const xx = m[0];\n const xy = m[1];\n const xz = m[2];\n const yx = m[4];\n const yy = m[5];\n const yz = m[6];\n const zx = m[8];\n const zy = m[9];\n const zz = m[10];\n dst[0] = Math.sqrt(xx * xx + xy * xy + xz * xz);\n dst[1] = Math.sqrt(yx * yx + yy * yy + yz * yz);\n dst[2] = Math.sqrt(zx * zx + zy * zy + zz * zz);\n return dst;\n}\n/**\n * Rotate a 3D vector around the x-axis\n *\n * @param {ReadonlyVec3} a The vec3 point to rotate\n * @param {ReadonlyVec3} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @param dst - The vector to set. If not passed a new one is created.\n * @returns the rotated vector\n */\nfunction rotateX$2(a, b, rad, dst) {\n dst = dst || new VecType$1(3);\n const p = [];\n const r = [];\n //Translate point to the origin\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2];\n //perform rotation\n r[0] = p[0];\n r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);\n r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);\n //translate to correct position\n dst[0] = r[0] + b[0];\n dst[1] = r[1] + b[1];\n dst[2] = r[2] + b[2];\n return dst;\n}\n/**\n * Rotate a 3D vector around the y-axis\n *\n * @param {ReadonlyVec3} a The vec3 point to rotate\n * @param {ReadonlyVec3} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @param dst - The vector to set. If not passed a new one is created.\n * @returns the rotated vector\n */\nfunction rotateY$2(a, b, rad, dst) {\n dst = dst || new VecType$1(3);\n const p = [];\n const r = [];\n // translate point to the origin\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2];\n // perform rotation\n r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);\n r[1] = p[1];\n r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);\n // translate to correct position\n dst[0] = r[0] + b[0];\n dst[1] = r[1] + b[1];\n dst[2] = r[2] + b[2];\n return dst;\n}\n/**\n * Rotate a 3D vector around the z-axis\n *\n * @param {ReadonlyVec3} a The vec3 point to rotate\n * @param {ReadonlyVec3} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @param dst - The vector to set. If not passed a new one is created.\n * @returns {vec3} out\n */\nfunction rotateZ$2(a, b, rad, dst) {\n dst = dst || new VecType$1(3);\n const p = [];\n const r = [];\n // translate point to the origin\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2];\n // perform rotation\n r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);\n r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);\n r[2] = p[2];\n // translate to correct position\n dst[0] = r[0] + b[0];\n dst[1] = r[1] + b[1];\n dst[2] = r[2] + b[2];\n return dst;\n}\n/**\n * Treat a 3D vector as a direction and set it's length\n *\n * @param a The vec3 to lengthen\n * @param len The length of the resulting vector\n * @returns The lengthened vector\n */\nfunction setLength$1(a, len, dst) {\n dst = dst || new VecType$1(3);\n normalize$2(a, dst);\n return mulScalar$2(dst, len, dst);\n}\n/**\n * Ensure a vector is not longer than a max length\n *\n * @param a The vec3 to limit\n * @param maxLen The longest length of the resulting vector\n * @returns The vector, shortened to maxLen if it's too long\n */\nfunction truncate$1(a, maxLen, dst) {\n dst = dst || new VecType$1(3);\n if (length$2(a) > maxLen) {\n return setLength$1(a, maxLen, dst);\n }\n return copy$3(a, dst);\n}\n/**\n * Return the vector exactly between 2 endpoint vectors\n *\n * @param a Endpoint 1\n * @param b Endpoint 2\n * @returns The vector exactly residing between endpoints 1 and 2\n */\nfunction midpoint$1(a, b, dst) {\n dst = dst || new VecType$1(3);\n return lerp$2(a, b, 0.5, dst);\n}\n\nvar vec3Impl = /*#__PURE__*/Object.freeze({\n __proto__: null,\n add: add$2,\n addScaled: addScaled$1,\n angle: angle$1,\n ceil: ceil$1,\n clamp: clamp$1,\n clone: clone$3,\n copy: copy$3,\n create: create$4,\n cross: cross,\n dist: dist$1,\n distSq: distSq$1,\n distance: distance$1,\n distanceSq: distanceSq$1,\n div: div$1,\n divScalar: divScalar$2,\n divide: divide$1,\n dot: dot$2,\n equals: equals$3,\n equalsApproximately: equalsApproximately$3,\n floor: floor$1,\n fromValues: fromValues$2,\n getAxis: getAxis$1,\n getScaling: getScaling$1,\n getTranslation: getTranslation$1,\n inverse: inverse$3,\n invert: invert$2,\n len: len$2,\n lenSq: lenSq$2,\n length: length$2,\n lengthSq: lengthSq$2,\n lerp: lerp$2,\n lerpV: lerpV$1,\n max: max$1,\n midpoint: midpoint$1,\n min: min$1,\n mul: mul$3,\n mulScalar: mulScalar$2,\n multiply: multiply$3,\n negate: negate$2,\n normalize: normalize$2,\n random: random,\n rotateX: rotateX$2,\n rotateY: rotateY$2,\n rotateZ: rotateZ$2,\n round: round$1,\n scale: scale$3,\n set: set$3,\n setDefaultType: setDefaultType$5,\n setLength: setLength$1,\n sub: sub$2,\n subtract: subtract$2,\n transformMat3: transformMat3,\n transformMat4: transformMat4$1,\n transformMat4Upper3x3: transformMat4Upper3x3,\n transformQuat: transformQuat,\n truncate: truncate$1,\n zero: zero$1\n});\n\n/**\n * 4x4 Matrix math math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new matrix. In other words you can do this\n *\n * const mat = mat4.translation([1, 2, 3]); // Creates a new translation matrix\n *\n * or\n *\n * const mat = mat4.create();\n * mat4.translation([1, 2, 3], mat); // Puts translation matrix in mat.\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always save to pass any matrix as the destination. So for example\n *\n * const mat = mat4.identity();\n * const trans = mat4.translation([1, 2, 3]);\n * mat4.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat.\n *\n */\nlet MatType = Float32Array;\n/**\n * Sets the type this library creates for a Mat4\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n * @returns previous constructor for Mat4\n */\nfunction setDefaultType$3(ctor) {\n const oldType = MatType;\n MatType = ctor;\n return oldType;\n}\n/**\n * Create a Mat4 from values\n *\n * Note: Since passing in a raw JavaScript array\n * is valid in all circumstances, if you want to\n * force a JavaScript array into a Mat4's specified type\n * it would be faster to use\n *\n * ```\n * const m = mat4.clone(someJSArray);\n * ```\n *\n * Note: a consequence of the implementation is if your Mat4Type = `Array`\n * instead of `Float32Array` or `Float64Array` then any values you\n * don't pass in will be undefined. Usually this is not an issue since\n * (a) using `Array` is rare and (b) using `mat4.create` is usually used\n * to create a Mat4 to be filled out as in\n *\n * ```\n * const m = mat4.create();\n * mat4.perspective(fov, aspect, near, far, m);\n * ```\n *\n * @param v0 - value for element 0\n * @param v1 - value for element 1\n * @param v2 - value for element 2\n * @param v3 - value for element 3\n * @param v4 - value for element 4\n * @param v5 - value for element 5\n * @param v6 - value for element 6\n * @param v7 - value for element 7\n * @param v8 - value for element 8\n * @param v9 - value for element 9\n * @param v10 - value for element 10\n * @param v11 - value for element 11\n * @param v12 - value for element 12\n * @param v13 - value for element 13\n * @param v14 - value for element 14\n * @param v15 - value for element 15\n * @returns created from values.\n */\nfunction create$2(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {\n const dst = new MatType(16);\n if (v0 !== undefined) {\n dst[0] = v0;\n if (v1 !== undefined) {\n dst[1] = v1;\n if (v2 !== undefined) {\n dst[2] = v2;\n if (v3 !== undefined) {\n dst[3] = v3;\n if (v4 !== undefined) {\n dst[4] = v4;\n if (v5 !== undefined) {\n dst[5] = v5;\n if (v6 !== undefined) {\n dst[6] = v6;\n if (v7 !== undefined) {\n dst[7] = v7;\n if (v8 !== undefined) {\n dst[8] = v8;\n if (v9 !== undefined) {\n dst[9] = v9;\n if (v10 !== undefined) {\n dst[10] = v10;\n if (v11 !== undefined) {\n dst[11] = v11;\n if (v12 !== undefined) {\n dst[12] = v12;\n if (v13 !== undefined) {\n dst[13] = v13;\n if (v14 !== undefined) {\n dst[14] = v14;\n if (v15 !== undefined) {\n dst[15] = v15;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return dst;\n}\n/**\n * Sets the values of a Mat4\n * Also see {@link mat4.create} and {@link mat4.copy}\n *\n * @param v0 - value for element 0\n * @param v1 - value for element 1\n * @param v2 - value for element 2\n * @param v3 - value for element 3\n * @param v4 - value for element 4\n * @param v5 - value for element 5\n * @param v6 - value for element 6\n * @param v7 - value for element 7\n * @param v8 - value for element 8\n * @param v9 - value for element 9\n * @param v10 - value for element 10\n * @param v11 - value for element 11\n * @param v12 - value for element 12\n * @param v13 - value for element 13\n * @param v14 - value for element 14\n * @param v15 - value for element 15\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns Mat4 created from values.\n */\nfunction set$2(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, dst) {\n dst = dst || new MatType(16);\n dst[0] = v0;\n dst[1] = v1;\n dst[2] = v2;\n dst[3] = v3;\n dst[4] = v4;\n dst[5] = v5;\n dst[6] = v6;\n dst[7] = v7;\n dst[8] = v8;\n dst[9] = v9;\n dst[10] = v10;\n dst[11] = v11;\n dst[12] = v12;\n dst[13] = v13;\n dst[14] = v14;\n dst[15] = v15;\n return dst;\n}\n/**\n * Creates a Mat4 from a Mat3\n * @param m3 - source matrix\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns Mat4 made from m3\n */\nfunction fromMat3(m3, dst) {\n dst = dst || new MatType(16);\n dst[0] = m3[0];\n dst[1] = m3[1];\n dst[2] = m3[2];\n dst[3] = 0;\n dst[4] = m3[4];\n dst[5] = m3[5];\n dst[6] = m3[6];\n dst[7] = 0;\n dst[8] = m3[8];\n dst[9] = m3[9];\n dst[10] = m3[10];\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Creates a Mat4 rotation matrix from a quaternion\n * @param q - quaternion to create matrix from\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns Mat4 made from q\n */\nfunction fromQuat(q, dst) {\n dst = dst || new MatType(16);\n const x = q[0];\n const y = q[1];\n const z = q[2];\n const w = q[3];\n const x2 = x + x;\n const y2 = y + y;\n const z2 = z + z;\n const xx = x * x2;\n const yx = y * x2;\n const yy = y * y2;\n const zx = z * x2;\n const zy = z * y2;\n const zz = z * z2;\n const wx = w * x2;\n const wy = w * y2;\n const wz = w * z2;\n dst[0] = 1 - yy - zz;\n dst[1] = yx + wz;\n dst[2] = zx - wy;\n dst[3] = 0;\n dst[4] = yx - wz;\n dst[5] = 1 - xx - zz;\n dst[6] = zy + wx;\n dst[7] = 0;\n dst[8] = zx + wy;\n dst[9] = zy - wx;\n dst[10] = 1 - xx - yy;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Negates a matrix.\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns -m.\n */\nfunction negate$1(m, dst) {\n dst = dst || new MatType(16);\n dst[0] = -m[0];\n dst[1] = -m[1];\n dst[2] = -m[2];\n dst[3] = -m[3];\n dst[4] = -m[4];\n dst[5] = -m[5];\n dst[6] = -m[6];\n dst[7] = -m[7];\n dst[8] = -m[8];\n dst[9] = -m[9];\n dst[10] = -m[10];\n dst[11] = -m[11];\n dst[12] = -m[12];\n dst[13] = -m[13];\n dst[14] = -m[14];\n dst[15] = -m[15];\n return dst;\n}\n/**\n * Copies a matrix. (same as {@link mat4.clone})\n * Also see {@link mat4.create} and {@link mat4.set}\n * @param m - The matrix.\n * @param dst - The matrix. If not passed a new one is created.\n * @returns A copy of m.\n */\nfunction copy$2(m, dst) {\n dst = dst || new MatType(16);\n dst[0] = m[0];\n dst[1] = m[1];\n dst[2] = m[2];\n dst[3] = m[3];\n dst[4] = m[4];\n dst[5] = m[5];\n dst[6] = m[6];\n dst[7] = m[7];\n dst[8] = m[8];\n dst[9] = m[9];\n dst[10] = m[10];\n dst[11] = m[11];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n return dst;\n}\n/**\n * Copies a matrix (same as {@link mat4.copy})\n * Also see {@link mat4.create} and {@link mat4.set}\n * @param m - The matrix.\n * @param dst - The matrix. If not passed a new one is created.\n * @returns A copy of m.\n */\nconst clone$2 = copy$2;\n/**\n * Check if 2 matrices are approximately equal\n * @param a - Operand matrix.\n * @param b - Operand matrix.\n * @returns true if matrices are approximately equal\n */\nfunction equalsApproximately$2(a, b) {\n return Math.abs(a[0] - b[0]) < EPSILON &&\n Math.abs(a[1] - b[1]) < EPSILON &&\n Math.abs(a[2] - b[2]) < EPSILON &&\n Math.abs(a[3] - b[3]) < EPSILON &&\n Math.abs(a[4] - b[4]) < EPSILON &&\n Math.abs(a[5] - b[5]) < EPSILON &&\n Math.abs(a[6] - b[6]) < EPSILON &&\n Math.abs(a[7] - b[7]) < EPSILON &&\n Math.abs(a[8] - b[8]) < EPSILON &&\n Math.abs(a[9] - b[9]) < EPSILON &&\n Math.abs(a[10] - b[10]) < EPSILON &&\n Math.abs(a[11] - b[11]) < EPSILON &&\n Math.abs(a[12] - b[12]) < EPSILON &&\n Math.abs(a[13] - b[13]) < EPSILON &&\n Math.abs(a[14] - b[14]) < EPSILON &&\n Math.abs(a[15] - b[15]) < EPSILON;\n}\n/**\n * Check if 2 matrices are exactly equal\n * @param a - Operand matrix.\n * @param b - Operand matrix.\n * @returns true if matrices are exactly equal\n */\nfunction equals$2(a, b) {\n return a[0] === b[0] &&\n a[1] === b[1] &&\n a[2] === b[2] &&\n a[3] === b[3] &&\n a[4] === b[4] &&\n a[5] === b[5] &&\n a[6] === b[6] &&\n a[7] === b[7] &&\n a[8] === b[8] &&\n a[9] === b[9] &&\n a[10] === b[10] &&\n a[11] === b[11] &&\n a[12] === b[12] &&\n a[13] === b[13] &&\n a[14] === b[14] &&\n a[15] === b[15];\n}\n/**\n * Creates a 4-by-4 identity matrix.\n *\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns A 4-by-4 identity matrix.\n */\nfunction identity$1(dst) {\n dst = dst || new MatType(16);\n dst[0] = 1;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = 1;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Takes the transpose of a matrix.\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The transpose of m.\n */\nfunction transpose(m, dst) {\n dst = dst || new MatType(16);\n if (dst === m) {\n let t;\n t = m[1];\n m[1] = m[4];\n m[4] = t;\n t = m[2];\n m[2] = m[8];\n m[8] = t;\n t = m[3];\n m[3] = m[12];\n m[12] = t;\n t = m[6];\n m[6] = m[9];\n m[9] = t;\n t = m[7];\n m[7] = m[13];\n m[13] = t;\n t = m[11];\n m[11] = m[14];\n m[14] = t;\n return dst;\n }\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n dst[0] = m00;\n dst[1] = m10;\n dst[2] = m20;\n dst[3] = m30;\n dst[4] = m01;\n dst[5] = m11;\n dst[6] = m21;\n dst[7] = m31;\n dst[8] = m02;\n dst[9] = m12;\n dst[10] = m22;\n dst[11] = m32;\n dst[12] = m03;\n dst[13] = m13;\n dst[14] = m23;\n dst[15] = m33;\n return dst;\n}\n/**\n * Computes the inverse of a 4-by-4 matrix.\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The inverse of m.\n */\nfunction inverse$2(m, dst) {\n dst = dst || new MatType(16);\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n const tmp0 = m22 * m33;\n const tmp1 = m32 * m23;\n const tmp2 = m12 * m33;\n const tmp3 = m32 * m13;\n const tmp4 = m12 * m23;\n const tmp5 = m22 * m13;\n const tmp6 = m02 * m33;\n const tmp7 = m32 * m03;\n const tmp8 = m02 * m23;\n const tmp9 = m22 * m03;\n const tmp10 = m02 * m13;\n const tmp11 = m12 * m03;\n const tmp12 = m20 * m31;\n const tmp13 = m30 * m21;\n const tmp14 = m10 * m31;\n const tmp15 = m30 * m11;\n const tmp16 = m10 * m21;\n const tmp17 = m20 * m11;\n const tmp18 = m00 * m31;\n const tmp19 = m30 * m01;\n const tmp20 = m00 * m21;\n const tmp21 = m20 * m01;\n const tmp22 = m00 * m11;\n const tmp23 = m10 * m01;\n const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) -\n (tmp1 * m11 + tmp2 * m21 + tmp5 * m31);\n const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) -\n (tmp0 * m01 + tmp7 * m21 + tmp8 * m31);\n const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) -\n (tmp3 * m01 + tmp6 * m11 + tmp11 * m31);\n const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) -\n (tmp4 * m01 + tmp9 * m11 + tmp10 * m21);\n const d = 1 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3);\n dst[0] = d * t0;\n dst[1] = d * t1;\n dst[2] = d * t2;\n dst[3] = d * t3;\n dst[4] = d * ((tmp1 * m10 + tmp2 * m20 + tmp5 * m30) -\n (tmp0 * m10 + tmp3 * m20 + tmp4 * m30));\n dst[5] = d * ((tmp0 * m00 + tmp7 * m20 + tmp8 * m30) -\n (tmp1 * m00 + tmp6 * m20 + tmp9 * m30));\n dst[6] = d * ((tmp3 * m00 + tmp6 * m10 + tmp11 * m30) -\n (tmp2 * m00 + tmp7 * m10 + tmp10 * m30));\n dst[7] = d * ((tmp4 * m00 + tmp9 * m10 + tmp10 * m20) -\n (tmp5 * m00 + tmp8 * m10 + tmp11 * m20));\n dst[8] = d * ((tmp12 * m13 + tmp15 * m23 + tmp16 * m33) -\n (tmp13 * m13 + tmp14 * m23 + tmp17 * m33));\n dst[9] = d * ((tmp13 * m03 + tmp18 * m23 + tmp21 * m33) -\n (tmp12 * m03 + tmp19 * m23 + tmp20 * m33));\n dst[10] = d * ((tmp14 * m03 + tmp19 * m13 + tmp22 * m33) -\n (tmp15 * m03 + tmp18 * m13 + tmp23 * m33));\n dst[11] = d * ((tmp17 * m03 + tmp20 * m13 + tmp23 * m23) -\n (tmp16 * m03 + tmp21 * m13 + tmp22 * m23));\n dst[12] = d * ((tmp14 * m22 + tmp17 * m32 + tmp13 * m12) -\n (tmp16 * m32 + tmp12 * m12 + tmp15 * m22));\n dst[13] = d * ((tmp20 * m32 + tmp12 * m02 + tmp19 * m22) -\n (tmp18 * m22 + tmp21 * m32 + tmp13 * m02));\n dst[14] = d * ((tmp18 * m12 + tmp23 * m32 + tmp15 * m02) -\n (tmp22 * m32 + tmp14 * m02 + tmp19 * m12));\n dst[15] = d * ((tmp22 * m22 + tmp16 * m02 + tmp21 * m12) -\n (tmp20 * m12 + tmp23 * m22 + tmp17 * m02));\n return dst;\n}\n/**\n * Compute the determinant of a matrix\n * @param m - the matrix\n * @returns the determinant\n */\nfunction determinant(m) {\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n const tmp0 = m22 * m33;\n const tmp1 = m32 * m23;\n const tmp2 = m12 * m33;\n const tmp3 = m32 * m13;\n const tmp4 = m12 * m23;\n const tmp5 = m22 * m13;\n const tmp6 = m02 * m33;\n const tmp7 = m32 * m03;\n const tmp8 = m02 * m23;\n const tmp9 = m22 * m03;\n const tmp10 = m02 * m13;\n const tmp11 = m12 * m03;\n const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) -\n (tmp1 * m11 + tmp2 * m21 + tmp5 * m31);\n const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) -\n (tmp0 * m01 + tmp7 * m21 + tmp8 * m31);\n const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) -\n (tmp3 * m01 + tmp6 * m11 + tmp11 * m31);\n const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) -\n (tmp4 * m01 + tmp9 * m11 + tmp10 * m21);\n return m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3;\n}\n/**\n * Computes the inverse of a 4-by-4 matrix. (same as inverse)\n * @param m - The matrix.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The inverse of m.\n */\nconst invert$1 = inverse$2;\n/**\n * Multiplies two 4-by-4 matrices with a on the left and b on the right\n * @param a - The matrix on the left.\n * @param b - The matrix on the right.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The matrix product of a and b.\n */\nfunction multiply$2(a, b, dst) {\n dst = dst || new MatType(16);\n const a00 = a[0];\n const a01 = a[1];\n const a02 = a[2];\n const a03 = a[3];\n const a10 = a[4 + 0];\n const a11 = a[4 + 1];\n const a12 = a[4 + 2];\n const a13 = a[4 + 3];\n const a20 = a[8 + 0];\n const a21 = a[8 + 1];\n const a22 = a[8 + 2];\n const a23 = a[8 + 3];\n const a30 = a[12 + 0];\n const a31 = a[12 + 1];\n const a32 = a[12 + 2];\n const a33 = a[12 + 3];\n const b00 = b[0];\n const b01 = b[1];\n const b02 = b[2];\n const b03 = b[3];\n const b10 = b[4 + 0];\n const b11 = b[4 + 1];\n const b12 = b[4 + 2];\n const b13 = b[4 + 3];\n const b20 = b[8 + 0];\n const b21 = b[8 + 1];\n const b22 = b[8 + 2];\n const b23 = b[8 + 3];\n const b30 = b[12 + 0];\n const b31 = b[12 + 1];\n const b32 = b[12 + 2];\n const b33 = b[12 + 3];\n dst[0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03;\n dst[1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03;\n dst[2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03;\n dst[3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03;\n dst[4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13;\n dst[5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13;\n dst[6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13;\n dst[7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13;\n dst[8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23;\n dst[9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23;\n dst[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23;\n dst[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23;\n dst[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;\n dst[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;\n dst[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;\n dst[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;\n return dst;\n}\n/**\n * Multiplies two 4-by-4 matrices with a on the left and b on the right (same as multiply)\n * @param a - The matrix on the left.\n * @param b - The matrix on the right.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The matrix product of a and b.\n */\nconst mul$2 = multiply$2;\n/**\n * Sets the translation component of a 4-by-4 matrix to the given\n * vector.\n * @param a - The matrix.\n * @param v - The vector.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The matrix with translation set.\n */\nfunction setTranslation(a, v, dst) {\n dst = dst || identity$1();\n if (a !== dst) {\n dst[0] = a[0];\n dst[1] = a[1];\n dst[2] = a[2];\n dst[3] = a[3];\n dst[4] = a[4];\n dst[5] = a[5];\n dst[6] = a[6];\n dst[7] = a[7];\n dst[8] = a[8];\n dst[9] = a[9];\n dst[10] = a[10];\n dst[11] = a[11];\n }\n dst[12] = v[0];\n dst[13] = v[1];\n dst[14] = v[2];\n dst[15] = 1;\n return dst;\n}\n/**\n * Returns the translation component of a 4-by-4 matrix as a vector with 3\n * entries.\n * @param m - The matrix.\n * @param dst - vector to hold result. If not passed a new one is created.\n * @returns The translation component of m.\n */\nfunction getTranslation(m, dst) {\n dst = dst || create$4();\n dst[0] = m[12];\n dst[1] = m[13];\n dst[2] = m[14];\n return dst;\n}\n/**\n * Returns an axis of a 4x4 matrix as a vector with 3 entries\n * @param m - The matrix.\n * @param axis - The axis 0 = x, 1 = y, 2 = z;\n * @returns The axis component of m.\n */\nfunction getAxis(m, axis, dst) {\n dst = dst || create$4();\n const off = axis * 4;\n dst[0] = m[off + 0];\n dst[1] = m[off + 1];\n dst[2] = m[off + 2];\n return dst;\n}\n/**\n * Sets an axis of a 4x4 matrix as a vector with 3 entries\n * @param m - The matrix.\n * @param v - the axis vector\n * @param axis - The axis 0 = x, 1 = y, 2 = z;\n * @param dst - The matrix to set. If not passed a new one is created.\n * @returns The matrix with axis set.\n */\nfunction setAxis(a, v, axis, dst) {\n if (dst !== a) {\n dst = copy$2(a, dst);\n }\n const off = axis * 4;\n dst[off + 0] = v[0];\n dst[off + 1] = v[1];\n dst[off + 2] = v[2];\n return dst;\n}\n/**\n * Returns the scaling component of the matrix\n * @param m - The Matrix\n * @param dst - The vector to set. If not passed a new one is created.\n */\nfunction getScaling(m, dst) {\n dst = dst || create$4();\n const xx = m[0];\n const xy = m[1];\n const xz = m[2];\n const yx = m[4];\n const yy = m[5];\n const yz = m[6];\n const zx = m[8];\n const zy = m[9];\n const zz = m[10];\n dst[0] = Math.sqrt(xx * xx + xy * xy + xz * xz);\n dst[1] = Math.sqrt(yx * yx + yy * yy + yz * yz);\n dst[2] = Math.sqrt(zx * zx + zy * zy + zz * zz);\n return dst;\n}\n/**\n * Computes a 4-by-4 perspective transformation matrix given the angular height\n * of the frustum, the aspect ratio, and the near and far clipping planes. The\n * arguments define a frustum extending in the negative z direction. The given\n * angle is the vertical angle of the frustum, and the horizontal angle is\n * determined to produce the given aspect ratio. The arguments near and far are\n * the distances to the near and far clipping planes. Note that near and far\n * are not z coordinates, but rather they are distances along the negative\n * z-axis. The matrix generated sends the viewing frustum to the unit box.\n * We assume a unit box extending from -1 to 1 in the x and y dimensions and\n * from 0 to 1 in the z dimension.\n *\n * Note: If you pass `Infinity` for zFar then it will produce a projection matrix\n * returns -Infinity for Z when transforming coordinates with Z <= 0 and +Infinity for Z\n * otherwise.\n *\n * @param fieldOfViewYInRadians - The camera angle from top to bottom (in radians).\n * @param aspect - The aspect ratio width / height.\n * @param zNear - The depth (negative z coordinate)\n * of the near clipping plane.\n * @param zFar - The depth (negative z coordinate)\n * of the far clipping plane.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The perspective matrix.\n */\nfunction perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {\n dst = dst || new MatType(16);\n const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);\n dst[0] = f / aspect;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = f;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[11] = -1;\n dst[12] = 0;\n dst[13] = 0;\n dst[15] = 0;\n if (zFar === Infinity) {\n dst[10] = -1;\n dst[14] = -zNear;\n }\n else {\n const rangeInv = 1 / (zNear - zFar);\n dst[10] = zFar * rangeInv;\n dst[14] = zFar * zNear * rangeInv;\n }\n return dst;\n}\n/**\n * Computes a 4-by-4 orthogonal transformation matrix that transforms from\n * the given the left, right, bottom, and top dimensions to -1 +1 in x, and y\n * and 0 to +1 in z.\n * @param left - Left side of the near clipping plane viewport.\n * @param right - Right side of the near clipping plane viewport.\n * @param bottom - Bottom of the near clipping plane viewport.\n * @param top - Top of the near clipping plane viewport.\n * @param near - The depth (negative z coordinate)\n * of the near clipping plane.\n * @param far - The depth (negative z coordinate)\n * of the far clipping plane.\n * @param dst - Output matrix. If not passed a new one is created.\n * @returns The orthographic projection matrix.\n */\nfunction ortho(left, right, bottom, top, near, far, dst) {\n dst = dst || new MatType(16);\n dst[0] = 2 / (right - left);\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = 2 / (top - bottom);\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1 / (near - far);\n dst[11] = 0;\n dst[12] = (right + left) / (left - right);\n dst[13] = (top + bottom) / (bottom - top);\n dst[14] = near / (near - far);\n dst[15] = 1;\n return dst;\n}\n/**\n * Computes a 4-by-4 perspective transformation matrix given the left, right,\n * top, bottom, near and far clipping planes. The arguments define a frustum\n * extending in the negative z direction. The arguments near and far are the\n * distances to the near and far clipping planes. Note that near and far are not\n * z coordinates, but rather they are distances along the negative z-axis. The\n * matrix generated sends the viewing frustum to the unit box. We assume a unit\n * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z\n * dimension.\n * @param left - The x coordinate of the left plane of the box.\n * @param right - The x coordinate of the right plane of the box.\n * @param bottom - The y coordinate of the bottom plane of the box.\n * @param top - The y coordinate of the right plane of the box.\n * @param near - The negative z coordinate of the near plane of the box.\n * @param far - The negative z coordinate of the far plane of the box.\n * @param dst - Output matrix. If not passed a new one is created.\n * @returns The perspective projection matrix.\n */\nfunction frustum(left, right, bottom, top, near, far, dst) {\n dst = dst || new MatType(16);\n const dx = (right - left);\n const dy = (top - bottom);\n const dz = (near - far);\n dst[0] = 2 * near / dx;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = 2 * near / dy;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = (left + right) / dx;\n dst[9] = (top + bottom) / dy;\n dst[10] = far / dz;\n dst[11] = -1;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = near * far / dz;\n dst[15] = 0;\n return dst;\n}\nlet xAxis;\nlet yAxis;\nlet zAxis;\n/**\n * Computes a 4-by-4 aim transformation.\n *\n * This is a matrix which positions an object aiming down positive Z.\n * toward the target.\n *\n * Note: this is **NOT** the inverse of lookAt as lookAt looks at negative Z.\n *\n * @param position - The position of the object.\n * @param target - The position meant to be aimed at.\n * @param up - A vector pointing up.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The aim matrix.\n */\nfunction aim(position, target, up, dst) {\n dst = dst || new MatType(16);\n xAxis = xAxis || create$4();\n yAxis = yAxis || create$4();\n zAxis = zAxis || create$4();\n normalize$2(subtract$2(target, position, zAxis), zAxis);\n normalize$2(cross(up, zAxis, xAxis), xAxis);\n normalize$2(cross(zAxis, xAxis, yAxis), yAxis);\n dst[0] = xAxis[0];\n dst[1] = xAxis[1];\n dst[2] = xAxis[2];\n dst[3] = 0;\n dst[4] = yAxis[0];\n dst[5] = yAxis[1];\n dst[6] = yAxis[2];\n dst[7] = 0;\n dst[8] = zAxis[0];\n dst[9] = zAxis[1];\n dst[10] = zAxis[2];\n dst[11] = 0;\n dst[12] = position[0];\n dst[13] = position[1];\n dst[14] = position[2];\n dst[15] = 1;\n return dst;\n}\n/**\n * Computes a 4-by-4 camera aim transformation.\n *\n * This is a matrix which positions an object aiming down negative Z.\n * toward the target.\n *\n * Note: this is the inverse of `lookAt`\n *\n * @param eye - The position of the object.\n * @param target - The position meant to be aimed at.\n * @param up - A vector pointing up.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The aim matrix.\n */\nfunction cameraAim(eye, target, up, dst) {\n dst = dst || new MatType(16);\n xAxis = xAxis || create$4();\n yAxis = yAxis || create$4();\n zAxis = zAxis || create$4();\n normalize$2(subtract$2(eye, target, zAxis), zAxis);\n normalize$2(cross(up, zAxis, xAxis), xAxis);\n normalize$2(cross(zAxis, xAxis, yAxis), yAxis);\n dst[0] = xAxis[0];\n dst[1] = xAxis[1];\n dst[2] = xAxis[2];\n dst[3] = 0;\n dst[4] = yAxis[0];\n dst[5] = yAxis[1];\n dst[6] = yAxis[2];\n dst[7] = 0;\n dst[8] = zAxis[0];\n dst[9] = zAxis[1];\n dst[10] = zAxis[2];\n dst[11] = 0;\n dst[12] = eye[0];\n dst[13] = eye[1];\n dst[14] = eye[2];\n dst[15] = 1;\n return dst;\n}\n/**\n * Computes a 4-by-4 view transformation.\n *\n * This is a view matrix which transforms all other objects\n * to be in the space of the view defined by the parameters.\n *\n * @param eye - The position of the object.\n * @param target - The position meant to be aimed at.\n * @param up - A vector pointing up.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The look-at matrix.\n */\nfunction lookAt(eye, target, up, dst) {\n dst = dst || new MatType(16);\n xAxis = xAxis || create$4();\n yAxis = yAxis || create$4();\n zAxis = zAxis || create$4();\n normalize$2(subtract$2(eye, target, zAxis), zAxis);\n normalize$2(cross(up, zAxis, xAxis), xAxis);\n normalize$2(cross(zAxis, xAxis, yAxis), yAxis);\n dst[0] = xAxis[0];\n dst[1] = yAxis[0];\n dst[2] = zAxis[0];\n dst[3] = 0;\n dst[4] = xAxis[1];\n dst[5] = yAxis[1];\n dst[6] = zAxis[1];\n dst[7] = 0;\n dst[8] = xAxis[2];\n dst[9] = yAxis[2];\n dst[10] = zAxis[2];\n dst[11] = 0;\n dst[12] = -(xAxis[0] * eye[0] + xAxis[1] * eye[1] + xAxis[2] * eye[2]);\n dst[13] = -(yAxis[0] * eye[0] + yAxis[1] * eye[1] + yAxis[2] * eye[2]);\n dst[14] = -(zAxis[0] * eye[0] + zAxis[1] * eye[1] + zAxis[2] * eye[2]);\n dst[15] = 1;\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which translates by the given vector v.\n * @param v - The vector by\n * which to translate.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The translation matrix.\n */\nfunction translation(v, dst) {\n dst = dst || new MatType(16);\n dst[0] = 1;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = 1;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n dst[11] = 0;\n dst[12] = v[0];\n dst[13] = v[1];\n dst[14] = v[2];\n dst[15] = 1;\n return dst;\n}\n/**\n * Translates the given 4-by-4 matrix by the given vector v.\n * @param m - The matrix.\n * @param v - The vector by\n * which to translate.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The translated matrix.\n */\nfunction translate(m, v, dst) {\n dst = dst || new MatType(16);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const m00 = m[0];\n const m01 = m[1];\n const m02 = m[2];\n const m03 = m[3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n if (m !== dst) {\n dst[0] = m00;\n dst[1] = m01;\n dst[2] = m02;\n dst[3] = m03;\n dst[4] = m10;\n dst[5] = m11;\n dst[6] = m12;\n dst[7] = m13;\n dst[8] = m20;\n dst[9] = m21;\n dst[10] = m22;\n dst[11] = m23;\n }\n dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;\n dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;\n dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;\n dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotation matrix.\n */\nfunction rotationX(angleInRadians, dst) {\n dst = dst || new MatType(16);\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = 1;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = c;\n dst[6] = s;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = -s;\n dst[10] = c;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Rotates the given 4-by-4 matrix around the x-axis by the given\n * angle.\n * @param m - The matrix.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotated matrix.\n */\nfunction rotateX$1(m, angleInRadians, dst) {\n dst = dst || new MatType(16);\n const m10 = m[4];\n const m11 = m[5];\n const m12 = m[6];\n const m13 = m[7];\n const m20 = m[8];\n const m21 = m[9];\n const m22 = m[10];\n const m23 = m[11];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[4] = c * m10 + s * m20;\n dst[5] = c * m11 + s * m21;\n dst[6] = c * m12 + s * m22;\n dst[7] = c * m13 + s * m23;\n dst[8] = c * m20 - s * m10;\n dst[9] = c * m21 - s * m11;\n dst[10] = c * m22 - s * m12;\n dst[11] = c * m23 - s * m13;\n if (m !== dst) {\n dst[0] = m[0];\n dst[1] = m[1];\n dst[2] = m[2];\n dst[3] = m[3];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotation matrix.\n */\nfunction rotationY(angleInRadians, dst) {\n dst = dst || new MatType(16);\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = c;\n dst[1] = 0;\n dst[2] = -s;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = 1;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = s;\n dst[9] = 0;\n dst[10] = c;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Rotates the given 4-by-4 matrix around the y-axis by the given\n * angle.\n * @param m - The matrix.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotated matrix.\n */\nfunction rotateY$1(m, angleInRadians, dst) {\n dst = dst || new MatType(16);\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = c * m00 - s * m20;\n dst[1] = c * m01 - s * m21;\n dst[2] = c * m02 - s * m22;\n dst[3] = c * m03 - s * m23;\n dst[8] = c * m20 + s * m00;\n dst[9] = c * m21 + s * m01;\n dst[10] = c * m22 + s * m02;\n dst[11] = c * m23 + s * m03;\n if (m !== dst) {\n dst[4] = m[4];\n dst[5] = m[5];\n dst[6] = m[6];\n dst[7] = m[7];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotation matrix.\n */\nfunction rotationZ(angleInRadians, dst) {\n dst = dst || new MatType(16);\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = c;\n dst[1] = s;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = -s;\n dst[5] = c;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 1;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Rotates the given 4-by-4 matrix around the z-axis by the given\n * angle.\n * @param m - The matrix.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotated matrix.\n */\nfunction rotateZ$1(m, angleInRadians, dst) {\n dst = dst || new MatType(16);\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n dst[0] = c * m00 + s * m10;\n dst[1] = c * m01 + s * m11;\n dst[2] = c * m02 + s * m12;\n dst[3] = c * m03 + s * m13;\n dst[4] = c * m10 - s * m00;\n dst[5] = c * m11 - s * m01;\n dst[6] = c * m12 - s * m02;\n dst[7] = c * m13 - s * m03;\n if (m !== dst) {\n dst[8] = m[8];\n dst[9] = m[9];\n dst[10] = m[10];\n dst[11] = m[11];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which rotates around the given axis by the given\n * angle.\n * @param axis - The axis\n * about which to rotate.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns A matrix which rotates angle radians\n * around the axis.\n */\nfunction axisRotation(axis, angleInRadians, dst) {\n dst = dst || new MatType(16);\n let x = axis[0];\n let y = axis[1];\n let z = axis[2];\n const n = Math.sqrt(x * x + y * y + z * z);\n x /= n;\n y /= n;\n z /= n;\n const xx = x * x;\n const yy = y * y;\n const zz = z * z;\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n const oneMinusCosine = 1 - c;\n dst[0] = xx + (1 - xx) * c;\n dst[1] = x * y * oneMinusCosine + z * s;\n dst[2] = x * z * oneMinusCosine - y * s;\n dst[3] = 0;\n dst[4] = x * y * oneMinusCosine - z * s;\n dst[5] = yy + (1 - yy) * c;\n dst[6] = y * z * oneMinusCosine + x * s;\n dst[7] = 0;\n dst[8] = x * z * oneMinusCosine + y * s;\n dst[9] = y * z * oneMinusCosine - x * s;\n dst[10] = zz + (1 - zz) * c;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which rotates around the given axis by the given\n * angle. (same as axisRotation)\n * @param axis - The axis\n * about which to rotate.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns A matrix which rotates angle radians\n * around the axis.\n */\nconst rotation = axisRotation;\n/**\n * Rotates the given 4-by-4 matrix around the given axis by the\n * given angle.\n * @param m - The matrix.\n * @param axis - The axis\n * about which to rotate.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotated matrix.\n */\nfunction axisRotate(m, axis, angleInRadians, dst) {\n dst = dst || new MatType(16);\n let x = axis[0];\n let y = axis[1];\n let z = axis[2];\n const n = Math.sqrt(x * x + y * y + z * z);\n x /= n;\n y /= n;\n z /= n;\n const xx = x * x;\n const yy = y * y;\n const zz = z * z;\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n const oneMinusCosine = 1 - c;\n const r00 = xx + (1 - xx) * c;\n const r01 = x * y * oneMinusCosine + z * s;\n const r02 = x * z * oneMinusCosine - y * s;\n const r10 = x * y * oneMinusCosine - z * s;\n const r11 = yy + (1 - yy) * c;\n const r12 = y * z * oneMinusCosine + x * s;\n const r20 = x * z * oneMinusCosine + y * s;\n const r21 = y * z * oneMinusCosine - x * s;\n const r22 = zz + (1 - zz) * c;\n const m00 = m[0];\n const m01 = m[1];\n const m02 = m[2];\n const m03 = m[3];\n const m10 = m[4];\n const m11 = m[5];\n const m12 = m[6];\n const m13 = m[7];\n const m20 = m[8];\n const m21 = m[9];\n const m22 = m[10];\n const m23 = m[11];\n dst[0] = r00 * m00 + r01 * m10 + r02 * m20;\n dst[1] = r00 * m01 + r01 * m11 + r02 * m21;\n dst[2] = r00 * m02 + r01 * m12 + r02 * m22;\n dst[3] = r00 * m03 + r01 * m13 + r02 * m23;\n dst[4] = r10 * m00 + r11 * m10 + r12 * m20;\n dst[5] = r10 * m01 + r11 * m11 + r12 * m21;\n dst[6] = r10 * m02 + r11 * m12 + r12 * m22;\n dst[7] = r10 * m03 + r11 * m13 + r12 * m23;\n dst[8] = r20 * m00 + r21 * m10 + r22 * m20;\n dst[9] = r20 * m01 + r21 * m11 + r22 * m21;\n dst[10] = r20 * m02 + r21 * m12 + r22 * m22;\n dst[11] = r20 * m03 + r21 * m13 + r22 * m23;\n if (m !== dst) {\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n return dst;\n}\n/**\n * Rotates the given 4-by-4 matrix around the given axis by the\n * given angle. (same as rotate)\n * @param m - The matrix.\n * @param axis - The axis\n * about which to rotate.\n * @param angleInRadians - The angle by which to rotate (in radians).\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The rotated matrix.\n */\nconst rotate = axisRotate;\n/**\n * Creates a 4-by-4 matrix which scales in each dimension by an amount given by\n * the corresponding entry in the given vector; assumes the vector has three\n * entries.\n * @param v - A vector of\n * three entries specifying the factor by which to scale in each dimension.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaling matrix.\n */\nfunction scaling(v, dst) {\n dst = dst || new MatType(16);\n dst[0] = v[0];\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = v[1];\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = v[2];\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Scales the given 4-by-4 matrix in each dimension by an amount\n * given by the corresponding entry in the given vector; assumes the vector has\n * three entries.\n * @param m - The matrix to be modified.\n * @param v - A vector of three entries specifying the\n * factor by which to scale in each dimension.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaled matrix.\n */\nfunction scale$2(m, v, dst) {\n dst = dst || new MatType(16);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n dst[0] = v0 * m[0 * 4 + 0];\n dst[1] = v0 * m[0 * 4 + 1];\n dst[2] = v0 * m[0 * 4 + 2];\n dst[3] = v0 * m[0 * 4 + 3];\n dst[4] = v1 * m[1 * 4 + 0];\n dst[5] = v1 * m[1 * 4 + 1];\n dst[6] = v1 * m[1 * 4 + 2];\n dst[7] = v1 * m[1 * 4 + 3];\n dst[8] = v2 * m[2 * 4 + 0];\n dst[9] = v2 * m[2 * 4 + 1];\n dst[10] = v2 * m[2 * 4 + 2];\n dst[11] = v2 * m[2 * 4 + 3];\n if (m !== dst) {\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n return dst;\n}\n/**\n * Creates a 4-by-4 matrix which scales a uniform amount in each dimension.\n * @param s - the amount to scale\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaling matrix.\n */\nfunction uniformScaling(s, dst) {\n dst = dst || new MatType(16);\n dst[0] = s;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n dst[4] = 0;\n dst[5] = s;\n dst[6] = 0;\n dst[7] = 0;\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = s;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n return dst;\n}\n/**\n * Scales the given 4-by-4 matrix in each dimension by a uniform scale.\n * @param m - The matrix to be modified.\n * @param s - The amount to scale.\n * @param dst - matrix to hold result. If not passed a new one is created.\n * @returns The scaled matrix.\n */\nfunction uniformScale(m, s, dst) {\n dst = dst || new MatType(16);\n dst[0] = s * m[0 * 4 + 0];\n dst[1] = s * m[0 * 4 + 1];\n dst[2] = s * m[0 * 4 + 2];\n dst[3] = s * m[0 * 4 + 3];\n dst[4] = s * m[1 * 4 + 0];\n dst[5] = s * m[1 * 4 + 1];\n dst[6] = s * m[1 * 4 + 2];\n dst[7] = s * m[1 * 4 + 3];\n dst[8] = s * m[2 * 4 + 0];\n dst[9] = s * m[2 * 4 + 1];\n dst[10] = s * m[2 * 4 + 2];\n dst[11] = s * m[2 * 4 + 3];\n if (m !== dst) {\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n return dst;\n}\n\nvar mat4Impl = /*#__PURE__*/Object.freeze({\n __proto__: null,\n aim: aim,\n axisRotate: axisRotate,\n axisRotation: axisRotation,\n cameraAim: cameraAim,\n clone: clone$2,\n copy: copy$2,\n create: create$2,\n determinant: determinant,\n equals: equals$2,\n equalsApproximately: equalsApproximately$2,\n fromMat3: fromMat3,\n fromQuat: fromQuat,\n frustum: frustum,\n getAxis: getAxis,\n getScaling: getScaling,\n getTranslation: getTranslation,\n identity: identity$1,\n inverse: inverse$2,\n invert: invert$1,\n lookAt: lookAt,\n mul: mul$2,\n multiply: multiply$2,\n negate: negate$1,\n ortho: ortho,\n perspective: perspective,\n rotate: rotate,\n rotateX: rotateX$1,\n rotateY: rotateY$1,\n rotateZ: rotateZ$1,\n rotation: rotation,\n rotationX: rotationX,\n rotationY: rotationY,\n rotationZ: rotationZ,\n scale: scale$2,\n scaling: scaling,\n set: set$2,\n setAxis: setAxis,\n setDefaultType: setDefaultType$3,\n setTranslation: setTranslation,\n translate: translate,\n translation: translation,\n transpose: transpose,\n uniformScale: uniformScale,\n uniformScaling: uniformScaling\n});\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n *\n * Quat4 math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new `Quat4`. In other words you can do this\n *\n * const v = quat4.cross(v1, v2); // Creates a new Quat4 with the cross product of v1 x v2.\n *\n * or\n *\n * const v = quat4.create();\n * quat4.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always safe to pass any vector as the destination. So for example\n *\n * quat4.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1\n *\n */\nlet QuatType = Float32Array;\n/**\n * Sets the type this library creates for a Quat4\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n * @returns previous constructor for Quat4\n */\nfunction setDefaultType$2(ctor) {\n const oldType = QuatType;\n QuatType = ctor;\n return oldType;\n}\n/**\n * Creates a quat4; may be called with x, y, z to set initial values.\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @param z - Initial z value.\n * @param w - Initial w value.\n * @returns the created vector\n */\nfunction create$1(x, y, z, w) {\n const dst = new QuatType(4);\n if (x !== undefined) {\n dst[0] = x;\n if (y !== undefined) {\n dst[1] = y;\n if (z !== undefined) {\n dst[2] = z;\n if (w !== undefined) {\n dst[3] = w;\n }\n }\n }\n }\n return dst;\n}\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n * Creates a Quat; may be called with x, y, z to set initial values. (same as create)\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @param z - Initial z value.\n * @param z - Initial w value.\n * @returns the created vector\n */\nconst fromValues$1 = create$1;\n/**\n * Sets the values of a Quat\n * Also see {@link quat.create} and {@link quat.copy}\n *\n * @param x first value\n * @param y second value\n * @param z third value\n * @param w fourth value\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector with its elements set.\n */\nfunction set$1(x, y, z, w, dst) {\n dst = dst || new QuatType(4);\n dst[0] = x;\n dst[1] = y;\n dst[2] = z;\n dst[3] = w;\n return dst;\n}\n/**\n * Sets a quaternion from the given angle and axis,\n * then returns it.\n *\n * @param axis - the axis to rotate around\n * @param angleInRadians - the angle\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The quaternion that represents the given axis and angle\n **/\nfunction fromAxisAngle(axis, angleInRadians, dst) {\n dst = dst || new QuatType(4);\n const halfAngle = angleInRadians * 0.5;\n const s = Math.sin(halfAngle);\n dst[0] = s * axis[0];\n dst[1] = s * axis[1];\n dst[2] = s * axis[2];\n dst[3] = Math.cos(halfAngle);\n return dst;\n}\n/**\n * Gets the rotation axis and angle\n * @param q - quaternion to compute from\n * @param dst - Vec3 to hold result. If not passed in a new one is created.\n * @return angle and axis\n */\nfunction toAxisAngle(q, dst) {\n dst = dst || create$4(4);\n const angle = Math.acos(q[3]) * 2;\n const s = Math.sin(angle * 0.5);\n if (s > EPSILON) {\n dst[0] = q[0] / s;\n dst[1] = q[1] / s;\n dst[2] = q[2] / s;\n }\n else {\n dst[0] = 1;\n dst[1] = 0;\n dst[2] = 0;\n }\n return { angle, axis: dst };\n}\n/**\n * Returns the angle in degrees between two rotations a and b.\n * @param a - quaternion a\n * @param b - quaternion b\n * @return angle in radians between the two quaternions\n */\nfunction angle(a, b) {\n const d = dot$1(a, b);\n return Math.acos(2 * d * d - 1);\n}\n/**\n * Multiplies two quaternions\n *\n * @param a - the first quaternion\n * @param b - the second quaternion\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the result of a * b\n */\nfunction multiply$1(a, b, dst) {\n dst = dst || new QuatType(4);\n const ax = a[0];\n const ay = a[1];\n const az = a[2];\n const aw = a[3];\n const bx = b[0];\n const by = b[1];\n const bz = b[2];\n const bw = b[3];\n dst[0] = ax * bw + aw * bx + ay * bz - az * by;\n dst[1] = ay * bw + aw * by + az * bx - ax * bz;\n dst[2] = az * bw + aw * bz + ax * by - ay * bx;\n dst[3] = aw * bw - ax * bx - ay * by - az * bz;\n return dst;\n}\n/**\n * Multiplies two quaternions\n *\n * @param a - the first quaternion\n * @param b - the second quaternion\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the result of a * b\n */\nconst mul$1 = multiply$1;\n/**\n * Rotates the given quaternion around the X axis by the given angle.\n * @param q - quaternion to rotate\n * @param angleInRadians - The angle by which to rotate\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the result of a * b\n */\nfunction rotateX(q, angleInRadians, dst) {\n dst = dst || new QuatType(4);\n const halfAngle = angleInRadians * 0.5;\n const qx = q[0];\n const qy = q[1];\n const qz = q[2];\n const qw = q[3];\n const bx = Math.sin(halfAngle);\n const bw = Math.cos(halfAngle);\n dst[0] = qx * bw + qw * bx;\n dst[1] = qy * bw + qz * bx;\n dst[2] = qz * bw - qy * bx;\n dst[3] = qw * bw - qx * bx;\n return dst;\n}\n/**\n * Rotates the given quaternion around the Y axis by the given angle.\n * @param q - quaternion to rotate\n * @param angleInRadians - The angle by which to rotate\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the result of a * b\n */\nfunction rotateY(q, angleInRadians, dst) {\n dst = dst || new QuatType(4);\n const halfAngle = angleInRadians * 0.5;\n const qx = q[0];\n const qy = q[1];\n const qz = q[2];\n const qw = q[3];\n const by = Math.sin(halfAngle);\n const bw = Math.cos(halfAngle);\n dst[0] = qx * bw - qz * by;\n dst[1] = qy * bw + qw * by;\n dst[2] = qz * bw + qx * by;\n dst[3] = qw * bw - qy * by;\n return dst;\n}\n/**\n * Rotates the given quaternion around the Z axis by the given angle.\n * @param q - quaternion to rotate\n * @param angleInRadians - The angle by which to rotate\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the result of a * b\n */\nfunction rotateZ(q, angleInRadians, dst) {\n dst = dst || new QuatType(4);\n const halfAngle = angleInRadians * 0.5;\n const qx = q[0];\n const qy = q[1];\n const qz = q[2];\n const qw = q[3];\n const bz = Math.sin(halfAngle);\n const bw = Math.cos(halfAngle);\n dst[0] = qx * bw + qy * bz;\n dst[1] = qy * bw - qx * bz;\n dst[2] = qz * bw + qw * bz;\n dst[3] = qw * bw - qz * bz;\n return dst;\n}\n/**\n * Spherically linear interpolate between two quaternions\n *\n * @param a - starting value\n * @param b - ending value\n * @param t - value where 0 = a and 1 = b\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the result of a * b\n */\nfunction slerp(a, b, t, dst) {\n dst = dst || new QuatType(4);\n const ax = a[0];\n const ay = a[1];\n const az = a[2];\n const aw = a[3];\n let bx = b[0];\n let by = b[1];\n let bz = b[2];\n let bw = b[3];\n let cosOmega = ax * bx + ay * by + az * bz + aw * bw;\n if (cosOmega < 0) {\n cosOmega = -cosOmega;\n bx = -bx;\n by = -by;\n bz = -bz;\n bw = -bw;\n }\n let scale0;\n let scale1;\n if (1.0 - cosOmega > EPSILON) {\n const omega = Math.acos(cosOmega);\n const sinOmega = Math.sin(omega);\n scale0 = Math.sin((1 - t) * omega) / sinOmega;\n scale1 = Math.sin(t * omega) / sinOmega;\n }\n else {\n scale0 = 1.0 - t;\n scale1 = t;\n }\n dst[0] = scale0 * ax + scale1 * bx;\n dst[1] = scale0 * ay + scale1 * by;\n dst[2] = scale0 * az + scale1 * bz;\n dst[3] = scale0 * aw + scale1 * bw;\n return dst;\n}\n/**\n * Compute the inverse of a quaternion\n *\n * @param q - quaternion to compute the inverse of\n * @returns A quaternion that is the result of a * b\n */\nfunction inverse$1(q, dst) {\n dst = dst || new QuatType(4);\n const a0 = q[0];\n const a1 = q[1];\n const a2 = q[2];\n const a3 = q[3];\n const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;\n const invDot = dot ? 1 / dot : 0;\n dst[0] = -a0 * invDot;\n dst[1] = -a1 * invDot;\n dst[2] = -a2 * invDot;\n dst[3] = a3 * invDot;\n return dst;\n}\n/**\n * Compute the conjugate of a quaternion\n * For quaternions with a magnitude of 1 (a unit quaternion)\n * this returns the same as the inverse but is faster to calculate.\n *\n * @param q - quaternion to compute the conjugate of.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The conjugate of q\n */\nfunction conjugate(q, dst) {\n dst = dst || new QuatType(4);\n dst[0] = -q[0];\n dst[1] = -q[1];\n dst[2] = -q[2];\n dst[3] = q[3];\n return dst;\n}\n/**\n * Creates a quaternion from the given rotation matrix.\n *\n * The created quaternion is not normalized.\n *\n * @param m - rotation matrix\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns the result\n */\nfunction fromMat(m, dst) {\n dst = dst || new QuatType(4);\n /*\n 0 1 2\n 3 4 5\n 6 7 8\n \n 0 1 2\n 4 5 6\n 8 9 10\n */\n // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes\n // article \"Quaternion Calculus and Fast Animation\".\n const trace = m[0] + m[5] + m[10];\n if (trace > 0.0) {\n // |w| > 1/2, may as well choose w > 1/2\n const root = Math.sqrt(trace + 1); // 2w\n dst[3] = 0.5 * root;\n const invRoot = 0.5 / root; // 1/(4w)\n dst[0] = (m[6] - m[9]) * invRoot;\n dst[1] = (m[8] - m[2]) * invRoot;\n dst[2] = (m[1] - m[4]) * invRoot;\n }\n else {\n // |w| <= 1/2\n let i = 0;\n if (m[5] > m[0]) {\n i = 1;\n }\n if (m[10] > m[i * 4 + i]) {\n i = 2;\n }\n const j = (i + 1) % 3;\n const k = (i + 2) % 3;\n const root = Math.sqrt(m[i * 4 + i] - m[j * 4 + j] - m[k * 4 + k] + 1.0);\n dst[i] = 0.5 * root;\n const invRoot = 0.5 / root;\n dst[3] = (m[j * 4 + k] - m[k * 4 + j]) * invRoot;\n dst[j] = (m[j * 4 + i] + m[i * 4 + j]) * invRoot;\n dst[k] = (m[k * 4 + i] + m[i * 4 + k]) * invRoot;\n }\n return dst;\n}\n/**\n * Creates a quaternion from the given euler angle x, y, z using the provided intrinsic order for the conversion.\n *\n * @param xAngleInRadians - angle to rotate around X axis in radians.\n * @param yAngleInRadians - angle to rotate around Y axis in radians.\n * @param zAngleInRadians - angle to rotate around Z axis in radians.\n * @param order - order to apply euler angles\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion representing the same rotation as the euler angles applied in the given order\n */\nfunction fromEuler(xAngleInRadians, yAngleInRadians, zAngleInRadians, order, dst) {\n dst = dst || new QuatType(4);\n const xHalfAngle = xAngleInRadians * 0.5;\n const yHalfAngle = yAngleInRadians * 0.5;\n const zHalfAngle = zAngleInRadians * 0.5;\n const sx = Math.sin(xHalfAngle);\n const cx = Math.cos(xHalfAngle);\n const sy = Math.sin(yHalfAngle);\n const cy = Math.cos(yHalfAngle);\n const sz = Math.sin(zHalfAngle);\n const cz = Math.cos(zHalfAngle);\n switch (order) {\n case 'xyz':\n dst[0] = sx * cy * cz + cx * sy * sz;\n dst[1] = cx * sy * cz - sx * cy * sz;\n dst[2] = cx * cy * sz + sx * sy * cz;\n dst[3] = cx * cy * cz - sx * sy * sz;\n break;\n case 'xzy':\n dst[0] = sx * cy * cz - cx * sy * sz;\n dst[1] = cx * sy * cz - sx * cy * sz;\n dst[2] = cx * cy * sz + sx * sy * cz;\n dst[3] = cx * cy * cz + sx * sy * sz;\n break;\n case 'yxz':\n dst[0] = sx * cy * cz + cx * sy * sz;\n dst[1] = cx * sy * cz - sx * cy * sz;\n dst[2] = cx * cy * sz - sx * sy * cz;\n dst[3] = cx * cy * cz + sx * sy * sz;\n break;\n case 'yzx':\n dst[0] = sx * cy * cz + cx * sy * sz;\n dst[1] = cx * sy * cz + sx * cy * sz;\n dst[2] = cx * cy * sz - sx * sy * cz;\n dst[3] = cx * cy * cz - sx * sy * sz;\n break;\n case 'zxy':\n dst[0] = sx * cy * cz - cx * sy * sz;\n dst[1] = cx * sy * cz + sx * cy * sz;\n dst[2] = cx * cy * sz + sx * sy * cz;\n dst[3] = cx * cy * cz - sx * sy * sz;\n break;\n case 'zyx':\n dst[0] = sx * cy * cz - cx * sy * sz;\n dst[1] = cx * sy * cz + sx * cy * sz;\n dst[2] = cx * cy * sz - sx * sy * cz;\n dst[3] = cx * cy * cz + sx * sy * sz;\n break;\n default:\n throw new Error(`Unknown rotation order: ${order}`);\n }\n return dst;\n}\n/**\n * Copies a quaternion. (same as {@link quat.clone})\n * Also see {@link quat.create} and {@link quat.set}\n * @param q - The quaternion.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is a copy of q\n */\nfunction copy$1(q, dst) {\n dst = dst || new QuatType(4);\n dst[0] = q[0];\n dst[1] = q[1];\n dst[2] = q[2];\n dst[3] = q[3];\n return dst;\n}\n/**\n * Clones a quaternion. (same as {@link quat.copy})\n * Also see {@link quat.create} and {@link quat.set}\n * @param q - The quaternion.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A copy of q.\n */\nconst clone$1 = copy$1;\n/**\n * Adds two quaternions; assumes a and b have the same dimension.\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the sum of a and b.\n */\nfunction add$1(a, b, dst) {\n dst = dst || new QuatType(4);\n dst[0] = a[0] + b[0];\n dst[1] = a[1] + b[1];\n dst[2] = a[2] + b[2];\n dst[3] = a[3] + b[3];\n return dst;\n}\n/**\n * Subtracts two quaternions.\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the difference of a and b.\n */\nfunction subtract$1(a, b, dst) {\n dst = dst || new QuatType(4);\n dst[0] = a[0] - b[0];\n dst[1] = a[1] - b[1];\n dst[2] = a[2] - b[2];\n dst[3] = a[3] - b[3];\n return dst;\n}\n/**\n * Subtracts two quaternions.\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns A quaternion that is the difference of a and b.\n */\nconst sub$1 = subtract$1;\n/**\n * Multiplies a quaternion by a scalar.\n * @param v - The quaternion.\n * @param k - The scalar.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The scaled quaternion.\n */\nfunction mulScalar$1(v, k, dst) {\n dst = dst || new QuatType(4);\n dst[0] = v[0] * k;\n dst[1] = v[1] * k;\n dst[2] = v[2] * k;\n dst[3] = v[3] * k;\n return dst;\n}\n/**\n * Multiplies a quaternion by a scalar. (same as mulScalar)\n * @param v - The quaternion.\n * @param k - The scalar.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The scaled quaternion.\n */\nconst scale$1 = mulScalar$1;\n/**\n * Divides a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The scaled quaternion.\n */\nfunction divScalar$1(v, k, dst) {\n dst = dst || new QuatType(4);\n dst[0] = v[0] / k;\n dst[1] = v[1] / k;\n dst[2] = v[2] / k;\n dst[3] = v[3] / k;\n return dst;\n}\n/**\n * Computes the dot product of two quaternions\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @returns dot product\n */\nfunction dot$1(a, b) {\n return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]);\n}\n/**\n * Performs linear interpolation on two quaternions.\n * Given quaternions a and b and interpolation coefficient t, returns\n * a + t * (b - a).\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @param t - Interpolation coefficient.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The linear interpolated result.\n */\nfunction lerp$1(a, b, t, dst) {\n dst = dst || new QuatType(4);\n dst[0] = a[0] + t * (b[0] - a[0]);\n dst[1] = a[1] + t * (b[1] - a[1]);\n dst[2] = a[2] + t * (b[2] - a[2]);\n dst[3] = a[3] + t * (b[3] - a[3]);\n return dst;\n}\n/**\n * Computes the length of quaternion\n * @param v - quaternion.\n * @returns length of quaternion.\n */\nfunction length$1(v) {\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const v3 = v[3];\n return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3);\n}\n/**\n * Computes the length of quaternion (same as length)\n * @param v - quaternion.\n * @returns length of quaternion.\n */\nconst len$1 = length$1;\n/**\n * Computes the square of the length of quaternion\n * @param v - quaternion.\n * @returns square of the length of quaternion.\n */\nfunction lengthSq$1(v) {\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const v3 = v[3];\n return v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3;\n}\n/**\n * Computes the square of the length of quaternion (same as lengthSq)\n * @param v - quaternion.\n * @returns square of the length of quaternion.\n */\nconst lenSq$1 = lengthSq$1;\n/**\n * Divides a quaternion by its Euclidean length and returns the quotient.\n * @param v - The quaternion.\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns The normalized quaternion.\n */\nfunction normalize$1(v, dst) {\n dst = dst || new QuatType(4);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const v3 = v[3];\n const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3);\n if (len > 0.00001) {\n dst[0] = v0 / len;\n dst[1] = v1 / len;\n dst[2] = v2 / len;\n dst[3] = v3 / len;\n }\n else {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n }\n return dst;\n}\n/**\n * Check if 2 quaternions are approximately equal\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @returns true if quaternions are approximately equal\n */\nfunction equalsApproximately$1(a, b) {\n return Math.abs(a[0] - b[0]) < EPSILON &&\n Math.abs(a[1] - b[1]) < EPSILON &&\n Math.abs(a[2] - b[2]) < EPSILON &&\n Math.abs(a[3] - b[3]) < EPSILON;\n}\n/**\n * Check if 2 quaternions are exactly equal\n * @param a - Operand quaternion.\n * @param b - Operand quaternion.\n * @returns true if quaternions are exactly equal\n */\nfunction equals$1(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Creates an identity quaternion\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns an identity quaternion\n */\nfunction identity(dst) {\n dst = dst || new QuatType(4);\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 1;\n return dst;\n}\nlet tempVec3;\nlet xUnitVec3;\nlet yUnitVec3;\n/**\n * Computes a quaternion to represent the shortest rotation from one vector to another.\n *\n * @param aUnit - the start vector\n * @param bUnit - the end vector\n * @param dst - quaternion to hold result. If not passed in a new one is created.\n * @returns the result\n */\nfunction rotationTo(aUnit, bUnit, dst) {\n dst = dst || new QuatType(4);\n tempVec3 = tempVec3 || create$4();\n xUnitVec3 = xUnitVec3 || create$4(1, 0, 0);\n yUnitVec3 = yUnitVec3 || create$4(0, 1, 0);\n const dot = dot$2(aUnit, bUnit);\n if (dot < -0.999999) {\n cross(xUnitVec3, aUnit, tempVec3);\n if (len$2(tempVec3) < 0.000001) {\n cross(yUnitVec3, aUnit, tempVec3);\n }\n normalize$2(tempVec3, tempVec3);\n fromAxisAngle(tempVec3, Math.PI, dst);\n return dst;\n }\n else if (dot > 0.999999) {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 1;\n return dst;\n }\n else {\n cross(aUnit, bUnit, tempVec3);\n dst[0] = tempVec3[0];\n dst[1] = tempVec3[1];\n dst[2] = tempVec3[2];\n dst[3] = 1 + dot;\n return normalize$1(dst, dst);\n }\n}\nlet tempQuat1;\nlet tempQuat2;\n/**\n * Performs a spherical linear interpolation with two control points\n *\n * @param a - the first quaternion\n * @param b - the second quaternion\n * @param c - the third quaternion\n * @param d - the fourth quaternion\n * @param t - Interpolation coefficient 0 to 1\n * @returns result\n */\nfunction sqlerp(a, b, c, d, t, dst) {\n dst = dst || new QuatType(4);\n tempQuat1 = tempQuat1 || new QuatType(4);\n tempQuat2 = tempQuat2 || new QuatType(4);\n slerp(a, d, t, tempQuat1);\n slerp(b, c, t, tempQuat2);\n slerp(tempQuat1, tempQuat2, 2 * t * (1 - t), dst);\n return dst;\n}\n\nvar quatImpl = /*#__PURE__*/Object.freeze({\n __proto__: null,\n add: add$1,\n angle: angle,\n clone: clone$1,\n conjugate: conjugate,\n copy: copy$1,\n create: create$1,\n divScalar: divScalar$1,\n dot: dot$1,\n equals: equals$1,\n equalsApproximately: equalsApproximately$1,\n fromAxisAngle: fromAxisAngle,\n fromEuler: fromEuler,\n fromMat: fromMat,\n fromValues: fromValues$1,\n identity: identity,\n inverse: inverse$1,\n len: len$1,\n lenSq: lenSq$1,\n length: length$1,\n lengthSq: lengthSq$1,\n lerp: lerp$1,\n mul: mul$1,\n mulScalar: mulScalar$1,\n multiply: multiply$1,\n normalize: normalize$1,\n rotateX: rotateX,\n rotateY: rotateY,\n rotateZ: rotateZ,\n rotationTo: rotationTo,\n scale: scale$1,\n set: set$1,\n setDefaultType: setDefaultType$2,\n slerp: slerp,\n sqlerp: sqlerp,\n sub: sub$1,\n subtract: subtract$1,\n toAxisAngle: toAxisAngle\n});\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n *\n * Vec4 math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new `Vec4`. In other words you can do this\n *\n * const v = vec4.cross(v1, v2); // Creates a new Vec4 with the cross product of v1 x v2.\n *\n * or\n *\n * const v = vec4.create();\n * vec4.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always safe to pass any vector as the destination. So for example\n *\n * vec4.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1\n *\n */\nlet VecType = Float32Array;\n/**\n * Sets the type this library creates for a Vec4\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n * @returns previous constructor for Vec4\n */\nfunction setDefaultType$1(ctor) {\n const oldType = VecType;\n VecType = ctor;\n return oldType;\n}\n/**\n * Creates a vec4; may be called with x, y, z to set initial values.\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @param z - Initial z value.\n * @param w - Initial w value.\n * @returns the created vector\n */\nfunction create(x, y, z, w) {\n const dst = new VecType(4);\n if (x !== undefined) {\n dst[0] = x;\n if (y !== undefined) {\n dst[1] = y;\n if (z !== undefined) {\n dst[2] = z;\n if (w !== undefined) {\n dst[3] = w;\n }\n }\n }\n }\n return dst;\n}\n\n/*\n * Copyright 2022 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n/**\n * Creates a vec4; may be called with x, y, z to set initial values. (same as create)\n * @param x - Initial x value.\n * @param y - Initial y value.\n * @param z - Initial z value.\n * @param z - Initial w value.\n * @returns the created vector\n */\nconst fromValues = create;\n/**\n * Sets the values of a Vec4\n * Also see {@link vec4.create} and {@link vec4.copy}\n *\n * @param x first value\n * @param y second value\n * @param z third value\n * @param w fourth value\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector with its elements set.\n */\nfunction set(x, y, z, w, dst) {\n dst = dst || new VecType(4);\n dst[0] = x;\n dst[1] = y;\n dst[2] = z;\n dst[3] = w;\n return dst;\n}\n/**\n * Applies Math.ceil to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the ceil of each element of v.\n */\nfunction ceil(v, dst) {\n dst = dst || new VecType(4);\n dst[0] = Math.ceil(v[0]);\n dst[1] = Math.ceil(v[1]);\n dst[2] = Math.ceil(v[2]);\n dst[3] = Math.ceil(v[3]);\n return dst;\n}\n/**\n * Applies Math.floor to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the floor of each element of v.\n */\nfunction floor(v, dst) {\n dst = dst || new VecType(4);\n dst[0] = Math.floor(v[0]);\n dst[1] = Math.floor(v[1]);\n dst[2] = Math.floor(v[2]);\n dst[3] = Math.floor(v[3]);\n return dst;\n}\n/**\n * Applies Math.round to each element of vector\n * @param v - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the round of each element of v.\n */\nfunction round(v, dst) {\n dst = dst || new VecType(4);\n dst[0] = Math.round(v[0]);\n dst[1] = Math.round(v[1]);\n dst[2] = Math.round(v[2]);\n dst[3] = Math.round(v[3]);\n return dst;\n}\n/**\n * Clamp each element of vector between min and max\n * @param v - Operand vector.\n * @param max - Min value, default 0\n * @param min - Max value, default 1\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that the clamped value of each element of v.\n */\nfunction clamp(v, min = 0, max = 1, dst) {\n dst = dst || new VecType(4);\n dst[0] = Math.min(max, Math.max(min, v[0]));\n dst[1] = Math.min(max, Math.max(min, v[1]));\n dst[2] = Math.min(max, Math.max(min, v[2]));\n dst[3] = Math.min(max, Math.max(min, v[3]));\n return dst;\n}\n/**\n * Adds two vectors; assumes a and b have the same dimension.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the sum of a and b.\n */\nfunction add(a, b, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] + b[0];\n dst[1] = a[1] + b[1];\n dst[2] = a[2] + b[2];\n dst[3] = a[3] + b[3];\n return dst;\n}\n/**\n * Adds two vectors, scaling the 2nd; assumes a and b have the same dimension.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param scale - Amount to scale b\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the sum of a + b * scale.\n */\nfunction addScaled(a, b, scale, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] + b[0] * scale;\n dst[1] = a[1] + b[1] * scale;\n dst[2] = a[2] + b[2] * scale;\n dst[3] = a[3] + b[3] * scale;\n return dst;\n}\n/**\n * Subtracts two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the difference of a and b.\n */\nfunction subtract(a, b, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] - b[0];\n dst[1] = a[1] - b[1];\n dst[2] = a[2] - b[2];\n dst[3] = a[3] - b[3];\n return dst;\n}\n/**\n * Subtracts two vectors.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A vector that is the difference of a and b.\n */\nconst sub = subtract;\n/**\n * Check if 2 vectors are approximately equal\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns true if vectors are approximately equal\n */\nfunction equalsApproximately(a, b) {\n return Math.abs(a[0] - b[0]) < EPSILON &&\n Math.abs(a[1] - b[1]) < EPSILON &&\n Math.abs(a[2] - b[2]) < EPSILON &&\n Math.abs(a[3] - b[3]) < EPSILON;\n}\n/**\n * Check if 2 vectors are exactly equal\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns true if vectors are exactly equal\n */\nfunction equals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient t, returns\n * a + t * (b - a).\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param t - Interpolation coefficient.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The linear interpolated result.\n */\nfunction lerp(a, b, t, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] + t * (b[0] - a[0]);\n dst[1] = a[1] + t * (b[1] - a[1]);\n dst[2] = a[2] + t * (b[2] - a[2]);\n dst[3] = a[3] + t * (b[3] - a[3]);\n return dst;\n}\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient vector t, returns\n * a + t * (b - a).\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param t - Interpolation coefficients vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns the linear interpolated result.\n */\nfunction lerpV(a, b, t, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] + t[0] * (b[0] - a[0]);\n dst[1] = a[1] + t[1] * (b[1] - a[1]);\n dst[2] = a[2] + t[2] * (b[2] - a[2]);\n dst[3] = a[3] + t[3] * (b[3] - a[3]);\n return dst;\n}\n/**\n * Return max values of two vectors.\n * Given vectors a and b returns\n * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The max components vector.\n */\nfunction max(a, b, dst) {\n dst = dst || new VecType(4);\n dst[0] = Math.max(a[0], b[0]);\n dst[1] = Math.max(a[1], b[1]);\n dst[2] = Math.max(a[2], b[2]);\n dst[3] = Math.max(a[3], b[3]);\n return dst;\n}\n/**\n * Return min values of two vectors.\n * Given vectors a and b returns\n * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The min components vector.\n */\nfunction min(a, b, dst) {\n dst = dst || new VecType(4);\n dst[0] = Math.min(a[0], b[0]);\n dst[1] = Math.min(a[1], b[1]);\n dst[2] = Math.min(a[2], b[2]);\n dst[3] = Math.min(a[3], b[3]);\n return dst;\n}\n/**\n * Multiplies a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nfunction mulScalar(v, k, dst) {\n dst = dst || new VecType(4);\n dst[0] = v[0] * k;\n dst[1] = v[1] * k;\n dst[2] = v[2] * k;\n dst[3] = v[3] * k;\n return dst;\n}\n/**\n * Multiplies a vector by a scalar. (same as mulScalar)\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nconst scale = mulScalar;\n/**\n * Divides a vector by a scalar.\n * @param v - The vector.\n * @param k - The scalar.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The scaled vector.\n */\nfunction divScalar(v, k, dst) {\n dst = dst || new VecType(4);\n dst[0] = v[0] / k;\n dst[1] = v[1] / k;\n dst[2] = v[2] / k;\n dst[3] = v[3] / k;\n return dst;\n}\n/**\n * Inverse a vector.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The inverted vector.\n */\nfunction inverse(v, dst) {\n dst = dst || new VecType(4);\n dst[0] = 1 / v[0];\n dst[1] = 1 / v[1];\n dst[2] = 1 / v[2];\n dst[3] = 1 / v[3];\n return dst;\n}\n/**\n * Invert a vector. (same as inverse)\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The inverted vector.\n */\nconst invert = inverse;\n/**\n * Computes the dot product of two vectors\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @returns dot product\n */\nfunction dot(a, b) {\n return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]);\n}\n/**\n * Computes the length of vector\n * @param v - vector.\n * @returns length of vector.\n */\nfunction length(v) {\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const v3 = v[3];\n return Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3);\n}\n/**\n * Computes the length of vector (same as length)\n * @param v - vector.\n * @returns length of vector.\n */\nconst len = length;\n/**\n * Computes the square of the length of vector\n * @param v - vector.\n * @returns square of the length of vector.\n */\nfunction lengthSq(v) {\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const v3 = v[3];\n return v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3;\n}\n/**\n * Computes the square of the length of vector (same as lengthSq)\n * @param v - vector.\n * @returns square of the length of vector.\n */\nconst lenSq = lengthSq;\n/**\n * Computes the distance between 2 points\n * @param a - vector.\n * @param b - vector.\n * @returns distance between a and b\n */\nfunction distance(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n const dz = a[2] - b[2];\n const dw = a[3] - b[3];\n return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);\n}\n/**\n * Computes the distance between 2 points (same as distance)\n * @param a - vector.\n * @param b - vector.\n * @returns distance between a and b\n */\nconst dist = distance;\n/**\n * Computes the square of the distance between 2 points\n * @param a - vector.\n * @param b - vector.\n * @returns square of the distance between a and b\n */\nfunction distanceSq(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n const dz = a[2] - b[2];\n const dw = a[3] - b[3];\n return dx * dx + dy * dy + dz * dz + dw * dw;\n}\n/**\n * Computes the square of the distance between 2 points (same as distanceSq)\n * @param a - vector.\n * @param b - vector.\n * @returns square of the distance between a and b\n */\nconst distSq = distanceSq;\n/**\n * Divides a vector by its Euclidean length and returns the quotient.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The normalized vector.\n */\nfunction normalize(v, dst) {\n dst = dst || new VecType(4);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const v3 = v[3];\n const len = Math.sqrt(v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3);\n if (len > 0.00001) {\n dst[0] = v0 / len;\n dst[1] = v1 / len;\n dst[2] = v2 / len;\n dst[3] = v3 / len;\n }\n else {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n }\n return dst;\n}\n/**\n * Negates a vector.\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns -v.\n */\nfunction negate(v, dst) {\n dst = dst || new VecType(4);\n dst[0] = -v[0];\n dst[1] = -v[1];\n dst[2] = -v[2];\n dst[3] = -v[3];\n return dst;\n}\n/**\n * Copies a vector. (same as {@link vec4.clone})\n * Also see {@link vec4.create} and {@link vec4.set}\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A copy of v.\n */\nfunction copy(v, dst) {\n dst = dst || new VecType(4);\n dst[0] = v[0];\n dst[1] = v[1];\n dst[2] = v[2];\n dst[3] = v[3];\n return dst;\n}\n/**\n * Clones a vector. (same as {@link vec4.copy})\n * Also see {@link vec4.create} and {@link vec4.set}\n * @param v - The vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns A copy of v.\n */\nconst clone = copy;\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of products of entries of a and b.\n */\nfunction multiply(a, b, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] * b[0];\n dst[1] = a[1] * b[1];\n dst[2] = a[2] * b[2];\n dst[3] = a[3] * b[3];\n return dst;\n}\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length. (same as mul)\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of products of entries of a and b.\n */\nconst mul = multiply;\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of quotients of entries of a and b.\n */\nfunction divide(a, b, dst) {\n dst = dst || new VecType(4);\n dst[0] = a[0] / b[0];\n dst[1] = a[1] / b[1];\n dst[2] = a[2] / b[2];\n dst[3] = a[3] / b[3];\n return dst;\n}\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length. (same as divide)\n * @param a - Operand vector.\n * @param b - Operand vector.\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The vector of quotients of entries of a and b.\n */\nconst div = divide;\n/**\n * Zero's a vector\n * @param dst - vector to hold result. If not passed in a new one is created.\n * @returns The zeroed vector.\n */\nfunction zero(dst) {\n dst = dst || new VecType(4);\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n return dst;\n}\n/**\n * transform vec4 by 4x4 matrix\n * @param v - the vector\n * @param m - The matrix.\n * @param dst - optional vec4 to store result. If not passed a new one is created.\n * @returns the transformed vector\n */\nfunction transformMat4(v, m, dst) {\n dst = dst || new VecType(4);\n const x = v[0];\n const y = v[1];\n const z = v[2];\n const w = v[3];\n dst[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n dst[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n dst[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n dst[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n return dst;\n}\n/**\n * Treat a 4D vector as a direction and set it's length\n *\n * @param a The vec4 to lengthen\n * @param len The length of the resulting vector\n * @returns The lengthened vector\n */\nfunction setLength(a, len, dst) {\n dst = dst || new VecType(4);\n normalize(a, dst);\n return mulScalar(dst, len, dst);\n}\n/**\n * Ensure a vector is not longer than a max length\n *\n * @param a The vec4 to limit\n * @param maxLen The longest length of the resulting vector\n * @returns The vector, shortened to maxLen if it's too long\n */\nfunction truncate(a, maxLen, dst) {\n dst = dst || new VecType(4);\n if (length(a) > maxLen) {\n return setLength(a, maxLen, dst);\n }\n return copy(a, dst);\n}\n/**\n * Return the vector exactly between 2 endpoint vectors\n *\n * @param a Endpoint 1\n * @param b Endpoint 2\n * @returns The vector exactly residing between endpoints 1 and 2\n */\nfunction midpoint(a, b, dst) {\n dst = dst || new VecType(4);\n return lerp(a, b, 0.5, dst);\n}\n\nvar vec4Impl = /*#__PURE__*/Object.freeze({\n __proto__: null,\n add: add,\n addScaled: addScaled,\n ceil: ceil,\n clamp: clamp,\n clone: clone,\n copy: copy,\n create: create,\n dist: dist,\n distSq: distSq,\n distance: distance,\n distanceSq: distanceSq,\n div: div,\n divScalar: divScalar,\n divide: divide,\n dot: dot,\n equals: equals,\n equalsApproximately: equalsApproximately,\n floor: floor,\n fromValues: fromValues,\n inverse: inverse,\n invert: invert,\n len: len,\n lenSq: lenSq,\n length: length,\n lengthSq: lengthSq,\n lerp: lerp,\n lerpV: lerpV,\n max: max,\n midpoint: midpoint,\n min: min,\n mul: mul,\n mulScalar: mulScalar,\n multiply: multiply,\n negate: negate,\n normalize: normalize,\n round: round,\n scale: scale,\n set: set,\n setDefaultType: setDefaultType$1,\n setLength: setLength,\n sub: sub,\n subtract: subtract,\n transformMat4: transformMat4,\n truncate: truncate,\n zero: zero\n});\n\n/**\n * Sets the type this library creates for all types\n *\n * example:\n *\n * ```\n * setDefaultType(Float64Array);\n * ```\n *\n * @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`\n */\nfunction setDefaultType(ctor) {\n setDefaultType$4(ctor);\n setDefaultType$3(ctor);\n setDefaultType$2(ctor);\n setDefaultType$6(ctor);\n setDefaultType$5(ctor);\n setDefaultType$1(ctor);\n}\n\nexport { mat3Impl as mat3, mat4Impl as mat4, quatImpl as quat, setDefaultType, utils, vec2Impl as vec2, vec3Impl as vec3, vec4Impl as vec4 };\n//# sourceMappingURL=wgpu-matrix.module.js.map\n","/**\n * dat-gui JavaScript Controller Library\n * https://github.com/dataarts/dat.gui\n *\n * Copyright 2011 Data Arts Team, Google Creative Lab\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n */\n\nfunction ___$insertStyle(css) {\n if (!css) {\n return;\n }\n if (typeof window === 'undefined') {\n return;\n }\n\n var style = document.createElement('style');\n\n style.setAttribute('type', 'text/css');\n style.innerHTML = css;\n document.head.appendChild(style);\n\n return css;\n}\n\nfunction colorToString (color, forceCSSHex) {\n var colorFormat = color.__state.conversionName.toString();\n var r = Math.round(color.r);\n var g = Math.round(color.g);\n var b = Math.round(color.b);\n var a = color.a;\n var h = Math.round(color.h);\n var s = color.s.toFixed(1);\n var v = color.v.toFixed(1);\n if (forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX') {\n var str = color.hex.toString(16);\n while (str.length < 6) {\n str = '0' + str;\n }\n return '#' + str;\n } else if (colorFormat === 'CSS_RGB') {\n return 'rgb(' + r + ',' + g + ',' + b + ')';\n } else if (colorFormat === 'CSS_RGBA') {\n return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';\n } else if (colorFormat === 'HEX') {\n return '0x' + color.hex.toString(16);\n } else if (colorFormat === 'RGB_ARRAY') {\n return '[' + r + ',' + g + ',' + b + ']';\n } else if (colorFormat === 'RGBA_ARRAY') {\n return '[' + r + ',' + g + ',' + b + ',' + a + ']';\n } else if (colorFormat === 'RGB_OBJ') {\n return '{r:' + r + ',g:' + g + ',b:' + b + '}';\n } else if (colorFormat === 'RGBA_OBJ') {\n return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}';\n } else if (colorFormat === 'HSV_OBJ') {\n return '{h:' + h + ',s:' + s + ',v:' + v + '}';\n } else if (colorFormat === 'HSVA_OBJ') {\n return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}';\n }\n return 'unknown format';\n}\n\nvar ARR_EACH = Array.prototype.forEach;\nvar ARR_SLICE = Array.prototype.slice;\nvar Common = {\n BREAK: {},\n extend: function extend(target) {\n this.each(ARR_SLICE.call(arguments, 1), function (obj) {\n var keys = this.isObject(obj) ? Object.keys(obj) : [];\n keys.forEach(function (key) {\n if (!this.isUndefined(obj[key])) {\n target[key] = obj[key];\n }\n }.bind(this));\n }, this);\n return target;\n },\n defaults: function defaults(target) {\n this.each(ARR_SLICE.call(arguments, 1), function (obj) {\n var keys = this.isObject(obj) ? Object.keys(obj) : [];\n keys.forEach(function (key) {\n if (this.isUndefined(target[key])) {\n target[key] = obj[key];\n }\n }.bind(this));\n }, this);\n return target;\n },\n compose: function compose() {\n var toCall = ARR_SLICE.call(arguments);\n return function () {\n var args = ARR_SLICE.call(arguments);\n for (var i = toCall.length - 1; i >= 0; i--) {\n args = [toCall[i].apply(this, args)];\n }\n return args[0];\n };\n },\n each: function each(obj, itr, scope) {\n if (!obj) {\n return;\n }\n if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {\n obj.forEach(itr, scope);\n } else if (obj.length === obj.length + 0) {\n var key = void 0;\n var l = void 0;\n for (key = 0, l = obj.length; key < l; key++) {\n if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {\n return;\n }\n }\n } else {\n for (var _key in obj) {\n if (itr.call(scope, obj[_key], _key) === this.BREAK) {\n return;\n }\n }\n }\n },\n defer: function defer(fnc) {\n setTimeout(fnc, 0);\n },\n debounce: function debounce(func, threshold, callImmediately) {\n var timeout = void 0;\n return function () {\n var obj = this;\n var args = arguments;\n function delayed() {\n timeout = null;\n if (!callImmediately) func.apply(obj, args);\n }\n var callNow = callImmediately || !timeout;\n clearTimeout(timeout);\n timeout = setTimeout(delayed, threshold);\n if (callNow) {\n func.apply(obj, args);\n }\n };\n },\n toArray: function toArray(obj) {\n if (obj.toArray) return obj.toArray();\n return ARR_SLICE.call(obj);\n },\n isUndefined: function isUndefined(obj) {\n return obj === undefined;\n },\n isNull: function isNull(obj) {\n return obj === null;\n },\n isNaN: function (_isNaN) {\n function isNaN(_x) {\n return _isNaN.apply(this, arguments);\n }\n isNaN.toString = function () {\n return _isNaN.toString();\n };\n return isNaN;\n }(function (obj) {\n return isNaN(obj);\n }),\n isArray: Array.isArray || function (obj) {\n return obj.constructor === Array;\n },\n isObject: function isObject(obj) {\n return obj === Object(obj);\n },\n isNumber: function isNumber(obj) {\n return obj === obj + 0;\n },\n isString: function isString(obj) {\n return obj === obj + '';\n },\n isBoolean: function isBoolean(obj) {\n return obj === false || obj === true;\n },\n isFunction: function isFunction(obj) {\n return obj instanceof Function;\n }\n};\n\nvar INTERPRETATIONS = [\n{\n litmus: Common.isString,\n conversions: {\n THREE_CHAR_HEX: {\n read: function read(original) {\n var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);\n if (test === null) {\n return false;\n }\n return {\n space: 'HEX',\n hex: parseInt('0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString(), 0)\n };\n },\n write: colorToString\n },\n SIX_CHAR_HEX: {\n read: function read(original) {\n var test = original.match(/^#([A-F0-9]{6})$/i);\n if (test === null) {\n return false;\n }\n return {\n space: 'HEX',\n hex: parseInt('0x' + test[1].toString(), 0)\n };\n },\n write: colorToString\n },\n CSS_RGB: {\n read: function read(original) {\n var test = original.match(/^rgb\\(\\s*(\\S+)\\s*,\\s*(\\S+)\\s*,\\s*(\\S+)\\s*\\)/);\n if (test === null) {\n return false;\n }\n return {\n space: 'RGB',\n r: parseFloat(test[1]),\n g: parseFloat(test[2]),\n b: parseFloat(test[3])\n };\n },\n write: colorToString\n },\n CSS_RGBA: {\n read: function read(original) {\n var test = original.match(/^rgba\\(\\s*(\\S+)\\s*,\\s*(\\S+)\\s*,\\s*(\\S+)\\s*,\\s*(\\S+)\\s*\\)/);\n if (test === null) {\n return false;\n }\n return {\n space: 'RGB',\n r: parseFloat(test[1]),\n g: parseFloat(test[2]),\n b: parseFloat(test[3]),\n a: parseFloat(test[4])\n };\n },\n write: colorToString\n }\n }\n},\n{\n litmus: Common.isNumber,\n conversions: {\n HEX: {\n read: function read(original) {\n return {\n space: 'HEX',\n hex: original,\n conversionName: 'HEX'\n };\n },\n write: function write(color) {\n return color.hex;\n }\n }\n }\n},\n{\n litmus: Common.isArray,\n conversions: {\n RGB_ARRAY: {\n read: function read(original) {\n if (original.length !== 3) {\n return false;\n }\n return {\n space: 'RGB',\n r: original[0],\n g: original[1],\n b: original[2]\n };\n },\n write: function write(color) {\n return [color.r, color.g, color.b];\n }\n },\n RGBA_ARRAY: {\n read: function read(original) {\n if (original.length !== 4) return false;\n return {\n space: 'RGB',\n r: original[0],\n g: original[1],\n b: original[2],\n a: original[3]\n };\n },\n write: function write(color) {\n return [color.r, color.g, color.b, color.a];\n }\n }\n }\n},\n{\n litmus: Common.isObject,\n conversions: {\n RGBA_OBJ: {\n read: function read(original) {\n if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b) && Common.isNumber(original.a)) {\n return {\n space: 'RGB',\n r: original.r,\n g: original.g,\n b: original.b,\n a: original.a\n };\n }\n return false;\n },\n write: function write(color) {\n return {\n r: color.r,\n g: color.g,\n b: color.b,\n a: color.a\n };\n }\n },\n RGB_OBJ: {\n read: function read(original) {\n if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b)) {\n return {\n space: 'RGB',\n r: original.r,\n g: original.g,\n b: original.b\n };\n }\n return false;\n },\n write: function write(color) {\n return {\n r: color.r,\n g: color.g,\n b: color.b\n };\n }\n },\n HSVA_OBJ: {\n read: function read(original) {\n if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v) && Common.isNumber(original.a)) {\n return {\n space: 'HSV',\n h: original.h,\n s: original.s,\n v: original.v,\n a: original.a\n };\n }\n return false;\n },\n write: function write(color) {\n return {\n h: color.h,\n s: color.s,\n v: color.v,\n a: color.a\n };\n }\n },\n HSV_OBJ: {\n read: function read(original) {\n if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v)) {\n return {\n space: 'HSV',\n h: original.h,\n s: original.s,\n v: original.v\n };\n }\n return false;\n },\n write: function write(color) {\n return {\n h: color.h,\n s: color.s,\n v: color.v\n };\n }\n }\n }\n}];\nvar result = void 0;\nvar toReturn = void 0;\nvar interpret = function interpret() {\n toReturn = false;\n var original = arguments.length > 1 ? Common.toArray(arguments) : arguments[0];\n Common.each(INTERPRETATIONS, function (family) {\n if (family.litmus(original)) {\n Common.each(family.conversions, function (conversion, conversionName) {\n result = conversion.read(original);\n if (toReturn === false && result !== false) {\n toReturn = result;\n result.conversionName = conversionName;\n result.conversion = conversion;\n return Common.BREAK;\n }\n });\n return Common.BREAK;\n }\n });\n return toReturn;\n};\n\nvar tmpComponent = void 0;\nvar ColorMath = {\n hsv_to_rgb: function hsv_to_rgb(h, s, v) {\n var hi = Math.floor(h / 60) % 6;\n var f = h / 60 - Math.floor(h / 60);\n var p = v * (1.0 - s);\n var q = v * (1.0 - f * s);\n var t = v * (1.0 - (1.0 - f) * s);\n var c = [[v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q]][hi];\n return {\n r: c[0] * 255,\n g: c[1] * 255,\n b: c[2] * 255\n };\n },\n rgb_to_hsv: function rgb_to_hsv(r, g, b) {\n var min = Math.min(r, g, b);\n var max = Math.max(r, g, b);\n var delta = max - min;\n var h = void 0;\n var s = void 0;\n if (max !== 0) {\n s = delta / max;\n } else {\n return {\n h: NaN,\n s: 0,\n v: 0\n };\n }\n if (r === max) {\n h = (g - b) / delta;\n } else if (g === max) {\n h = 2 + (b - r) / delta;\n } else {\n h = 4 + (r - g) / delta;\n }\n h /= 6;\n if (h < 0) {\n h += 1;\n }\n return {\n h: h * 360,\n s: s,\n v: max / 255\n };\n },\n rgb_to_hex: function rgb_to_hex(r, g, b) {\n var hex = this.hex_with_component(0, 2, r);\n hex = this.hex_with_component(hex, 1, g);\n hex = this.hex_with_component(hex, 0, b);\n return hex;\n },\n component_from_hex: function component_from_hex(hex, componentIndex) {\n return hex >> componentIndex * 8 & 0xFF;\n },\n hex_with_component: function hex_with_component(hex, componentIndex, value) {\n return value << (tmpComponent = componentIndex * 8) | hex & ~(0xFF << tmpComponent);\n }\n};\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) {\n return typeof obj;\n} : function (obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n};\n\n\n\n\n\n\n\n\n\n\n\nvar classCallCheck = function (instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n};\n\nvar createClass = function () {\n function defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n }\n\n return function (Constructor, protoProps, staticProps) {\n if (protoProps) defineProperties(Constructor.prototype, protoProps);\n if (staticProps) defineProperties(Constructor, staticProps);\n return Constructor;\n };\n}();\n\n\n\n\n\n\n\nvar get = function get(object, property, receiver) {\n if (object === null) object = Function.prototype;\n var desc = Object.getOwnPropertyDescriptor(object, property);\n\n if (desc === undefined) {\n var parent = Object.getPrototypeOf(object);\n\n if (parent === null) {\n return undefined;\n } else {\n return get(parent, property, receiver);\n }\n } else if (\"value\" in desc) {\n return desc.value;\n } else {\n var getter = desc.get;\n\n if (getter === undefined) {\n return undefined;\n }\n\n return getter.call(receiver);\n }\n};\n\nvar inherits = function (subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass);\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;\n};\n\n\n\n\n\n\n\n\n\n\n\nvar possibleConstructorReturn = function (self, call) {\n if (!self) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self;\n};\n\nvar Color = function () {\n function Color() {\n classCallCheck(this, Color);\n this.__state = interpret.apply(this, arguments);\n if (this.__state === false) {\n throw new Error('Failed to interpret color arguments');\n }\n this.__state.a = this.__state.a || 1;\n }\n createClass(Color, [{\n key: 'toString',\n value: function toString() {\n return colorToString(this);\n }\n }, {\n key: 'toHexString',\n value: function toHexString() {\n return colorToString(this, true);\n }\n }, {\n key: 'toOriginal',\n value: function toOriginal() {\n return this.__state.conversion.write(this);\n }\n }]);\n return Color;\n}();\nfunction defineRGBComponent(target, component, componentHexIndex) {\n Object.defineProperty(target, component, {\n get: function get$$1() {\n if (this.__state.space === 'RGB') {\n return this.__state[component];\n }\n Color.recalculateRGB(this, component, componentHexIndex);\n return this.__state[component];\n },\n set: function set$$1(v) {\n if (this.__state.space !== 'RGB') {\n Color.recalculateRGB(this, component, componentHexIndex);\n this.__state.space = 'RGB';\n }\n this.__state[component] = v;\n }\n });\n}\nfunction defineHSVComponent(target, component) {\n Object.defineProperty(target, component, {\n get: function get$$1() {\n if (this.__state.space === 'HSV') {\n return this.__state[component];\n }\n Color.recalculateHSV(this);\n return this.__state[component];\n },\n set: function set$$1(v) {\n if (this.__state.space !== 'HSV') {\n Color.recalculateHSV(this);\n this.__state.space = 'HSV';\n }\n this.__state[component] = v;\n }\n });\n}\nColor.recalculateRGB = function (color, component, componentHexIndex) {\n if (color.__state.space === 'HEX') {\n color.__state[component] = ColorMath.component_from_hex(color.__state.hex, componentHexIndex);\n } else if (color.__state.space === 'HSV') {\n Common.extend(color.__state, ColorMath.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v));\n } else {\n throw new Error('Corrupted color state');\n }\n};\nColor.recalculateHSV = function (color) {\n var result = ColorMath.rgb_to_hsv(color.r, color.g, color.b);\n Common.extend(color.__state, {\n s: result.s,\n v: result.v\n });\n if (!Common.isNaN(result.h)) {\n color.__state.h = result.h;\n } else if (Common.isUndefined(color.__state.h)) {\n color.__state.h = 0;\n }\n};\nColor.COMPONENTS = ['r', 'g', 'b', 'h', 's', 'v', 'hex', 'a'];\ndefineRGBComponent(Color.prototype, 'r', 2);\ndefineRGBComponent(Color.prototype, 'g', 1);\ndefineRGBComponent(Color.prototype, 'b', 0);\ndefineHSVComponent(Color.prototype, 'h');\ndefineHSVComponent(Color.prototype, 's');\ndefineHSVComponent(Color.prototype, 'v');\nObject.defineProperty(Color.prototype, 'a', {\n get: function get$$1() {\n return this.__state.a;\n },\n set: function set$$1(v) {\n this.__state.a = v;\n }\n});\nObject.defineProperty(Color.prototype, 'hex', {\n get: function get$$1() {\n if (this.__state.space !== 'HEX') {\n this.__state.hex = ColorMath.rgb_to_hex(this.r, this.g, this.b);\n this.__state.space = 'HEX';\n }\n return this.__state.hex;\n },\n set: function set$$1(v) {\n this.__state.space = 'HEX';\n this.__state.hex = v;\n }\n});\n\nvar Controller = function () {\n function Controller(object, property) {\n classCallCheck(this, Controller);\n this.initialValue = object[property];\n this.domElement = document.createElement('div');\n this.object = object;\n this.property = property;\n this.__onChange = undefined;\n this.__onFinishChange = undefined;\n }\n createClass(Controller, [{\n key: 'onChange',\n value: function onChange(fnc) {\n this.__onChange = fnc;\n return this;\n }\n }, {\n key: 'onFinishChange',\n value: function onFinishChange(fnc) {\n this.__onFinishChange = fnc;\n return this;\n }\n }, {\n key: 'setValue',\n value: function setValue(newValue) {\n this.object[this.property] = newValue;\n if (this.__onChange) {\n this.__onChange.call(this, newValue);\n }\n this.updateDisplay();\n return this;\n }\n }, {\n key: 'getValue',\n value: function getValue() {\n return this.object[this.property];\n }\n }, {\n key: 'updateDisplay',\n value: function updateDisplay() {\n return this;\n }\n }, {\n key: 'isModified',\n value: function isModified() {\n return this.initialValue !== this.getValue();\n }\n }]);\n return Controller;\n}();\n\nvar EVENT_MAP = {\n HTMLEvents: ['change'],\n MouseEvents: ['click', 'mousemove', 'mousedown', 'mouseup', 'mouseover'],\n KeyboardEvents: ['keydown']\n};\nvar EVENT_MAP_INV = {};\nCommon.each(EVENT_MAP, function (v, k) {\n Common.each(v, function (e) {\n EVENT_MAP_INV[e] = k;\n });\n});\nvar CSS_VALUE_PIXELS = /(\\d+(\\.\\d+)?)px/;\nfunction cssValueToPixels(val) {\n if (val === '0' || Common.isUndefined(val)) {\n return 0;\n }\n var match = val.match(CSS_VALUE_PIXELS);\n if (!Common.isNull(match)) {\n return parseFloat(match[1]);\n }\n return 0;\n}\nvar dom = {\n makeSelectable: function makeSelectable(elem, selectable) {\n if (elem === undefined || elem.style === undefined) return;\n elem.onselectstart = selectable ? function () {\n return false;\n } : function () {};\n elem.style.MozUserSelect = selectable ? 'auto' : 'none';\n elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none';\n elem.unselectable = selectable ? 'on' : 'off';\n },\n makeFullscreen: function makeFullscreen(elem, hor, vert) {\n var vertical = vert;\n var horizontal = hor;\n if (Common.isUndefined(horizontal)) {\n horizontal = true;\n }\n if (Common.isUndefined(vertical)) {\n vertical = true;\n }\n elem.style.position = 'absolute';\n if (horizontal) {\n elem.style.left = 0;\n elem.style.right = 0;\n }\n if (vertical) {\n elem.style.top = 0;\n elem.style.bottom = 0;\n }\n },\n fakeEvent: function fakeEvent(elem, eventType, pars, aux) {\n var params = pars || {};\n var className = EVENT_MAP_INV[eventType];\n if (!className) {\n throw new Error('Event type ' + eventType + ' not supported.');\n }\n var evt = document.createEvent(className);\n switch (className) {\n case 'MouseEvents':\n {\n var clientX = params.x || params.clientX || 0;\n var clientY = params.y || params.clientY || 0;\n evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0,\n 0,\n clientX,\n clientY,\n false, false, false, false, 0, null);\n break;\n }\n case 'KeyboardEvents':\n {\n var init = evt.initKeyboardEvent || evt.initKeyEvent;\n Common.defaults(params, {\n cancelable: true,\n ctrlKey: false,\n altKey: false,\n shiftKey: false,\n metaKey: false,\n keyCode: undefined,\n charCode: undefined\n });\n init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode);\n break;\n }\n default:\n {\n evt.initEvent(eventType, params.bubbles || false, params.cancelable || true);\n break;\n }\n }\n Common.defaults(evt, aux);\n elem.dispatchEvent(evt);\n },\n bind: function bind(elem, event, func, newBool) {\n var bool = newBool || false;\n if (elem.addEventListener) {\n elem.addEventListener(event, func, bool);\n } else if (elem.attachEvent) {\n elem.attachEvent('on' + event, func);\n }\n return dom;\n },\n unbind: function unbind(elem, event, func, newBool) {\n var bool = newBool || false;\n if (elem.removeEventListener) {\n elem.removeEventListener(event, func, bool);\n } else if (elem.detachEvent) {\n elem.detachEvent('on' + event, func);\n }\n return dom;\n },\n addClass: function addClass(elem, className) {\n if (elem.className === undefined) {\n elem.className = className;\n } else if (elem.className !== className) {\n var classes = elem.className.split(/ +/);\n if (classes.indexOf(className) === -1) {\n classes.push(className);\n elem.className = classes.join(' ').replace(/^\\s+/, '').replace(/\\s+$/, '');\n }\n }\n return dom;\n },\n removeClass: function removeClass(elem, className) {\n if (className) {\n if (elem.className === className) {\n elem.removeAttribute('class');\n } else {\n var classes = elem.className.split(/ +/);\n var index = classes.indexOf(className);\n if (index !== -1) {\n classes.splice(index, 1);\n elem.className = classes.join(' ');\n }\n }\n } else {\n elem.className = undefined;\n }\n return dom;\n },\n hasClass: function hasClass(elem, className) {\n return new RegExp('(?:^|\\\\s+)' + className + '(?:\\\\s+|$)').test(elem.className) || false;\n },\n getWidth: function getWidth(elem) {\n var style = getComputedStyle(elem);\n return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style.width);\n },\n getHeight: function getHeight(elem) {\n var style = getComputedStyle(elem);\n return cssValueToPixels(style['border-top-width']) + cssValueToPixels(style['border-bottom-width']) + cssValueToPixels(style['padding-top']) + cssValueToPixels(style['padding-bottom']) + cssValueToPixels(style.height);\n },\n getOffset: function getOffset(el) {\n var elem = el;\n var offset = { left: 0, top: 0 };\n if (elem.offsetParent) {\n do {\n offset.left += elem.offsetLeft;\n offset.top += elem.offsetTop;\n elem = elem.offsetParent;\n } while (elem);\n }\n return offset;\n },\n isActive: function isActive(elem) {\n return elem === document.activeElement && (elem.type || elem.href);\n }\n};\n\nvar BooleanController = function (_Controller) {\n inherits(BooleanController, _Controller);\n function BooleanController(object, property) {\n classCallCheck(this, BooleanController);\n var _this2 = possibleConstructorReturn(this, (BooleanController.__proto__ || Object.getPrototypeOf(BooleanController)).call(this, object, property));\n var _this = _this2;\n _this2.__prev = _this2.getValue();\n _this2.__checkbox = document.createElement('input');\n _this2.__checkbox.setAttribute('type', 'checkbox');\n function onChange() {\n _this.setValue(!_this.__prev);\n }\n dom.bind(_this2.__checkbox, 'change', onChange, false);\n _this2.domElement.appendChild(_this2.__checkbox);\n _this2.updateDisplay();\n return _this2;\n }\n createClass(BooleanController, [{\n key: 'setValue',\n value: function setValue(v) {\n var toReturn = get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'setValue', this).call(this, v);\n if (this.__onFinishChange) {\n this.__onFinishChange.call(this, this.getValue());\n }\n this.__prev = this.getValue();\n return toReturn;\n }\n }, {\n key: 'updateDisplay',\n value: function updateDisplay() {\n if (this.getValue() === true) {\n this.__checkbox.setAttribute('checked', 'checked');\n this.__checkbox.checked = true;\n this.__prev = true;\n } else {\n this.__checkbox.checked = false;\n this.__prev = false;\n }\n return get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'updateDisplay', this).call(this);\n }\n }]);\n return BooleanController;\n}(Controller);\n\nvar OptionController = function (_Controller) {\n inherits(OptionController, _Controller);\n function OptionController(object, property, opts) {\n classCallCheck(this, OptionController);\n var _this2 = possibleConstructorReturn(this, (OptionController.__proto__ || Object.getPrototypeOf(OptionController)).call(this, object, property));\n var options = opts;\n var _this = _this2;\n _this2.__select = document.createElement('select');\n if (Common.isArray(options)) {\n var map = {};\n Common.each(options, function (element) {\n map[element] = element;\n });\n options = map;\n }\n Common.each(options, function (value, key) {\n var opt = document.createElement('option');\n opt.innerHTML = key;\n opt.setAttribute('value', value);\n _this.__select.appendChild(opt);\n });\n _this2.updateDisplay();\n dom.bind(_this2.__select, 'change', function () {\n var desiredValue = this.options[this.selectedIndex].value;\n _this.setValue(desiredValue);\n });\n _this2.domElement.appendChild(_this2.__select);\n return _this2;\n }\n createClass(OptionController, [{\n key: 'setValue',\n value: function setValue(v) {\n var toReturn = get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'setValue', this).call(this, v);\n if (this.__onFinishChange) {\n this.__onFinishChange.call(this, this.getValue());\n }\n return toReturn;\n }\n }, {\n key: 'updateDisplay',\n value: function updateDisplay() {\n if (dom.isActive(this.__select)) return this;\n this.__select.value = this.getValue();\n return get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'updateDisplay', this).call(this);\n }\n }]);\n return OptionController;\n}(Controller);\n\nvar StringController = function (_Controller) {\n inherits(StringController, _Controller);\n function StringController(object, property) {\n classCallCheck(this, StringController);\n var _this2 = possibleConstructorReturn(this, (StringController.__proto__ || Object.getPrototypeOf(StringController)).call(this, object, property));\n var _this = _this2;\n function onChange() {\n _this.setValue(_this.__input.value);\n }\n function onBlur() {\n if (_this.__onFinishChange) {\n _this.__onFinishChange.call(_this, _this.getValue());\n }\n }\n _this2.__input = document.createElement('input');\n _this2.__input.setAttribute('type', 'text');\n dom.bind(_this2.__input, 'keyup', onChange);\n dom.bind(_this2.__input, 'change', onChange);\n dom.bind(_this2.__input, 'blur', onBlur);\n dom.bind(_this2.__input, 'keydown', function (e) {\n if (e.keyCode === 13) {\n this.blur();\n }\n });\n _this2.updateDisplay();\n _this2.domElement.appendChild(_this2.__input);\n return _this2;\n }\n createClass(StringController, [{\n key: 'updateDisplay',\n value: function updateDisplay() {\n if (!dom.isActive(this.__input)) {\n this.__input.value = this.getValue();\n }\n return get(StringController.prototype.__proto__ || Object.getPrototypeOf(StringController.prototype), 'updateDisplay', this).call(this);\n }\n }]);\n return StringController;\n}(Controller);\n\nfunction numDecimals(x) {\n var _x = x.toString();\n if (_x.indexOf('.') > -1) {\n return _x.length - _x.indexOf('.') - 1;\n }\n return 0;\n}\nvar NumberController = function (_Controller) {\n inherits(NumberController, _Controller);\n function NumberController(object, property, params) {\n classCallCheck(this, NumberController);\n var _this = possibleConstructorReturn(this, (NumberController.__proto__ || Object.getPrototypeOf(NumberController)).call(this, object, property));\n var _params = params || {};\n _this.__min = _params.min;\n _this.__max = _params.max;\n _this.__step = _params.step;\n if (Common.isUndefined(_this.__step)) {\n if (_this.initialValue === 0) {\n _this.__impliedStep = 1;\n } else {\n _this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(_this.initialValue)) / Math.LN10)) / 10;\n }\n } else {\n _this.__impliedStep = _this.__step;\n }\n _this.__precision = numDecimals(_this.__impliedStep);\n return _this;\n }\n createClass(NumberController, [{\n key: 'setValue',\n value: function setValue(v) {\n var _v = v;\n if (this.__min !== undefined && _v < this.__min) {\n _v = this.__min;\n } else if (this.__max !== undefined && _v > this.__max) {\n _v = this.__max;\n }\n if (this.__step !== undefined && _v % this.__step !== 0) {\n _v = Math.round(_v / this.__step) * this.__step;\n }\n return get(NumberController.prototype.__proto__ || Object.getPrototypeOf(NumberController.prototype), 'setValue', this).call(this, _v);\n }\n }, {\n key: 'min',\n value: function min(minValue) {\n this.__min = minValue;\n return this;\n }\n }, {\n key: 'max',\n value: function max(maxValue) {\n this.__max = maxValue;\n return this;\n }\n }, {\n key: 'step',\n value: function step(stepValue) {\n this.__step = stepValue;\n this.__impliedStep = stepValue;\n this.__precision = numDecimals(stepValue);\n return this;\n }\n }]);\n return NumberController;\n}(Controller);\n\nfunction roundToDecimal(value, decimals) {\n var tenTo = Math.pow(10, decimals);\n return Math.round(value * tenTo) / tenTo;\n}\nvar NumberControllerBox = function (_NumberController) {\n inherits(NumberControllerBox, _NumberController);\n function NumberControllerBox(object, property, params) {\n classCallCheck(this, NumberControllerBox);\n var _this2 = possibleConstructorReturn(this, (NumberControllerBox.__proto__ || Object.getPrototypeOf(NumberControllerBox)).call(this, object, property, params));\n _this2.__truncationSuspended = false;\n var _this = _this2;\n var prevY = void 0;\n function onChange() {\n var attempted = parseFloat(_this.__input.value);\n if (!Common.isNaN(attempted)) {\n _this.setValue(attempted);\n }\n }\n function onFinish() {\n if (_this.__onFinishChange) {\n _this.__onFinishChange.call(_this, _this.getValue());\n }\n }\n function onBlur() {\n onFinish();\n }\n function onMouseDrag(e) {\n var diff = prevY - e.clientY;\n _this.setValue(_this.getValue() + diff * _this.__impliedStep);\n prevY = e.clientY;\n }\n function onMouseUp() {\n dom.unbind(window, 'mousemove', onMouseDrag);\n dom.unbind(window, 'mouseup', onMouseUp);\n onFinish();\n }\n function onMouseDown(e) {\n dom.bind(window, 'mousemove', onMouseDrag);\n dom.bind(window, 'mouseup', onMouseUp);\n prevY = e.clientY;\n }\n _this2.__input = document.createElement('input');\n _this2.__input.setAttribute('type', 'text');\n dom.bind(_this2.__input, 'change', onChange);\n dom.bind(_this2.__input, 'blur', onBlur);\n dom.bind(_this2.__input, 'mousedown', onMouseDown);\n dom.bind(_this2.__input, 'keydown', function (e) {\n if (e.keyCode === 13) {\n _this.__truncationSuspended = true;\n this.blur();\n _this.__truncationSuspended = false;\n onFinish();\n }\n });\n _this2.updateDisplay();\n _this2.domElement.appendChild(_this2.__input);\n return _this2;\n }\n createClass(NumberControllerBox, [{\n key: 'updateDisplay',\n value: function updateDisplay() {\n this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);\n return get(NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf(NumberControllerBox.prototype), 'updateDisplay', this).call(this);\n }\n }]);\n return NumberControllerBox;\n}(NumberController);\n\nfunction map(v, i1, i2, o1, o2) {\n return o1 + (o2 - o1) * ((v - i1) / (i2 - i1));\n}\nvar NumberControllerSlider = function (_NumberController) {\n inherits(NumberControllerSlider, _NumberController);\n function NumberControllerSlider(object, property, min, max, step) {\n classCallCheck(this, NumberControllerSlider);\n var _this2 = possibleConstructorReturn(this, (NumberControllerSlider.__proto__ || Object.getPrototypeOf(NumberControllerSlider)).call(this, object, property, { min: min, max: max, step: step }));\n var _this = _this2;\n _this2.__background = document.createElement('div');\n _this2.__foreground = document.createElement('div');\n dom.bind(_this2.__background, 'mousedown', onMouseDown);\n dom.bind(_this2.__background, 'touchstart', onTouchStart);\n dom.addClass(_this2.__background, 'slider');\n dom.addClass(_this2.__foreground, 'slider-fg');\n function onMouseDown(e) {\n document.activeElement.blur();\n dom.bind(window, 'mousemove', onMouseDrag);\n dom.bind(window, 'mouseup', onMouseUp);\n onMouseDrag(e);\n }\n function onMouseDrag(e) {\n e.preventDefault();\n var bgRect = _this.__background.getBoundingClientRect();\n _this.setValue(map(e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max));\n return false;\n }\n function onMouseUp() {\n dom.unbind(window, 'mousemove', onMouseDrag);\n dom.unbind(window, 'mouseup', onMouseUp);\n if (_this.__onFinishChange) {\n _this.__onFinishChange.call(_this, _this.getValue());\n }\n }\n function onTouchStart(e) {\n if (e.touches.length !== 1) {\n return;\n }\n dom.bind(window, 'touchmove', onTouchMove);\n dom.bind(window, 'touchend', onTouchEnd);\n onTouchMove(e);\n }\n function onTouchMove(e) {\n var clientX = e.touches[0].clientX;\n var bgRect = _this.__background.getBoundingClientRect();\n _this.setValue(map(clientX, bgRect.left, bgRect.right, _this.__min, _this.__max));\n }\n function onTouchEnd() {\n dom.unbind(window, 'touchmove', onTouchMove);\n dom.unbind(window, 'touchend', onTouchEnd);\n if (_this.__onFinishChange) {\n _this.__onFinishChange.call(_this, _this.getValue());\n }\n }\n _this2.updateDisplay();\n _this2.__background.appendChild(_this2.__foreground);\n _this2.domElement.appendChild(_this2.__background);\n return _this2;\n }\n createClass(NumberControllerSlider, [{\n key: 'updateDisplay',\n value: function updateDisplay() {\n var pct = (this.getValue() - this.__min) / (this.__max - this.__min);\n this.__foreground.style.width = pct * 100 + '%';\n return get(NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf(NumberControllerSlider.prototype), 'updateDisplay', this).call(this);\n }\n }]);\n return NumberControllerSlider;\n}(NumberController);\n\nvar FunctionController = function (_Controller) {\n inherits(FunctionController, _Controller);\n function FunctionController(object, property, text) {\n classCallCheck(this, FunctionController);\n var _this2 = possibleConstructorReturn(this, (FunctionController.__proto__ || Object.getPrototypeOf(FunctionController)).call(this, object, property));\n var _this = _this2;\n _this2.__button = document.createElement('div');\n _this2.__button.innerHTML = text === undefined ? 'Fire' : text;\n dom.bind(_this2.__button, 'click', function (e) {\n e.preventDefault();\n _this.fire();\n return false;\n });\n dom.addClass(_this2.__button, 'button');\n _this2.domElement.appendChild(_this2.__button);\n return _this2;\n }\n createClass(FunctionController, [{\n key: 'fire',\n value: function fire() {\n if (this.__onChange) {\n this.__onChange.call(this);\n }\n this.getValue().call(this.object);\n if (this.__onFinishChange) {\n this.__onFinishChange.call(this, this.getValue());\n }\n }\n }]);\n return FunctionController;\n}(Controller);\n\nvar ColorController = function (_Controller) {\n inherits(ColorController, _Controller);\n function ColorController(object, property) {\n classCallCheck(this, ColorController);\n var _this2 = possibleConstructorReturn(this, (ColorController.__proto__ || Object.getPrototypeOf(ColorController)).call(this, object, property));\n _this2.__color = new Color(_this2.getValue());\n _this2.__temp = new Color(0);\n var _this = _this2;\n _this2.domElement = document.createElement('div');\n dom.makeSelectable(_this2.domElement, false);\n _this2.__selector = document.createElement('div');\n _this2.__selector.className = 'selector';\n _this2.__saturation_field = document.createElement('div');\n _this2.__saturation_field.className = 'saturation-field';\n _this2.__field_knob = document.createElement('div');\n _this2.__field_knob.className = 'field-knob';\n _this2.__field_knob_border = '2px solid ';\n _this2.__hue_knob = document.createElement('div');\n _this2.__hue_knob.className = 'hue-knob';\n _this2.__hue_field = document.createElement('div');\n _this2.__hue_field.className = 'hue-field';\n _this2.__input = document.createElement('input');\n _this2.__input.type = 'text';\n _this2.__input_textShadow = '0 1px 1px ';\n dom.bind(_this2.__input, 'keydown', function (e) {\n if (e.keyCode === 13) {\n onBlur.call(this);\n }\n });\n dom.bind(_this2.__input, 'blur', onBlur);\n dom.bind(_this2.__selector, 'mousedown', function () {\n dom.addClass(this, 'drag').bind(window, 'mouseup', function () {\n dom.removeClass(_this.__selector, 'drag');\n });\n });\n dom.bind(_this2.__selector, 'touchstart', function () {\n dom.addClass(this, 'drag').bind(window, 'touchend', function () {\n dom.removeClass(_this.__selector, 'drag');\n });\n });\n var valueField = document.createElement('div');\n Common.extend(_this2.__selector.style, {\n width: '122px',\n height: '102px',\n padding: '3px',\n backgroundColor: '#222',\n boxShadow: '0px 1px 3px rgba(0,0,0,0.3)'\n });\n Common.extend(_this2.__field_knob.style, {\n position: 'absolute',\n width: '12px',\n height: '12px',\n border: _this2.__field_knob_border + (_this2.__color.v < 0.5 ? '#fff' : '#000'),\n boxShadow: '0px 1px 3px rgba(0,0,0,0.5)',\n borderRadius: '12px',\n zIndex: 1\n });\n Common.extend(_this2.__hue_knob.style, {\n position: 'absolute',\n width: '15px',\n height: '2px',\n borderRight: '4px solid #fff',\n zIndex: 1\n });\n Common.extend(_this2.__saturation_field.style, {\n width: '100px',\n height: '100px',\n border: '1px solid #555',\n marginRight: '3px',\n display: 'inline-block',\n cursor: 'pointer'\n });\n Common.extend(valueField.style, {\n width: '100%',\n height: '100%',\n background: 'none'\n });\n linearGradient(valueField, 'top', 'rgba(0,0,0,0)', '#000');\n Common.extend(_this2.__hue_field.style, {\n width: '15px',\n height: '100px',\n border: '1px solid #555',\n cursor: 'ns-resize',\n position: 'absolute',\n top: '3px',\n right: '3px'\n });\n hueGradient(_this2.__hue_field);\n Common.extend(_this2.__input.style, {\n outline: 'none',\n textAlign: 'center',\n color: '#fff',\n border: 0,\n fontWeight: 'bold',\n textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)'\n });\n dom.bind(_this2.__saturation_field, 'mousedown', fieldDown);\n dom.bind(_this2.__saturation_field, 'touchstart', fieldDown);\n dom.bind(_this2.__field_knob, 'mousedown', fieldDown);\n dom.bind(_this2.__field_knob, 'touchstart', fieldDown);\n dom.bind(_this2.__hue_field, 'mousedown', fieldDownH);\n dom.bind(_this2.__hue_field, 'touchstart', fieldDownH);\n function fieldDown(e) {\n setSV(e);\n dom.bind(window, 'mousemove', setSV);\n dom.bind(window, 'touchmove', setSV);\n dom.bind(window, 'mouseup', fieldUpSV);\n dom.bind(window, 'touchend', fieldUpSV);\n }\n function fieldDownH(e) {\n setH(e);\n dom.bind(window, 'mousemove', setH);\n dom.bind(window, 'touchmove', setH);\n dom.bind(window, 'mouseup', fieldUpH);\n dom.bind(window, 'touchend', fieldUpH);\n }\n function fieldUpSV() {\n dom.unbind(window, 'mousemove', setSV);\n dom.unbind(window, 'touchmove', setSV);\n dom.unbind(window, 'mouseup', fieldUpSV);\n dom.unbind(window, 'touchend', fieldUpSV);\n onFinish();\n }\n function fieldUpH() {\n dom.unbind(window, 'mousemove', setH);\n dom.unbind(window, 'touchmove', setH);\n dom.unbind(window, 'mouseup', fieldUpH);\n dom.unbind(window, 'touchend', fieldUpH);\n onFinish();\n }\n function onBlur() {\n var i = interpret(this.value);\n if (i !== false) {\n _this.__color.__state = i;\n _this.setValue(_this.__color.toOriginal());\n } else {\n this.value = _this.__color.toString();\n }\n }\n function onFinish() {\n if (_this.__onFinishChange) {\n _this.__onFinishChange.call(_this, _this.__color.toOriginal());\n }\n }\n _this2.__saturation_field.appendChild(valueField);\n _this2.__selector.appendChild(_this2.__field_knob);\n _this2.__selector.appendChild(_this2.__saturation_field);\n _this2.__selector.appendChild(_this2.__hue_field);\n _this2.__hue_field.appendChild(_this2.__hue_knob);\n _this2.domElement.appendChild(_this2.__input);\n _this2.domElement.appendChild(_this2.__selector);\n _this2.updateDisplay();\n function setSV(e) {\n if (e.type.indexOf('touch') === -1) {\n e.preventDefault();\n }\n var fieldRect = _this.__saturation_field.getBoundingClientRect();\n var _ref = e.touches && e.touches[0] || e,\n clientX = _ref.clientX,\n clientY = _ref.clientY;\n var s = (clientX - fieldRect.left) / (fieldRect.right - fieldRect.left);\n var v = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top);\n if (v > 1) {\n v = 1;\n } else if (v < 0) {\n v = 0;\n }\n if (s > 1) {\n s = 1;\n } else if (s < 0) {\n s = 0;\n }\n _this.__color.v = v;\n _this.__color.s = s;\n _this.setValue(_this.__color.toOriginal());\n return false;\n }\n function setH(e) {\n if (e.type.indexOf('touch') === -1) {\n e.preventDefault();\n }\n var fieldRect = _this.__hue_field.getBoundingClientRect();\n var _ref2 = e.touches && e.touches[0] || e,\n clientY = _ref2.clientY;\n var h = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top);\n if (h > 1) {\n h = 1;\n } else if (h < 0) {\n h = 0;\n }\n _this.__color.h = h * 360;\n _this.setValue(_this.__color.toOriginal());\n return false;\n }\n return _this2;\n }\n createClass(ColorController, [{\n key: 'updateDisplay',\n value: function updateDisplay() {\n var i = interpret(this.getValue());\n if (i !== false) {\n var mismatch = false;\n Common.each(Color.COMPONENTS, function (component) {\n if (!Common.isUndefined(i[component]) && !Common.isUndefined(this.__color.__state[component]) && i[component] !== this.__color.__state[component]) {\n mismatch = true;\n return {};\n }\n }, this);\n if (mismatch) {\n Common.extend(this.__color.__state, i);\n }\n }\n Common.extend(this.__temp.__state, this.__color.__state);\n this.__temp.a = 1;\n var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0;\n var _flip = 255 - flip;\n Common.extend(this.__field_knob.style, {\n marginLeft: 100 * this.__color.s - 7 + 'px',\n marginTop: 100 * (1 - this.__color.v) - 7 + 'px',\n backgroundColor: this.__temp.toHexString(),\n border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')'\n });\n this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px';\n this.__temp.s = 1;\n this.__temp.v = 1;\n linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toHexString());\n this.__input.value = this.__color.toString();\n Common.extend(this.__input.style, {\n backgroundColor: this.__color.toHexString(),\n color: 'rgb(' + flip + ',' + flip + ',' + flip + ')',\n textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)'\n });\n }\n }]);\n return ColorController;\n}(Controller);\nvar vendors = ['-moz-', '-o-', '-webkit-', '-ms-', ''];\nfunction linearGradient(elem, x, a, b) {\n elem.style.background = '';\n Common.each(vendors, function (vendor) {\n elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); ';\n });\n}\nfunction hueGradient(elem) {\n elem.style.background = '';\n elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);';\n elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';\n elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';\n elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';\n elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';\n}\n\nvar css = {\n load: function load(url, indoc) {\n var doc = indoc || document;\n var link = doc.createElement('link');\n link.type = 'text/css';\n link.rel = 'stylesheet';\n link.href = url;\n doc.getElementsByTagName('head')[0].appendChild(link);\n },\n inject: function inject(cssContent, indoc) {\n var doc = indoc || document;\n var injected = document.createElement('style');\n injected.type = 'text/css';\n injected.innerHTML = cssContent;\n var head = doc.getElementsByTagName('head')[0];\n try {\n head.appendChild(injected);\n } catch (e) {\n }\n }\n};\n\nvar saveDialogContents = \"
GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n GUI
's constructor:\\n\\n \\n\\n localStorage
on exit.\\n\\n localStorage
will\\n override those passed to dat.GUI
's constructor. This makes it\\n easier to work incrementally, but localStorage
is fragile,\\n and your friends may not see the same values you do.\\n\\n