@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
29 lines (22 loc) • 540 B
JavaScript
import AABB2 from "../core/geom/2d/aabb/AABB2.js";
/**
*
* @param {Element} el
* @returns {AABB2}
*/
export function html_element_to_aabb(el) {
const clientRect = el.getBoundingClientRect();
let x0 = clientRect.left;
let y0 = clientRect.top;
let x1 = clientRect.right;
let y1 = clientRect.bottom;
// sanitize bounds
if (Number.isNaN(x1)) {
x1 = x0;
}
if (Number.isNaN(y1)) {
y1 = y0;
}
// write bounds
return new AABB2(x0, y0, x1, y1);
}