Creates a new Matrix22 instance.
Float32Array containing matrix values in column-major order
Gets the class name for this matrix type.
The string 'Matrix22'
Indicates whether this matrix is an identity matrix class.
This property should be overridden in derived classes that represent identity matrices to return true.
False for the base AbstractMatrix class
Gets the matrix element at row 0, column 0.
The m00 component of the matrix
Gets the matrix element at row 0, column 1.
The m01 component of the matrix
Gets the matrix element at row 1, column 0.
The m10 component of the matrix
Gets the matrix element at row 1, column 1.
The m11 component of the matrix
StaticcompositionGets the composition type for this matrix.
The CompositionType.Mat2 enum value
Creates a deep copy of this matrix.
A new Matrix22 instance with the same values
Returns the matrix elements as a flat array in column-major order.
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.
A Vector2 containing the scale factors for x and y axes
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.
The mutable vector to store the scale factors
The output vector containing the scale factors
Checks if this is a dummy matrix (empty data).
True if the matrix has no data, false otherwise
Checks if this matrix is approximately equal to another matrix within a tolerance.
The matrix to compare with
The tolerance for comparison (default: Number.EPSILON)
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.
The matrix to compare with
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.
The ArrayBuffer to compare against
True if the internal storage uses the same ArrayBuffer, false otherwise
Multiplies this matrix by a 2D vector and stores the result in the output vector. This method avoids creating a new vector instance for better performance.
The 2D vector to multiply
The mutable vector to store the result
The output vector containing the transformed vector
Returns an approximate string representation of the matrix with rounded values. Uses financial rounding for cleaner display of floating-point numbers.
A string showing the matrix with rounded values
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.
The zero-based flat index into the matrix storage
The matrix element value at the specified index
StaticdummyCreates a dummy matrix with empty data. Used as a placeholder when no valid matrix data is available.
A new Matrix22 with empty Float32Array
StaticfromCreates 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.
Element at row 0, column 0
Element at row 1, column 0
Element at row 0, column 1
Element at row 1, column 1
A new Matrix22 with the specified values
StaticfromCreates 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.
Element at row 0, column 0
Element at row 0, column 1
Element at row 1, column 0
Element at row 1, column 1
A new Matrix22 with the specified values
StaticfromStaticfromStaticfromCreates a new Matrix22 from a variable-length array in column-major order. Only the first 4 elements are used.
Array containing matrix values in column-major order
A new Matrix22 with the first 4 array values
StaticfromCreates a new Matrix22 from a variable-length array in row-major order. Only the first 4 elements are used.
Array containing matrix values in row-major order
A new Matrix22 with values converted to column-major order
StaticfromCreates a new Matrix22 by copying values from a Float32Array in column-major order.
Float32Array containing matrix values in column-major order
A new Matrix22 with copied values
StaticfromCreates a new Matrix22 by copying values from a Float32Array in row-major order.
Float32Array containing matrix values in row-major order
A new Matrix22 with values converted to column-major order
StaticfromStaticfromCreates a new Matrix22 that directly uses the provided Float32Array. The array is used as-is without copying, so modifications to the array will affect the matrix.
Float32Array containing matrix values in column-major order
A new Matrix22 using the provided array
StaticidentityStaticinvertCreates 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 |
The matrix to invert
A new Matrix22 that is the inverse of the input matrix
StaticinvertCalculates 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.
The matrix to invert
The mutable matrix to store the result
The output matrix containing the inverse
StaticmultiplyMultiplies two 2x2 matrices and returns the result. Matrix multiplication is not commutative: A * B ≠ B * A in general.
A new Matrix22 containing the product l_mat * r_mat
StaticmultiplyMultiplies 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.
The left matrix operand
The right matrix operand
The mutable matrix to store the result
The output matrix containing the product
StaticrotateCreates a 2D rotation matrix for the given angle.
The rotation matrix is: | cos(θ) -sin(θ) | | sin(θ) cos(θ) |
The rotation angle in radians (positive values rotate counter-clockwise)
A new Matrix22 representing the rotation transformation
StaticscaleStatictransposeStaticzero
A 2x2 matrix class for 2D transformations and linear algebra operations.
This immutable matrix class supports common 2D transformations including rotation, scaling, and general linear transformations. The matrix data is stored in column-major order as a Float32Array for WebGL compatibility.
Matrix layout:
Example