30 lines
963 B
TypeScript
30 lines
963 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { sweepInterval } from "./sweep1d.ts";
|
|
|
|
test("moving right into the interval", () => {
|
|
// point at 0, moves +10 this frame, interval [5, 8]
|
|
// enters at (5-0)/10 = 0.5, exits at (8-0)/10 = 0.8
|
|
const s = sweepInterval(0, 10, 5, 8)!;
|
|
expect(s.entry).toBeCloseTo(0.5);
|
|
expect(s.exit).toBeCloseTo(0.8);
|
|
});
|
|
|
|
test("moving left: entry/exit are swapped into order", () => {
|
|
// point at 10, moves -10, interval [5, 8]
|
|
// crosses 8 at t=0.2, crosses 5 at t=0.5 -> entry 0.2, exit 0.5
|
|
const s = sweepInterval(10, -10, 5, 8)!;
|
|
expect(s.entry).toBeCloseTo(0.2);
|
|
expect(s.exit).toBeCloseTo(0.5);
|
|
expect(s.entry).toBeLessThanOrEqual(s.exit);
|
|
});
|
|
|
|
test("not moving but already inside -> infinite span", () => {
|
|
const s = sweepInterval(6, 0, 5, 8)!;
|
|
expect(s.entry).toBe(-Infinity);
|
|
expect(s.exit).toBe(Infinity);
|
|
});
|
|
|
|
test("not moving and outside -> null", () => {
|
|
expect(sweepInterval(2, 0, 5, 8)).toBeNull();
|
|
});
|