UNPKG

@rpgjs/physic

Version:

A deterministic 2D top-down physics library for RPG, sandbox and MMO games

130 lines 3.45 kB
/** * 2x2 Matrix class for 2D rotations and transformations * * Used for rotating vectors and handling 2D transformations. * All operations are deterministic. * * @example * ```typescript * const rotation = Matrix2.fromAngle(Math.PI / 4); * const rotated = rotation.multiplyVector(new Vector2(1, 0)); * ``` */ export declare class Matrix2 { /** * Matrix elements in column-major order: * [m00, m10] * [m01, m11] */ m00: number; m01: number; m10: number; m11: number; /** * Creates a new 2x2 matrix * * @param m00 - Element at row 0, column 0 * @param m01 - Element at row 0, column 1 * @param m10 - Element at row 1, column 0 * @param m11 - Element at row 1, column 1 */ constructor(m00?: number, m01?: number, m10?: number, m11?: number); /** * Creates an identity matrix * * @returns Identity matrix */ static identity(): Matrix2; /** * Creates a rotation matrix from an angle * * @param angle - Rotation angle in radians * @returns Rotation matrix */ static fromAngle(angle: number): Matrix2; /** * Creates a copy of this matrix * * @returns New matrix with the same values */ clone(): Matrix2; /** * Copies values from another matrix * * @param other - Matrix to copy from * @returns This matrix for chaining */ copyFrom(other: Matrix2): Matrix2; /** * Multiplies this matrix by another matrix * * @param other - Matrix to multiply with * @returns New matrix with the result */ multiply(other: Matrix2): Matrix2; /** * Multiplies this matrix by another matrix (in-place) * * @param other - Matrix to multiply with * @returns This matrix for chaining */ multiplyInPlace(other: Matrix2): Matrix2; /** * Multiplies a vector by this matrix (transforms the vector) * * @param x - Vector X component * @param y - Vector Y component * @returns Object with transformed x and y */ multiplyVector(x: number, y: number): { x: number; y: number; }; /** * Calculates the determinant of this matrix * * @returns Determinant value */ determinant(): number; /** * Calculates the inverse of this matrix * * @returns New inverted matrix * @throws Error if matrix is singular (determinant is zero) */ inverse(): Matrix2; /** * Transposes this matrix * * @returns New transposed matrix */ transpose(): Matrix2; /** * Sets this matrix to a rotation matrix * * @param angle - Rotation angle in radians * @returns This matrix for chaining */ setRotation(angle: number): Matrix2; /** * Extracts the rotation angle from this matrix * * @returns Rotation angle in radians */ getAngle(): number; /** * Checks if this matrix equals another (with epsilon tolerance) * * @param other - Matrix to compare * @param epsilon - Tolerance for comparison (default: 1e-5) * @returns True if matrices are approximately equal */ equals(other: Matrix2, epsilon?: number): boolean; /** * Returns a string representation of this matrix * * @returns String representation */ toString(): string; } //# sourceMappingURL=Matrix2.d.ts.map