time for a snapshot
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user