@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
17 lines (15 loc) • 571 B
JavaScript
/**
* Transposes a 2x2 matrix, stored in a flattened array.
*
* @param {number[]} out Output: The transposed matrix. Can be the same array as `m`.
* @param {number[]} m Input: The 2x2 matrix to transpose, stored as a flattened array [a, b, c, d], representing [[a, c], [b, d]].
* @returns {number[]} The `out` parameter.
*/
export function m2_transpose(out, m) {
const b = m[1]; // Cache m[1] (which becomes m[2] after the swap)
out[0] = m[0];
out[1] = m[2];
out[2] = b; // Use the cached value
out[3] = m[3];
return out;
}