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)

    Implements

    Index

    Constructors

    Properties

    _v: Float32Array = ...

    Internal Float32Array storage for matrix elements

    Accessors

    • 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 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

    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 column-major order. This matches the internal storage format used by WebGL.

      Parameters

      • m00: number

        Value for position (0,0)

      • m10: number

        Value for position (1,0)

      • m01: number

        Value for position (0,1)

      • m11: number

        Value for position (1,1)

      Returns MutableMatrix22

      A new MutableMatrix22 instance

    • 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