@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
36 lines (29 loc) • 1.09 kB
JavaScript
import { max2 } from "../../../math/max2.js";
import { min2 } from "../../../math/min2.js";
/**
* Merge bounds of two axis-aligned bounding boxes, the result is a box that tightly bounds inputs
* @param {ArrayLike<number>|number[]|Float32Array} result where resulting value is written to
* @param {number} result_offset
* @param {ArrayLike<number>|number[]|Float32Array} a
* @param {number} a_offset
* @param {ArrayLike<number>|number[]|Float32Array} b
* @param {number} b_offset
*/
export function aabb2_array_combine(
result, result_offset,
a, a_offset,
b, b_offset
) {
const a_x0 = a[a_offset];
const a_y0 = a[a_offset + 1];
const a_x1 = a[a_offset + 2];
const a_y1 = a[a_offset + 3];
const b_x0 = b[b_offset];
const b_y0 = b[b_offset + 1];
const b_x1 = b[b_offset + 2];
const b_y1 = b[b_offset + 3];
result[result_offset] = min2(a_x0, b_x0);
result[result_offset + 1] = min2(a_y0, b_y0);
result[result_offset + 2] = max2(a_x1, b_x1);
result[result_offset + 3] = max2(a_y1, b_y1);
}