UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

117 lines 4.16 kB
/** * Represents a square matrix (number of rows equals number of columns). * Data is stored in a typed array. */ export class SquareMatrix { /** * @param {number} size Side length of the matrix (e.g. '3' for a 3x3 matrix). * @param {BinaryDataType|string} type Data type of the elements. Must be a valid BinaryDataType (e.g., "uint8", "float32"). * @throws {Error} If the provided type is not supported. */ constructor(size: number, type: BinaryDataType | string); /** * Side length of the matrix. * @type {number} */ size: number; /** * Data type of matrix elements. * @type {BinaryDataType} */ type: BinaryDataType; /** * Matrix data, stored as a typed array. Column-major order. * @type {number[]} */ data: number[]; /** * @returns {number} Side length of the matrix. */ get n(): number; /** * @returns {number} Total number of elements in the matrix (size * size). */ get length(): number; /** * Returns direct reference to underlying data, modifying it WILL affect the matrix. * @returns {number[]} */ get val(): number[]; /** * Fills the entire matrix with the given value. * @param {number} v Value to fill the matrix with. * @returns {void} */ fill(v: number): void; /** * Subtracts another matrix from this matrix (this = this - other). * @param {SquareMatrix} other The matrix to subtract. Must be of the same size. */ subtract(other: SquareMatrix): void; /** * Subtracts matrix 'b' from matrix 'a', storing the result in this matrix (this = a - b). * Component-wise operation. * @param {SquareMatrix} a The first matrix. * @param {SquareMatrix} b The second matrix. */ subtractMatrices(a: SquareMatrix, b: SquareMatrix): void; /** * Negates all elements of the matrix (multiplies each element by -1). */ negate(): void; /** * Sets all elements of the matrix to 0. */ clear(): void; /** * Set diagonal to 1 * NOTE: if the other cells are 0s - it will produce identity matrix, but those cells will not be written explicitly */ eye(): void; /** * Copies the elements of another matrix into this matrix. * @param {SquareMatrix} other The matrix to copy from. Must be the same size. */ copy(other: SquareMatrix): void; /** * Creates a new matrix that is a copy of this matrix. * @returns {SquareMatrix} A new matrix with the same elements. */ clone(): SquareMatrix; /** * Transposes the matrix in-place (swaps rows and columns). */ transpose(): void; /** * Populates matrix from a 1D array. * @param {number[]} arr Source array. Must have at least size*size elements. */ fromArray(arr: number[]): void; /** * Copies matrix elements into a 1D array. * @param {number[]} [destination] Array to store matrix into. Creates a new array if not provided. * @param {number} [offset=0] Starting index in the destination array. * @returns {number[]} The array containing the matrix data. */ toArray(destination?: number[], offset?: number): number[]; /** * Sets the value of a cell in the matrix. * @param {number} row_index Row index (0-based). * @param {number} column_index Column index (0-based). * @param {number} value The value to set. */ setCellValue(row_index: number, column_index: number, value: number): void; /** * Retrieves the value of a cell in the matrix. * @param {number} row_index Row index (0-based). * @param {number} column_index Column index (0-based). * @returns {number} The value of the cell. */ getCellValue(row_index: number, column_index: number): number; /** * Read values at the diagonal, from left to right, top to bottom * @param {number[]|Float32Array|Float64Array} result Array to store the diagonal. */ readDiagonal(result: number[] | Float32Array | Float64Array): void; } //# sourceMappingURL=SquareMatrix.d.ts.map