20 lines
621 B
TypeScript
20 lines
621 B
TypeScript
import { expect, test } from "vitest";
|
|
import { vec } from "./given.ts";
|
|
import { resolve } from "./resolve.ts";
|
|
|
|
test("no collision -> full move", () => {
|
|
expect(resolve(vec(0, 0), vec(10, 5), null)).toEqual({ x: 10, y: 5 });
|
|
});
|
|
|
|
test("collision at t=0.3 -> stop at contact", () => {
|
|
const hit = { time: 0.3, normal: vec(-1, 0) };
|
|
const p = resolve(vec(0, 0), vec(10, 0), hit);
|
|
expect(p.x).toBeCloseTo(3);
|
|
expect(p.y).toBeCloseTo(0);
|
|
});
|
|
|
|
test("collision at t=0 -> don't move at all", () => {
|
|
const hit = { time: 0, normal: vec(-1, 0) };
|
|
expect(resolve(vec(5, 5), vec(10, 10), hit)).toEqual({ x: 5, y: 5 });
|
|
});
|