rhodonite
    Preparing search index...

    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 Summary)

    Index
    _v: TypedArray = ...

    Internal typed array storage for matrix elements (Float32Array or Float64Array)

    • get className(): string

      Gets the class name for debugging purposes.

      Returns string

      The class name "MutableMatrix22"

    • get glslStrAsFloat(): string

      Gets the GLSL string representation of the matrix as float values.

      Returns string

      GLSL-formatted string for float values

      Error - Must be implemented by subclasses

    • get glslStrAsInt(): string

      Gets the GLSL string representation of the matrix as integer values.

      Returns string

      GLSL-formatted string for integer values

      Error - Must be implemented by subclasses

    • get glslStrAsUint(): string

      Gets the GLSL string representation of the matrix as unsigned integer values.

      Returns string

      GLSL-formatted string for unsigned integer values with 'u' suffix

      Error - Must be implemented by subclasses

    • 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 m00(): number

      Gets the value at position (0,0) of the matrix.

      Returns number

      The value at position (0,0)

    • set m00(val: number): void

      Sets the value at position (0,0) of the matrix.

      Parameters

      • val: number

        The value to set

      Returns void

    • get m01(): number

      Gets the value at position (0,1) of the matrix.

      Returns number

      The value at position (0,1)

    • set m01(val: number): void

      Sets the value at position (0,1) of the matrix.

      Parameters

      • val: number

        The value to set

      Returns void

    • get m10(): number

      Gets the value at position (1,0) of the matrix.

      Returns number

      The value at position (1,0)

    • set m10(val: number): void

      Sets the value at position (1,0) of the matrix.

      Parameters

      • val: number

        The value to set

      Returns void

    • get m11(): number

      Gets the value at position (1,1) of the matrix.

      Returns number

      The value at position (1,1)

    • set m11(val: number): void

      Sets the value at position (1,1) of the matrix.

      Parameters

      • val: number

        The value to set

      Returns void

    • get wgslStrAsFloat(): string

      Gets the WGSL string representation of the matrix as float values.

      Returns string

      WGSL-formatted string for float values

      Error - Must be implemented by subclasses

    • get wgslStrAsInt(): string

      Gets the WGSL string representation of the matrix as integer values.

      Returns string

      WGSL-formatted string for integer values

      Error - Must be implemented by subclasses

    • get wgslStrAsUint(): string

      Gets the WGSL string representation of the matrix as unsigned integer values.

      Returns string

      WGSL-formatted string for unsigned integer values with 'u' suffix

      Error - Must be implemented by subclasses

    • get compositionType(): CompositionTypeClass<"MAT2">

      Gets the composition type for this matrix.

      Returns CompositionTypeClass<"MAT2">

      The CompositionType.Mat2 enum value

    • Internal helper method to swap two elements in the matrix array.

      Parameters

      • l: number

        Index of the first element

      • r: number

        Index of the second element

      Returns void

    • 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
    • Returns the matrix elements as a flat array in column-major order.

      Returns number[]

      An array containing [m00, m10, m01, m11]

    • 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]
    • Extracts the scale factors from this transformation matrix and stores them in the output vector. This method avoids creating a new vector instance for better performance.

      Parameters

      • outVec: MutableVector2

        The mutable vector to store the scale factors

      Returns MutableVector2

      The output vector containing the scale factors

    • Inverts this matrix in place.

      If the matrix is numerically singular, it is set to the identity matrix instead of being filled with Infinity/NaN. Use MutableMatrix22.tryInvert when the caller needs to detect the failure.

      Returns MutableMatrix22

      This matrix instance for method chaining

    • Checks if this is a dummy matrix (empty data).

      Returns boolean

      True if the matrix has no data, false otherwise

    • 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 this matrix is exactly equal to another matrix. Uses strict equality comparison for all elements.

      Parameters

      • mat: Matrix22

        The matrix to compare with

      Returns boolean

      True if all corresponding elements are exactly equal

    • 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

    • Multiplies this matrix by a 2D vector and returns the result.

      Parameters

      • vec: Vector2

        The 2D vector to multiply

      Returns Vector2

      A new Vector2 containing the transformed vector

      const rotation = Matrix22.rotate(Math.PI / 2);
      const vec = Vector2.fromCopyArray2([1, 0]);
      const result = rotation.multiplyVector(vec); // Rotates (1,0) to (0,1)
    • Gets the raw Float32Array containing the matrix data.

      Returns TypedArray

      The internal Float32Array in column-major order

    • Sets this matrix to a rotation matrix for the given angle.

      Parameters

      • radian: number

        The rotation angle in radians

      Returns MutableMatrix22

      This matrix instance for method chaining

    • Sets the value at the specified row and column position.

      Parameters

      • row_i: number

        The row index (0-1)

      • column_i: number

        The column index (0-1)

      • value: number

        The value to set

      Returns MutableMatrix22

      This matrix instance for method chaining

    • Sets all matrix components directly.

      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

      This matrix instance for method chaining

    • Returns a string representation of the matrix in a readable format.

      Returns string

      A string showing the matrix in 2x2 layout

      const mat = Matrix22.identity();
      console.log(mat.toString());
      // Output:
      // 1 0
      // 0 1
    • Returns an approximate string representation of the matrix with rounded values. Uses financial rounding for cleaner display of floating-point numbers.

      Returns string

      A string showing the matrix with rounded values

    • Attempts to invert this matrix in place.

      The matrix is left unchanged when it is numerically singular, which lets callers keep the previous valid value.

      Returns boolean

      True if the inversion succeeded, false if the matrix is singular

    • 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 Matrix22 from individual components in column-major order.

      Column-major means you specify values column by column: First column: m00, m10 Second column: m01, m11

      Note: WebGL matrices are stored in column-major order internally.

      Parameters

      • m00: number

        Element at row 0, column 0

      • m10: number

        Element at row 1, column 0

      • m01: number

        Element at row 0, column 1

      • m11: number

        Element at row 1, column 1

      • type: FloatTypedArrayConstructor

      Returns IMatrix22

      A new Matrix22 with the specified values

    • Creates a new Matrix22 from individual components in row-major order.

      Row-major means you specify values as they appear visually:

      | m00 m01 |
      | m10 m11 |

      Note: Internally, WebGL matrices are stored in column-major order.

      Parameters

      • m00: number

        Element at row 0, column 0

      • m01: number

        Element at row 0, column 1

      • m10: number

        Element at row 1, column 0

      • m11: number

        Element at row 1, column 1

      • type: FloatTypedArrayConstructor

      Returns IMatrix22

      A new Matrix22 with the specified values

      const mat = Matrix22.fromCopy4RowMajor(1, 2, 3, 4);
      // Creates:
      // | 1 2 |
      // | 3 4 |
    • Creates the inverse of the given matrix.

      For a 2x2 matrix, the inverse is calculated using the formula: A^(-1) = (1/det(A)) * | d -b | |-c a | where A = | a b | and det(A) = ad - bc | c d |

      If the matrix is numerically singular, an identity matrix is returned instead of dividing by zero. Use Matrix22.tryInvert when the caller needs to detect the failure.

      Parameters

      Returns IMatrix22

      A new Matrix22 that is the inverse of the input matrix, or the identity matrix if the input is singular

      const mat = Matrix22.fromCopy4RowMajor(2, 0, 0, 2);
      const inverse = Matrix22.invert(mat);
      // Returns:
      // | 0.5 0 |
      // | 0 0.5 |
    • 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.

      If the matrix is numerically singular, the output matrix is set to the identity matrix instead of being filled with Infinity/NaN. Use Matrix22.tryInvertTo when the caller needs to detect the failure.

      Parameters

      Returns IMutableMatrix22

      The output matrix containing the inverse, or the identity matrix if the input is singular

    • Multiplies two 2x2 matrices and returns the result. Matrix multiplication is not commutative: A * B ≠ B * A in general.

      Parameters

      Returns IMatrix22

      A new Matrix22 containing the product l_mat * r_mat

      const a = Matrix22.scale(Vector2.fromCopyArray2([2, 2]));
      const b = Matrix22.rotate(Math.PI / 4);
      const result = Matrix22.multiply(a, b); // Scale then rotate
    • 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 IMutableMatrix22

      The output matrix containing the product

    • Creates a 2D rotation matrix for the given angle.

      The rotation matrix is: | cos(θ) -sin(θ) | | sin(θ) cos(θ) |

      Parameters

      Returns IMatrix22

      A new Matrix22 representing the rotation transformation

      // 90-degree counter-clockwise rotation
      const rotation = Matrix22.rotate(Math.PI / 2);
    • Creates a 2D scaling matrix from a 2D vector.

      The scaling matrix is: | sx 0 | | 0 sy |

      Parameters

      Returns IMatrix22

      A new Matrix22 representing the scaling transformation

      const scale = Matrix22.scale(Vector2.fromCopyArray2([2, 3]));
      // Creates a matrix that scales x by 2 and y by 3
    • Creates the transpose of the given matrix. The transpose swaps rows and columns: (i,j) becomes (j,i).

      Parameters

      Returns IMatrix22

      A new Matrix22 that is the transpose of the input matrix

      const mat = Matrix22.fromCopy4RowMajor(1, 2, 3, 4);
      const transposed = Matrix22.transpose(mat);
      // Original: Transposed:
      // | 1 2 | -> | 1 3 |
      // | 3 4 | | 2 4 |
    • Attempts to calculate the inverse of the given matrix and stores the result in the output matrix.

      The output matrix is left untouched when the input is numerically singular, which lets callers keep the previous valid value.

      Parameters

      Returns boolean

      True if the inversion succeeded, false if the matrix is singular

    • Creates a matrix from column-major components.

      Parameters

      • m00: number
      • m10: number
      • m01: number
      • m11: number

      Returns MutableMatrix22

    • Creates a matrix from row-major components.

      Parameters

      • m00: number
      • m01: number
      • m10: number
      • m11: number

      Returns MutableMatrix22

    • Creates a matrix from a 4-element array in column-major order.

      Parameters

      Returns MutableMatrix22

    • Creates a matrix from a 4-element array in row-major order.

      Parameters

      Returns MutableMatrix22

    • Creates a matrix from an array in column-major order.

      Parameters

      • array: number[]

      Returns MutableMatrix22

    • Creates a matrix from an array in row-major order.

      Parameters

      • array: number[]

      Returns MutableMatrix22

    • Creates a matrix by copying a Float32Array in column-major order.

      Parameters

      • array: Float32Array

      Returns MutableMatrix22

    • Creates a matrix by copying a Float32Array in row-major order.

      Parameters

      • array: Float32Array

      Returns MutableMatrix22

    • Creates a matrix that directly uses the given Float32Array.

      Parameters

      • array: Float32Array

      Returns MutableMatrix22

    • Creates a 2D rotation matrix.

      Parameters

      • radian: number

      Returns MutableMatrix22

    • Attempts to invert the given matrix into outMat.

      Type Parameters

      Parameters

      Returns boolean