@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
26 lines (23 loc) • 783 B
JavaScript
/**
* N-dimensional dot product over offset slices of two flat buffers.
*
* sum_{i=0..n-1} a[aOff + i] * b[bOff + i]
*
* Use when the operands are columns/rows of a flat matrix laid out in a
* single typed array — passing the buffer plus an offset avoids the header
* allocation that `.subarray(...)` would incur on every call.
*
* @param {number[]|Float32Array|Float64Array} a
* @param {number} aOff starting index into a
* @param {number[]|Float32Array|Float64Array} b
* @param {number} bOff starting index into b
* @param {number} n number of elements
* @return {number}
*/
export function vector_dot_offset(a, aOff, b, bOff, n) {
let result = 0;
for (let i = 0; i < n; i++) {
result += a[aOff + i] * b[bOff + i];
}
return result;
}