Files
2026-07-11 17:48:28 +02:00

19 lines
607 B
TypeScript

export type Vec = { x: number; y: number };
/** Axis-aligned box: (x,y) is the top-left corner, w/h are width/height. */
export type AABB = { x: number; y: number; w: number; h: number };
/** Is the point inside (or on the edge of) the box? */
export function pointInAABB(p: Vec, box: AABB): boolean {
return (
p.x >= box.x && p.x <= box.x + box.w && p.y >= box.y && p.y <= box.y + box.h
);
}
/** Do the two boxes overlap right now? (discrete test) */
export function aabbOverlap(a: AABB, b: AABB): boolean {
return (
a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
);
}