Class MutableMatrix22

A mutable 2x2 matrix class that extends Matrix22 and provides modification capabilities. This class allows in-place operations for matrix transformations, making it suitable for performance-critical applications where object creation overhead should be minimized.

The matrix is stored in column-major order as a Float32Array, compatible with WebGL. Matrix layout:

| m00 m01 |
| m10 m11 |
const matrix = MutableMatrix22.identity();
matrix.rotate(Math.PI / 4); // Rotate 45 degrees
matrix.scale(Vector2.fromCopyArray([2, 3])); // Scale by 2x and 3y

Hierarchy (view full)

Implements

Constructors

Properties

_v: Float32Array = ...

Internal Float32Array storage for matrix elements

Accessors

  • get isIdentityMatrixClass(): boolean
  • Indicates whether this matrix is an identity matrix class.

    This property should be overridden in derived classes that represent identity matrices to return true.

    Returns boolean

    False for the base AbstractMatrix class

  • get compositionType(): CompositionTypeClass<"MAT2">
  • Gets the composition type for this matrix.

    Returns CompositionTypeClass<"MAT2">

    The CompositionType.Mat2 enum value

Methods

  • Gets the matrix element at the specified row and column.

    Parameters

    • row_i: number

      The row index (0 or 1)

    • column_i: number

      The column index (0 or 1)

    Returns number

    The matrix element at the specified position

    const mat = Matrix22.identity();
    const m01 = mat.at(0, 1); // Returns 0
  • Calculates the determinant of this 2x2 matrix.

    For a 2x2 matrix | a b |, the determinant is ad - bc. | c d |

    Returns number

    The determinant value

    const mat = Matrix22.fromCopy4RowMajor(2, 3, 1, 4);
    const det = mat.determinant(); // Returns 2*4 - 3*1 = 5
  • Extracts the scale factors from this transformation matrix. Calculates the length of each column vector to determine the scale.

    Returns Vector2

    A Vector2 containing the scale factors for x and y axes

    const scaleAndRotation = Matrix22.multiply(
    Matrix22.scale(Vector2.fromCopyArray2([2, 3])),
    Matrix22.rotate(Math.PI / 4)
    );
    const scale = scaleAndRotation.getScale(); // Returns approximately [2, 3]
  • Checks if this matrix is approximately equal to another matrix within a tolerance.

    Parameters

    • mat: Matrix22

      The matrix to compare with

    • delta: number = Number.EPSILON

      The tolerance for comparison (default: Number.EPSILON)

    Returns boolean

    True if all corresponding elements are within the tolerance

  • Checks if the matrix's internal storage shares the same ArrayBuffer as the provided one.

    This method is useful for determining if two matrices share the same underlying memory, which can be important for performance optimizations and avoiding unnecessary data copying.

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer to compare against

    Returns boolean

    True if the internal storage uses the same ArrayBuffer, false otherwise

  • Gets the matrix element at the specified flat index.

    This provides direct access to the underlying Float32Array storage using a single index rather than row/column coordinates.

    Parameters

    • i: number

      The zero-based flat index into the matrix storage

    Returns number

    The matrix element value at the specified index

  • Creates a new matrix from values provided in row-major order. This is more intuitive for manual input as values are specified in the same order they appear visually in the matrix.

    Parameters

    • m00: number

      Value for position (0,0)

    • m01: number

      Value for position (0,1)

    • m10: number

      Value for position (1,0)

    • m11: number

      Value for position (1,1)

    Returns MutableMatrix22

    A new MutableMatrix22 instance

  • Calculates the inverse of the given matrix and stores the result in the output matrix. This method avoids creating a new matrix instance for better performance.

    Parameters

    Returns MutableMatrix22

    The output matrix containing the inverse

    Error if the matrix is singular (determinant is 0)

  • Multiplies two matrices and stores the result in the output matrix. This method avoids creating a new matrix instance for better performance.

    Note: The parameter types suggest Matrix33, but this appears to be a bug as this should operate on Matrix22 instances.

    Parameters

    Returns MutableMatrix22

    The output matrix containing the product