32 lines
752 B
TypeScript
32 lines
752 B
TypeScript
export interface Point
|
|
{
|
|
x: number;
|
|
y: number;
|
|
}
|
|
export interface AABB
|
|
{
|
|
x1: number;
|
|
y1: number;
|
|
x2: number;
|
|
y2: number;
|
|
}
|
|
|
|
export function intersectsObj(a: AABB, b: AABB | Point): Boolean
|
|
{
|
|
if(b.hasOwnProperty("x") && b.hasOwnProperty("y"))
|
|
{
|
|
b = b as Point;
|
|
|
|
return a.x1 <= b.x && a.x2 >= b.x && a.y1 <= b.y && a.y2 >= b.y;
|
|
}
|
|
else
|
|
{
|
|
b = b as AABB;
|
|
|
|
return a.x1 <= b.x2 && a.x2 >= b.x1 && a.y1 <= b.y2 && a.y2 >= b.y1;
|
|
}
|
|
}
|
|
export function intersects(aLeft: number, aTop: number, aRight: number, aBottom: number, bLeft: number, bTop: number, bRight: number, bBottom: number): Boolean
|
|
{
|
|
return aLeft <= bRight && aRight >= bLeft && aTop <= bBottom && aBottom >= bTop;
|
|
} |