@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
43 lines (35 loc) • 842 B
JavaScript
import { max2 } from "../../../math/max2.js";
import { min2 } from "../../../math/min2.js";
/**
*
* @param {number} ax0
* @param {number} ay0
* @param {number} ax1
* @param {number} ay1
* @param {number} bx0
* @param {number} by0
* @param {number} bx1
* @param {number} by1
* @param {AABB2} result
* @returns {boolean} true if overlap exists, false if no overlap
*/
export function aabb2_compute_overlap(
ax0, ay0, ax1, ay1,
bx0, by0, bx1, by1,
result
) {
const x0 = max2(ax0, bx0);
const x1 = min2(ax1, bx1);
if (x0 >= x1) {
//no overlap
return false;
}
const y0 = max2(ay0, by0);
const y1 = min2(ay1, by1);
if (y0 >= y1) {
//no overlap
return false;
}
result.set(x0, y0, x1, y1);
return true;
}