@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
29 lines (28 loc) • 980 B
JavaScript
/**
* Applies a Givens rotation (c, s) to two row vectors in place:
*
* row_i' = c * row_i + s * row_j
* row_j' = -s * row_i + c * row_j
*
* Each row is treated as a length-n vector and rotated element-by-element.
*
* Accepts plain arrays or typed arrays. The two row arguments can be
* standalone arrays or subarray views into a larger flat matrix — useful
* for row-major QR/Hessenberg maintenance where the matrix is a single
* Float64Array and the caller hands in `M.subarray(i*n, (i+1)*n)` and
* `M.subarray(j*n, (j+1)*n)`.
*
* @param {Float64Array|number[]} row_i length >= n
* @param {Float64Array|number[]} row_j length >= n
* @param {number} c
* @param {number} s
* @param {number} n number of elements to rotate
*/
export function givens_apply_rows(row_i, row_j, c, s, n) {
for (let i = 0; i < n; ++i) {
const a = row_i[i];
const b = row_j[i];
row_i[i] = c * a + s * b;
row_j[i] = c * b - s * a;
}
}