Files
nage/workshop/steps/04-aabb/aabb.test.ts
T
2026-07-11 17:48:28 +02:00

29 lines
901 B
TypeScript

import { expect, test } from "bun:test";
import { type AABB, aabbOverlap, pointInAABB } from "./aabb.ts";
const box: AABB = { x: 10, y: 10, w: 20, h: 20 }; // spans 10..30 in both axes
test("point inside the box", () => {
expect(pointInAABB({ x: 15, y: 15 }, box)).toBe(true);
});
test("point outside the box", () => {
expect(pointInAABB({ x: 5, y: 15 }, box)).toBe(false);
expect(pointInAABB({ x: 15, y: 35 }, box)).toBe(false);
});
test("overlapping boxes", () => {
const other: AABB = { x: 20, y: 20, w: 20, h: 20 };
expect(aabbOverlap(box, other)).toBe(true);
});
test("separated on the x axis only -> no overlap", () => {
const other: AABB = { x: 40, y: 10, w: 5, h: 20 };
expect(aabbOverlap(box, other)).toBe(false);
});
test("separated on the y axis only -> no overlap", () => {
const other: AABB = { x: 10, y: 40, w: 20, h: 5 };
expect(aabbOverlap(box, other)).toBe(false);
});