UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

117 lines 3.99 kB
/** * Represents a physical unit as a vector of exponents over the 7 SI base dimensions. * * Composition rules: * - multiplying two units adds their exponents component-wise (e.g. m * s = m·s, m * m = m^2) * - dividing two units subtracts their exponents (e.g. m / s = m/s, m / m = dimensionless) * - raising a unit to a power scales every exponent by that power (e.g. m^3 = volume) * * Storage uses a fixed-size {@link Float64Array} so fractional exponents (e.g. sqrt of a unit) * are representable, and so that composition can be performed without per-call allocation. */ export class UnitMatrix { /** * Exponent for each SI base dimension, indexed by {@link UnitDimension}. * @type {Float64Array} */ exponents: Float64Array; /** * Set the exponent of a single base dimension. * @param {number} dimension Index from {@link UnitDimension}. * @param {number} value */ set_exponent(dimension: number, value: number): void; /** * Read the exponent of a single base dimension. * @param {number} dimension Index from {@link UnitDimension}. * @returns {number} */ get_exponent(dimension: number): number; /** * Bulk-set every dimension exponent in a single call. * @param {number} length * @param {number} mass * @param {number} time * @param {number} electric_current * @param {number} temperature * @param {number} amount_of_substance * @param {number} luminous_intensity * @returns {this} */ set(length: number, mass: number, time: number, electric_current: number, temperature: number, amount_of_substance: number, luminous_intensity: number): this; /** * Reset to dimensionless (every exponent is 0). */ set_zero(): void; /** * Copy values from another unit matrix. * @param {UnitMatrix} other */ copy(other: UnitMatrix): void; /** * Allocate a new unit matrix with the same exponents. * @returns {UnitMatrix} */ clone(): UnitMatrix; /** * Strict structural equality between two unit matrices. * Two matrices are equal when every exponent matches exactly. * @param {UnitMatrix} other * @returns {boolean} */ equals(other: UnitMatrix): boolean; /** * Whether this matrix represents a dimensionless quantity (all exponents are 0). * @returns {boolean} */ is_dimensionless(): boolean; /** * Multiply this matrix by another in-place (this *= other). * Adds exponents component-wise. * @param {UnitMatrix} other */ multiply(other: UnitMatrix): void; /** * Divide this matrix by another in-place (this /= other). * Subtracts exponents component-wise. * @param {UnitMatrix} other */ divide(other: UnitMatrix): void; /** * Store the product a * b into this matrix (this = a * b). * Safe to call with this === a or this === b. * @param {UnitMatrix} a * @param {UnitMatrix} b */ multiply_matrices(a: UnitMatrix, b: UnitMatrix): void; /** * Store the quotient a / b into this matrix (this = a / b). * Safe to call with this === a or this === b. * @param {UnitMatrix} a * @param {UnitMatrix} b */ divide_matrices(a: UnitMatrix, b: UnitMatrix): void; /** * Raise this matrix to a power in-place (this **= n). * @param {number} n */ power(n: number): void; /** * Store a ** n into this matrix (this = a ** n). * Safe to call with this === a. * @param {UnitMatrix} a * @param {number} n */ power_of_matrix(a: UnitMatrix, n: number): void; /** * Invert in-place: every exponent is negated, so this becomes 1 / this. */ invert(): void; /** * Store 1 / a into this matrix. * Safe to call with this === a. * @param {UnitMatrix} a */ invert_matrix(a: UnitMatrix): void; } //# sourceMappingURL=UnitMatrix.d.ts.map