{"version":3,"file":"ts-matrix.mjs","names":[],"sources":["../src/Vector.ts","../src/Matrix.ts","../src/constants.ts","../src/Quat.ts"],"sourcesContent":["import Matrix from './Matrix';\n\nexport default class Vector {\n\n    /** Values of the vector */\n    private _values: number[];\n\n    constructor(values?: number[]) {\n        // Create matrix filled with 0 by default\n        this._values = new Array<number>((values || [0]).length).fill(0);\n\n        if (values) {\n            this.values = values;\n        }\n    }\n\n    get rows() {\n        return this.values.length;\n    }\n\n    get values() {\n        return this._values;\n    }\n\n    /**\n     * Set values into the vector.\n     * If the parameters vector is to wide, the values are cropped to the current vector size.\n     * It the parameters vector is to small, remaining cells will be filled with 0.\n     * @param newValues Arrays of new values.\n     */\n    set values(newValues: number[]) {\n        const minSize = Math.min(this.values.length, newValues.length);\n        for (let i = 0; i < minSize; i++) {\n            this.values[i] = newValues[i];\n        }\n    }\n\n    /**\n     * Calculates the angle in radians between the vector and the receiver.\n     * @param vector The operand vector\n     * @return An angle, between 0 and +π inclusive.\n     */\n    angle(vector: Vector): number {\n      if (this.rows !== vector.rows) throw new Error('To calculate the angle, vectors must have the same dimension!');\n      const dot = this.dot(vector);\n      const cos = dot / (this.length() * vector.length());\n      return Math.acos(cos);\n    }\n\n    /**\n     * Calculates the distance between the vector and the receiver.\n     * Equivalent to |receiver - vector|\n     * @param vector The operand vector\n     * @return The distance (absolute value) between the two vectors\n     */  \n    distance(vector: Vector): number {\n      if(this.rows !== vector.rows) throw new Error('To calculate the distance, vectors must have the same dimension!');\n      return this.subtract(vector).length();\n    }\n\n    /**\n     * Get a matrix value, from its position\n     * @param row Matrix line, from 0 to `rows`\n     */\n    at(row: number): number {\n        return this.values[row];\n    }\n\n    /**\n     * Get the position, from its matrix value\n     * @param value The value to search\n     * @return The position of the value, or -1 if not found\n     */\n    indexOf(value: number): number  {\n      return this.values.indexOf(value);\n    }\n\n    /**\n     * Sets all matrix values to 0\n     */\n    reset(): void {\n        this.values = this.values.fill(0);\n    }\n\n    /**\n    * Get a new vector with extra 0 values appended to it\n    * @param count Number of values to add (default: 1)\n     * @return A new, larger Vector\n     */\n    addValues(count = 1): Vector {\n        if (!Number.isInteger(count) || count < 0) {\n            throw new Error('Dimension error! Value count must be a non-negative integer.');\n        }\n        return new Vector([...this.values, ...new Array<number>(count).fill(0)]);\n    }\n\n    /**\n     * Get a copy of this vector\n     * @return A new vector with the same values\n     */\n    copy(): Vector {\n        return new Vector(this.values);\n    }\n\n    /**\n     * Check if two vectors are equals, value by value\n     * @param vec The vector against to check equality\n     * @param threshold The maximum allowed difference between two values to still be considered equal (default: 0, i.e. exact equality)\n     */\n    equals(vec: Vector, threshold = 0): boolean {\n        return (this.rows === vec.rows)\n            && this.values.reduce((eql: boolean, val, i) => eql && Math.abs(vec.at(i) - val) <= threshold, true);\n    }\n\n    /**\n     * Negate all values of the vector (get the opposite sign)\n     * @return A new vector whose all values have the opposed sign\n     */\n    negate(): Vector {\n        return new Vector(this.values.map((val) => -val));\n    }\n\n    /** Get the length of the vector */\n    length(): number {\n        return Math.sqrt(this.squaredLength());\n    }\n\n    /** Get the squared length of the vector */\n    squaredLength(): number {\n        return this.dot(this);\n    }\n\n    /**\n     * Add all vector values with the same position value of the operand vector\n     * @param vector The operand vector\n     * @throws Error if the two vectors don't have the same dimension\n     * @return a new Vector with the result values\n     */\n    add(vector: Vector): Vector {\n        if (this.rows !== vector.rows) throw new Error(\"Vectors don't have the same dimension!\");\n        return this.operateOnAllValues((val, i) => (val + vector.at(i)));\n    }\n\n    /**\n     * subtract all vector values with the same position value of the operand vector\n     * @param vector The operand vector\n     * @throws Error if the two vectors don't have the same dimension\n     * @return a new Vector with the result values\n     */\n    subtract(vector: Vector): Vector {\n        if (this.rows !== vector.rows) throw new Error(\"Vectors don't have the same dimension!\");\n        return this.operateOnAllValues((val, i) => (val - vector.at(i)));\n    }\n\n    /**\n     * Multiply all vector values with the same position value of the operand vector\n     * @param vector The operand vector\n     * @throws Error if the two vectors don't have the same dimension\n     * @return a new Vector with the result values\n     */\n    multiply(vector: Vector): Vector {\n        if (this.rows !== vector.rows) throw new Error(\"Vectors don't have the same dimension!\");\n        return this.operateOnAllValues((val, i) => (val * vector.at(i)));\n    }\n\n    /**\n     * Divide all vector values with the same position value of the operand vector\n     * Be aware of divisions by 0!\n     * @param vector The operand vector\n     * @throws Error if the two vectors don't have the same dimension\n     * @return a new Vector with the result values\n     */\n    divide(vector: Vector): Vector {\n        if (this.rows !== vector.rows) throw new Error(\"Vectors don't have the same dimension!\");\n        return this.operateOnAllValues((val, i) => {\n            if (vector.at(i) === 0) return val;\n            return (val / vector.at(i));\n        });\n    }\n\n    /**\n     * Computes the product of this vector with a matrix (vector * matrix)\n     * The vector is treated as a row vector\n     * @param matrix The matrix to multiply with\n     * @throws Error if vector.rows != matrix.rows\n     * @return A new Vector, result of the multiplication\n     */\n    multiplyMatrix(matrix: Matrix): Vector {\n        if (this.rows !== matrix.rows) throw new Error(\"Dimension error! The vector must have the same number of elements as the matrix rows!\");\n        \n        const resultValues = new Array<number>(matrix.columns);\n        for (let j = 0; j < matrix.columns; j++) {\n            resultValues[j] = this.values.reduce((sum, element, index) => sum + (element * matrix.at(index, j)), 0);\n        }\n        \n        return new Vector(resultValues);\n    }\n\n    /**\n     * Computes the maximum value of the vector\n     * @return The maximum value\n     * @throws Error if the vector is empty\n     */\n    max(): number {\n      if (this.rows === 0) throw new Error('Cannot get the maximum value of an empty vector!');\n      return Math.max(...this.values);\n    }\n\n    /**\n     * Computes the minimum value of the vector\n     * @return The minimum value\n     * @throws Error if the vector is empty\n     */\n    min(): number {\n      if (this.rows === 0) throw new Error('Cannot get the minimum value of an empty vector!');\n      return Math.min(...this.values);\n    }\n\n    /**\n     * Rounds all vector values to the nearest integer\n     * @return A new vector with the rounded values\n     * @throws Error if the vector is empty\n     */\n    round(): Vector {\n      if(this.rows === 0) throw new Error('Cannot round an empty vector!');\n      return this.operateOnAllValues((x) => Math.round(x));\n    }\n\n    /**\n     * Multiply all vector values by the given number\n     * @param scale The number to multiply with the values\n     */\n    scale(scale: number): Vector {\n        return this.operateOnAllValues((val) => (val * scale));\n    }\n\n    /**\n     * Run a function on all vector values, as a map.\n     * @param operation The mapping method\n     * @return a new Vector with the operation done on all its values\n     */\n    private operateOnAllValues(operation: (val: number, index: number) => number): Vector {\n        return new Vector(this.values.map(operation));\n    }\n\n    /**\n     * Computes the normalized vector\n     * @return The normalized vector, or a zero vector if this vector has a length of 0\n     */\n    normalize(): Vector {\n        const vectorLength = this.length();\n        if (!vectorLength) return new Vector(this.values.map(() => 0));\n        return this.operateOnAllValues((val) => val / vectorLength);\n    }\n\n    /**\n     * Computes the dot product of vectors\n     * @param vector The operand vector\n     */\n    dot(vector: Vector): number {\n        return this.values.reduce((res, val, i) => res + (val * vector.at(i)), 0);\n    }\n\n    /**\n     * Computes the cross product of vectors\n     * @param vector The operand vector\n     */\n    cross(vector: Vector): Vector {\n        if (this.rows < 3 || vector.rows < 3) throw new Error('Cross product is possible on 3D vectors only');\n        const crossValues = new Array<number>(3);\n        crossValues[0] = this.at(1) * vector.at(2) - this.at(2) * vector.at(1);\n        crossValues[1] = this.at(2) * vector.at(0) - this.at(0) * vector.at(2);\n        crossValues[2] = this.at(0) * vector.at(1) - this.at(1) * vector.at(0);\n        return new Vector(crossValues);\n    }\n\n    mix(vector: Vector, time: number): Vector {\n        return new Vector(this.values.map((val, i) => val + time * (vector.at(i) - val)));\n    }\n\n    /**\n     * Calculates the signed angle in radians between two 3D vectors.\n     * @param Va First vector\n     * @param Vb Second vector\n     * @return A signed angle between -π and +π\n     */\n    static signedAngle(Va: Vector, Vb: Vector) {\n        if (Va.rows !== 3 || Vb.rows !== 3) throw new Error('Vectors must be in 3D!. You can add a 1 dimension if it is missing.');\n        return -Math.atan2(\n          Vb.cross(Va).dot(new Vector([0, 0, 1]).normalize()),\n          Va.dot(Vb)\n        );\n    }\n\n    toString(): string {\n        return `[${this.values.join(', ')}]`;\n    }\n}\n","import Vector from './Vector';\n\nexport default class Matrix {\n\n    /** Number of rows of the matrix */\n    private _rows: number;\n    /** Number of columns of the matrix */\n    private _columns: number;\n    /** Values of the matrix as a two dimensional array */\n    private _values: number[][];\n\n    constructor(rows: number, columns: number, values?: number[][]) {\n        this._rows = Math.max(rows, 1);\n        this._columns = Math.max(columns, 1);\n        // Create matrix filled with 0 by default\n        this._values = new Array<number[]>(this._rows).fill([]).map(() => new Array<number>(this._columns).fill(0));\n\n        if (values) {\n            this.values = values;\n        }\n    }\n\n    get rows(): number {\n        return this._rows;\n    }\n    get columns(): number {\n        return this._columns;\n    }\n    get values(): number[][] {\n        return this._values;\n    }\n\n    /**\n     * Set values into the matrix.\n     * If the parameters matrix is to wide, the values are cropped to the current matrix size.\n     * It the parameters matrix is to small, remaining cells will be filled with 0.\n     * @param newValues Arrays of new values.\n     */\n    set values(newValues: number[][]) {\n        if (newValues.length === 0) return;\n        const minRow = Math.min(newValues.length, this.rows);\n        const minCol = Math.min(newValues[0].length, this.columns);\n        for (let r = 0; r < minRow; r++) {\n            for (let c = 0; c < minCol; c++) {\n                this.values[r][c] = newValues[r][c];\n            }\n        }\n    }\n\n    /**\n     * Get a matrix value, from its position\n     * @param row Matrix line, from 0 to `rows`\n     * @param col Matric column, from 0 to `columns`\n     */\n    at(row: number, col: number): number {\n        return this.values[row][col];\n    }\n\n    /**\n     * Sets all matrix values to 0\n     */\n    reset(): void {\n        this.values = this.values.map((row) => row.map(() => 0));\n    }\n\n    /**\n     * Get a copy of this matrix\n     * @return A new matrix with the same values\n     */\n    copy(): Matrix {\n        return new Matrix(this.rows, this.columns, this.values);\n    }\n\n    /**\n     * Computes the trace of the matrix, i.e. the sum of its diagonal values\n     * @throws Error if the matrix is not squared\n     */\n    trace(): number {\n        if (this.rows !== this.columns) throw new Error(\"Dimension error! The matrix isn't squared!\");\n        let sum = 0;\n        for (let i = 0; i < this.rows; i++) {\n            sum += this.at(i, i);\n        }\n        return sum;\n    }\n\n    /**\n    * Add new columns to the matrix, filled with 0\n    * @param count Number of columns to add (default: 1)\n     */\n    addColumns(count = 1): Matrix {\n        if (!Number.isInteger(count) || count < 0) {\n            throw new Error('Dimension error! Column count must be a non-negative integer.');\n        }\n        return new Matrix(this.rows, this.columns + count, this.values);\n    }\n\n    /**\n    * Add new rows to the matrix, filled with 0\n    * @param count Number of rows to add (default: 1)\n     */\n    addRows(count = 1): Matrix {\n        if (!Number.isInteger(count) || count < 0) {\n            throw new Error('Dimension error! Row count must be a non-negative integer.');\n        }\n        return new Matrix(this.rows + count, this.columns, this.values);\n    }\n\n    /**\n     * Check if two matrix are equals, value by value\n     * @param mat The matrix against to check equality\n     * @param threshold The maximum allowed difference between two values to still be considered equal (default: 0, i.e. exact equality)\n     */\n    equals(mat: Matrix, threshold = 0): boolean {\n        // Reduce on rows -> reduce on columns -> if a value != then false!\n        return (this.rows === mat.rows && this.columns === mat.columns)\n            && this.values.reduce(// Rows\n                (eql: boolean, row, i) => eql && row.reduce(// Columns (real values)\n                        (eql2: boolean, val, j) => eql2 && Math.abs(mat.at(i, j) - val) <= threshold, eql)\n                , true);\n    }\n\n    /**\n     * Sets the matrix as an identity matrix\n     */\n    setIdentity() {\n        if (this.rows !== this.columns) throw new Error(\"Dimension error! The matrix isn't squared!\");\n        this.values.forEach((row, i) => {\n            row.forEach((c, j) => {\n                this.values[i][j] = i === j ? 1 : 0;\n            });\n        });\n        return this;\n    }\n\n    /**\n     * Gets an identity matrix (1 on diagonal)\n     * @param dimension Dimension of the squared matrix\n     */\n    static identity(dimension: number): Matrix {\n        if (dimension < 1) throw Error('Dimension error! Matrix dimension must be positive.');\n        return new Matrix(dimension, dimension).setIdentity();\n    }\n\n    /**\n     * Builds a matrix from a flat, row-major array of values\n     * @param values Flat array of values, read row by row\n     * @param rows Number of rows\n     * @param columns Number of columns\n     * @throws Error if values.length !== rows * columns\n     * @return A new Matrix built from the given values\n     */\n    static fromArray(values: number[], rows: number, columns: number): Matrix {\n        if (values.length !== rows * columns) throw new Error(`Dimension error! Expected ${rows * columns} values for a ${rows}x${columns} matrix, got ${values.length}.`);\n\n        const rowMajorValues = new Array<number[]>(rows);\n        for (let i = 0; i < rows; i++) {\n            rowMajorValues[i] = values.slice(i * columns, (i + 1) * columns);\n        }\n\n        return new Matrix(rows, columns, rowMajorValues);\n    }\n\n    /**\n     * Add all matrix values with the same position value of the operand matrix\n     * @param mat The operand matrix\n     * @throws Error if the two matrices don't have the same dimensions\n     * @return A new Matrix with the result values\n     */\n    add(mat: Matrix): Matrix {\n        if (this.rows !== mat.rows || this.columns !== mat.columns) throw new Error(\"Dimension error! Both matrices must have the same dimensions!\");\n        return this.operateOnAllValues((val, i, j) => val + mat.at(i, j));\n    }\n\n    /**\n     * Subtract all matrix values with the same position value of the operand matrix\n     * @param mat The operand matrix\n     * @throws Error if the two matrices don't have the same dimensions\n     * @return A new Matrix with the result values\n     */\n    subtract(mat: Matrix): Matrix {\n        if (this.rows !== mat.rows || this.columns !== mat.columns) throw new Error(\"Dimension error! Both matrices must have the same dimensions!\");\n        return this.operateOnAllValues((val, i, j) => val - mat.at(i, j));\n    }\n\n    /**\n     * Multiply all matrix values by the given number\n     * @param scale The number to multiply with the values\n     * @return A new Matrix with the result values\n     */\n    scale(scale: number): Matrix {\n        return this.operateOnAllValues((val) => val * scale);\n    }\n\n    /**\n     * Run a function on all matrix values, as a map.\n     * @param operation The mapping method\n     * @return a new Matrix with the operation done on all its values\n     */\n    private operateOnAllValues(operation: (val: number, row: number, col: number) => number): Matrix {\n        return new Matrix(this.rows, this.columns, this.values.map((row, i) => row.map((val, j) => operation(val, i, j))));\n    }\n\n    /**\n     * Computes the product with another matrix\n     * @param mat The second operand matrix\n     * @throws Error if matrixA.columns != matrixB.rows\n     * @return A new Matrix, result of the multiplication\n     */\n    multiply(mat: Matrix): Matrix {\n        if (this.columns !== mat.rows) throw new Error(\"Dimension error! The operand matrix must have the same number of rows as 'this' matrix columns!\");\n        const resMatrix = new Matrix(this.rows, mat.columns);\n        resMatrix.values = resMatrix.values.map((row, i) => {\n            return row.map((val, j) => {\n                return this.values[i].reduce((sum, elm, k) => sum + (elm * mat.at(k, j)), 0);\n            });\n        });\n        return resMatrix;\n    }\n\n    /**\n     * Computes the product with a vector\n     * @param vec The vector to multiply with\n     * @throws Error if matrix.columns != vector.rows\n     * @return A new Vector, result of the multiplication\n     */\n    multiplyVector(vec: Vector): Vector {\n        if (this.columns !== vec.rows) throw new Error(\"Dimension error! The vector must have the same number of elements as the matrix columns!\");\n        \n        const resultValues = this.values.map(row => {\n            return row.reduce((sum, element, index) => sum + (element * vec.at(index)), 0);\n        });\n        \n        return new Vector(resultValues);\n    }\n\n    /**\n     * Get the position, from its matrix value\n     * @param value The value to search\n     * @return The position of the value, or -1 if not found\n     */\n    indexOf(value: number): [number, number]  {\n      for(let i = 0; i < this.rows; i++) {\n        for(let j = 0; j < this.columns; j++) {\n          if(this.values[i][j] === value) return [i, j];\n        }\n      }\n\n      return [-1, -1];\n    }\n\n    /**\n     * Computes the maximum value of the matrix\n     * @return The maximum value\n     */\n    max(): number {\n      return this.values.reduce((max, row) => Math.max(max, ...row), -Infinity);\n    }\n\n    /**\n     * Computes the minimum value of the matrix\n     * @return The minimum value\n     * @throws Error if the matrix is empty\n     */\n    min(): number {\n      return this.values.reduce((min, row) => Math.min(min, ...row), Infinity);\n    }\n\n    /**\n     * Rounds all matrix values to the nearest integer\n     * @return A new matrix with the rounded values\n     */\n    round(): Matrix {\n      return new Matrix(this.rows, this.columns, this.values.map(row => row.map(val => Math.round(val))));\n    }\n\n    /**\n     * Computes the determinant of the matrix via LU decomposition with partial\n     * pivoting, in O(n^3) instead of the O(n!) of a cofactor expansion.\n     * @throws Error if the matrix is not squared\n     */\n    determinant(): number {\n        if (this.rows !== this.columns) throw new Error(\"Dimension error! The matrix isn't squared!\");\n\n        const n = this.rows;\n        const a = this.values.map((row) => [...row]);\n        let sign = 1;\n\n        for (let k = 0; k < n; k++) {\n            let pivotRow = k;\n            let maxAbs = Math.abs(a[k][k]);\n            for (let i = k + 1; i < n; i++) {\n                if (Math.abs(a[i][k]) > maxAbs) {\n                    maxAbs = Math.abs(a[i][k]);\n                    pivotRow = i;\n                }\n            }\n            // No non-zero pivot left in this column: the matrix is singular.\n            if (maxAbs === 0) return 0;\n\n            if (pivotRow !== k) {\n                [a[k], a[pivotRow]] = [a[pivotRow], a[k]];\n                sign = -sign;\n            }\n\n            for (let i = k + 1; i < n; i++) {\n                const factor = a[i][k] / a[k][k];\n                for (let j = k; j < n; j++) {\n                    a[i][j] -= factor * a[k][j];\n                }\n            }\n        }\n\n        let det = sign;\n        for (let i = 0; i < n; i++) det *= a[i][i];\n        return det;\n    }\n\n    /**\n    * Gets a cofactor matrix\n     * @param row The row to omit in the matrix\n     * @param col The column to omit in the matrix\n     * @return The cofactor matrix sized (r-1)x(c-1)\n     */\n    cofactor(row: number, col: number): Matrix {\n        return new Matrix(this.rows - 1, this.columns - 1, this.values\n            .filter((v, i) => i !== row) // Remove the unnecessary row\n            .map((c) => c.filter((v, i) => i !== col)));\n    }\n\n    /**\n     * Computes a transposed the matrix\n     * @return A new matrix sized (columns) x (rows)\n     */\n    transpose(): Matrix {\n        return new Matrix(this.columns, this.rows, new Array<number[]>(this.columns).fill([])\n            .map((row, i) => new Array<number>(this.rows).fill(0).map((c, j) => this.at(j, i))));\n    }\n\n    /**\n     * Computes the inversed matrix via Gauss-Jordan elimination with partial\n     * pivoting, in O(n^3) instead of the O(n!) of a cofactor/adjugate approach.\n     * @return A new matrix inversed\n     * @throws Error if the matrix is not squared, or is singular (not invertible)\n     */\n    inverse(): Matrix {\n        if (this.rows !== this.columns) throw new Error(\"Dimension error! The matrix isn't squared!\");\n\n        const n = this.rows;\n        // Augmented matrix [A | I], reduced in place to [I | A^-1]\n        const a = this.values.map((row, i) => [\n            ...row,\n            ...new Array<number>(n).fill(0).map((_, j) => (i === j ? 1 : 0)),\n        ]);\n\n        for (let k = 0; k < n; k++) {\n            let pivotRow = k;\n            let maxAbs = Math.abs(a[k][k]);\n            for (let i = k + 1; i < n; i++) {\n                if (Math.abs(a[i][k]) > maxAbs) {\n                    maxAbs = Math.abs(a[i][k]);\n                    pivotRow = i;\n                }\n            }\n            if (maxAbs === 0) throw new Error(\"Determinant is 0, can't compute inverse.\");\n\n            if (pivotRow !== k) [a[k], a[pivotRow]] = [a[pivotRow], a[k]];\n\n            const pivot = a[k][k];\n            for (let j = 0; j < 2 * n; j++) a[k][j] /= pivot;\n\n            for (let i = 0; i < n; i++) {\n                if (i === k) continue;\n                const factor = a[i][k];\n                for (let j = 0; j < 2 * n; j++) {\n                    a[i][j] -= factor * a[k][j];\n                }\n            }\n        }\n\n        return new Matrix(n, n, a.map((row) => row.slice(n)));\n    }\n\n    toString(): string {\n        return `[${this.values.map(row => `[${row.join(', ')}]`).join(',\\n')}]`;\n    }\n}\n","export const EPSILON = 0.00001;\n","import { EPSILON } from './constants';\nimport Vector from './Vector';\n\n/**\n * Class representing a Quaternion for 3D rotations\n */\nexport default class Quat {\n\n    /** Values of the quaternion as [x, y, z, w] */\n    private _values: number[];\n\n    constructor(values?: [number, number, number, number]) {\n        // Create quaternion with identity by default [0, 0, 0, 1]\n        this._values = values ? [...values] : [0, 0, 0, 1];\n    }\n\n    get values(): number[] {\n        return this._values;\n    }\n\n    /**\n     * Set values into the quaternion.\n     * @param newValues Array of new values [x, y, z, w].\n     */\n    set values(newValues: number[]) {\n        const minSize = Math.min(4, newValues.length);\n        for (let i = 0; i < minSize; i++) {\n            this._values[i] = newValues[i];\n        }\n    }\n\n    get x(): number {\n        return this._values[0];\n    }\n\n    get y(): number {\n        return this._values[1];\n    }\n\n    get z(): number {\n        return this._values[2];\n    }\n\n    get w(): number {\n        return this._values[3];\n    }\n\n    get xy(): [number, number] {\n        return [\n            this._values[0],\n            this._values[1],\n        ];\n    }\n\n    get xyz(): [number, number, number] {\n        return [\n            this._values[0],\n            this._values[1],\n            this._values[2],\n        ];\n    }\n\n    get xyzw(): [number, number, number, number] {\n        return [\n            this._values[0],\n            this._values[1],\n            this._values[2],\n            this._values[3],\n        ];\n    }\n\n    /**\n     * Get an identity quaternion (rotation by 0 degrees)\n     * @return A new identity quaternion\n     */\n    static identity(): Quat {\n        return new Quat([0, 0, 0, 1]);\n    }\n\n    /**\n     * Get a quaternion value at a specific index\n     * @param index Index from 0 to 3\n     * @return The value at the specified index\n     */\n    at(index: number): number {\n        return this._values[index];\n    }\n\n    /**\n     * Sets all quaternion values to 0\n     */\n    reset(): void {\n        this.values = [0, 0, 0, 0];\n    }\n\n    /**\n     * Get a copy of this quaternion\n     * @return A new quaternion with the same values\n     */\n    copy(): Quat {\n        return new Quat(this.xyzw);\n    }\n\n    /**\n     * Calculate the roll angle (rotation around x-axis)\n     * @return Roll angle in radians\n     */\n    roll(): number {\n        const { x, y, z, w } = this;\n\n        return Math.atan2(2.0 * (x * y + w * z), w * w + x * x - y * y - z * z);\n    }\n\n    /**\n     * Calculate the pitch angle (rotation around y-axis)\n     * @return Pitch angle in radians\n     */\n    pitch(): number {\n        const { x, y, z, w } = this;\n\n        return Math.atan2(2.0 * (y * z + w * x), w * w - x * x - y * y + z * z);\n    }\n\n    /**\n     * Calculate the yaw angle (rotation around z-axis)\n     * @return Yaw angle in radians\n     */\n    yaw(): number {\n        return Math.asin(2.0 * (this.x * this.z - this.w * this.y));\n    }\n\n    /**\n     * Check if two quaternions are equal within a threshold\n     * @param quat The quaternion to compare against\n     * @param threshold The threshold for comparison (default: EPSILON)\n     * @return True if quaternions are equal within threshold\n     */\n    equals(quat: Quat, threshold = EPSILON): boolean {\n        for (let i = 0; i < 4; i++) {\n            if (Math.abs(this._values[i] - quat.at(i)) > threshold) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n\n    /**\n     * Sets the quaternion as an identity quaternion\n     * @return This quaternion for method chaining\n     */\n    setIdentity(): Quat {\n        this.values = [0, 0, 0, 1];\n\n        return this;\n    }\n\n    /**\n     * Calculate the w component based on x, y, z components.\n     * Note: this always yields a non-positive w (a valid unit quaternion,\n     * on the opposite hemisphere from `Quat.identity()`, due to the sign\n     * convention below).\n     * @return A new quaternion with the computed w component\n     */\n    calculateW(): Quat {\n        const { x, y, z } = this;\n        const w = -(Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)));\n\n        return new Quat([x, y, z, w]);\n    }\n\n    /**\n     * Compute the inverse of the quaternion\n     * @return A new, inversed quaternion\n     */\n    inverse(): Quat {\n        const dot = Quat.dot(this, this);\n\n        if (!dot) {\n            return new Quat([0, 0, 0, 0]);\n        }\n\n        const invDot = 1.0 / dot;\n\n        return new Quat([\n            this.x * -invDot,\n            this.y * -invDot,\n            this.z * -invDot,\n            this.w * invDot,\n        ]);\n    }\n\n    /**\n     * Compute the conjugate of the quaternion\n     * @return A new, conjugated quaternion\n     */\n    conjugate(): Quat {\n        return new Quat([-this.x, -this.y, -this.z, this.w]);\n    }\n\n    /**\n     * Calculate the length (magnitude) of the quaternion\n     * @return The length of the quaternion\n     */\n    length(): number {\n        const { x, y, z, w } = this;\n\n        return Math.sqrt(x * x + y * y + z * z + w * w);\n    }\n\n    /**\n     * Computes the normalized quaternion\n     * @return A new, normalized quaternion\n     */\n    normalize(): Quat {\n        const length = this.length();\n\n        if (!length) {\n            return new Quat([0, 0, 0, 0]);\n        }\n\n        const invLength = 1 / length;\n\n        return new Quat([\n            this.x * invLength,\n            this.y * invLength,\n            this.z * invLength,\n            this.w * invLength,\n        ]);\n    }\n\n    /**\n     * Add another quaternion to this quaternion\n     * @param other The quaternion to add\n     * @return A new quaternion with the sum\n     */\n    add(other: Quat): Quat {\n        return Quat.sum(this, other);\n    }\n\n    /**\n     * Multiply this quaternion by another quaternion\n     * @param other The quaternion to multiply with\n     * @return A new quaternion with the product\n     */\n    multiply(other: Quat): Quat {\n        return Quat.product(this, other);\n    }\n\n    /**\n     * Calculate the dot product of two quaternions\n     * @param q1 First quaternion\n     * @param q2 Second quaternion\n     * @return The dot product\n     */\n    static dot(q1: Quat, q2: Quat): number {\n        return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;\n    }\n\n    /**\n     * Calculate the sum of two quaternions\n     * @param q1 First quaternion\n     * @param q2 Second quaternion\n     * @return A new quaternion with the sum\n     */\n    static sum(q1: Quat, q2: Quat): Quat {\n        return new Quat([\n            q1.x + q2.x,\n            q1.y + q2.y,\n            q1.z + q2.z,\n            q1.w + q2.w,\n        ]);\n    }\n\n    /**\n     * Calculate the product of two quaternions\n     * @param q1 First quaternion\n     * @param q2 Second quaternion\n     * @return A new quaternion with the product\n     */\n    static product(q1: Quat, q2: Quat): Quat {\n        const q1x = q1.x;\n        const q1y = q1.y;\n        const q1z = q1.z;\n        const q1w = q1.w;\n\n        const q2x = q2.x;\n        const q2y = q2.y;\n        const q2z = q2.z;\n        const q2w = q2.w;\n\n        return new Quat([\n            q1x * q2w + q1w * q2x + q1y * q2z - q1z * q2y,\n            q1y * q2w + q1w * q2y + q1z * q2x - q1x * q2z,\n            q1z * q2w + q1w * q2z + q1x * q2y - q1y * q2x,\n            q1w * q2w - q1x * q2x - q1y * q2y - q1z * q2z,\n        ]);\n    }\n\n    /**\n     * Calculate the cross product of two quaternions, i.e. (q1 * q2 - q2 * q1) / 2.\n     * For quaternions with a 0 w component, this is equivalent to the cross\n     * product of their [x, y, z] vector parts.\n     * @param q1 First quaternion\n     * @param q2 Second quaternion\n     * @return A new quaternion with the cross product\n     */\n    static cross(q1: Quat, q2: Quat): Quat {\n        return new Quat([\n            q1.y * q2.z - q1.z * q2.y,\n            q1.z * q2.x - q1.x * q2.z,\n            q1.x * q2.y - q1.y * q2.x,\n            0,\n        ]);\n    }\n\n    /**\n     * Spherical linear interpolation between two quaternions with short path\n     * @param q1 First quaternion\n     * @param q2 Second quaternion\n     * @param time Interpolation parameter (0 to 1)\n     * @return A new interpolated quaternion\n     */\n    static shortMix(q1: Quat, q2: Quat, time: number): Quat {\n        if (time <= 0.0) {\n            return new Quat(q1.xyzw);\n        } else if (time >= 1.0) {\n            return new Quat(q2.xyzw);\n        }\n\n        let cos = Quat.dot(q1, q2);\n        let q2a = q2;\n\n        if (cos < 0.0) {\n            // Negate all 4 components (not just xyz, as Quat#inverse would) to\n            // flip q2a to the equivalent rotation on the other side of the\n            // hypersphere, which is what actually shortens the path.\n            q2a = new Quat([-q2.x, -q2.y, -q2.z, -q2.w]);\n            cos = -cos;\n        }\n\n        let k0: number;\n        let k1: number;\n\n        if (cos > 0.9999) {\n            k0 = 1 - time;\n            k1 = 0 + time;\n        } else {\n            const sin: number = Math.sqrt(1 - cos * cos);\n            const angle: number = Math.atan2(sin, cos);\n\n            const oneOverSin: number = 1 / sin;\n\n            k0 = Math.sin((1 - time) * angle) * oneOverSin;\n            k1 = Math.sin((0 + time) * angle) * oneOverSin;\n        }\n\n        return new Quat([\n            k0 * q1.x + k1 * q2a.x,\n            k0 * q1.y + k1 * q2a.y,\n            k0 * q1.z + k1 * q2a.z,\n            k0 * q1.w + k1 * q2a.w,\n        ]);\n    }\n\n    /**\n     * Spherical linear interpolation between two quaternions\n     * @param q1 First quaternion\n     * @param q2 Second quaternion\n     * @param time Interpolation parameter (0 to 1)\n     * @return A new interpolated quaternion\n     */\n    static mix(q1: Quat, q2: Quat, time: number): Quat {\n        const cosHalfTheta = q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;\n\n        if (Math.abs(cosHalfTheta) >= 1.0) {\n            return new Quat(q1.xyzw);\n        }\n\n        const halfTheta = Math.acos(cosHalfTheta);\n        const sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);\n\n        if (Math.abs(sinHalfTheta) < 0.001) {\n            return new Quat([\n                q1.x * 0.5 + q2.x * 0.5,\n                q1.y * 0.5 + q2.y * 0.5,\n                q1.z * 0.5 + q2.z * 0.5,\n                q1.w * 0.5 + q2.w * 0.5,\n            ]);\n        }\n\n        const ratioA = Math.sin((1 - time) * halfTheta) / sinHalfTheta;\n        const ratioB = Math.sin(time * halfTheta) / sinHalfTheta;\n\n        return new Quat([\n            q1.x * ratioA + q2.x * ratioB,\n            q1.y * ratioA + q2.y * ratioB,\n            q1.z * ratioA + q2.z * ratioB,\n            q1.w * ratioA + q2.w * ratioB,\n        ]);\n    }\n\n    /**\n     * Create a quaternion from an axis and angle\n     * @param axis The rotation axis as a 3D vector\n     * @param angle The rotation angle in radians\n     * @return A new quaternion representing the rotation\n     * @throws Error if the axis vector is not 3D\n     */\n    static fromAxisAngle(axis: Vector, angle: number): Quat {\n        if (axis.rows !== 3) throw new Error('The axis vector must be in 3D!');\n\n        const halfAngle = angle * 0.5;\n        const sin = Math.sin(halfAngle);\n\n        return new Quat([\n            axis.at(0) * sin,\n            axis.at(1) * sin,\n            axis.at(2) * sin,\n            Math.cos(halfAngle),\n        ]);\n    }\n\n    toString(): string {\n        return `[${this._values.join(', ')}]`;\n    }\n}\n"],"mappings":";AAEA,IAAqB,IAArB,MAAqB,EAAO;CAKxB,YAAY,GAAmB;EAI3B,AAFA,KAAK,UAAc,OAAe,KAAU,CAAC,CAAC,EAAA,CAAG,MAAM,CAAC,CAAC,KAAK,CAAC,GAE3D,MACA,KAAK,SAAS;CAEtB;CAEA,IAAI,OAAO;EACP,OAAO,KAAK,OAAO;CACvB;CAEA,IAAI,SAAS;EACT,OAAO,KAAK;CAChB;CAQA,IAAI,OAAO,GAAqB;EAC5B,IAAM,IAAU,KAAK,IAAI,KAAK,OAAO,QAAQ,EAAU,MAAM;EAC7D,KAAK,IAAI,IAAI,GAAG,IAAI,GAAS,KACzB,KAAK,OAAO,KAAK,EAAU;CAEnC;CAOA,MAAM,GAAwB;EAC5B,IAAI,KAAK,SAAS,EAAO,MAAM,MAAU,MAAM,+DAA+D;EAE9G,IAAM,IADM,KAAK,IAAI,CACT,KAAO,KAAK,OAAO,IAAI,EAAO,OAAO;EACjD,OAAO,KAAK,KAAK,CAAG;CACtB;CAQA,SAAS,GAAwB;EAC/B,IAAG,KAAK,SAAS,EAAO,MAAM,MAAU,MAAM,kEAAkE;EAChH,OAAO,KAAK,SAAS,CAAM,CAAC,CAAC,OAAO;CACtC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