time for a snapshot
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { dot, vec } from "./given.ts";
|
||||
import { slide } from "./slide.ts";
|
||||
|
||||
test("vertical wall kills horizontal motion, keeps vertical", () => {
|
||||
// moving (10,5) into a wall with normal (-1,0)
|
||||
const s = slide(vec(10, 5), vec(-1, 0));
|
||||
expect(s.x).toBeCloseTo(0);
|
||||
expect(s.y).toBeCloseTo(5);
|
||||
});
|
||||
|
||||
test("horizontal wall kills vertical motion, keeps horizontal", () => {
|
||||
const s = slide(vec(10, 5), vec(0, -1));
|
||||
expect(s.x).toBeCloseTo(10);
|
||||
expect(s.y).toBeCloseTo(0);
|
||||
});
|
||||
|
||||
test("result always runs along the wall (perpendicular to the normal)", () => {
|
||||
// a diagonal (unit) normal: 0.36 + 0.64 = 1
|
||||
const normal = vec(-0.6, -0.8);
|
||||
const s = slide(vec(10, 0), normal);
|
||||
// the slid velocity has no component into the wall -> dot with normal is 0
|
||||
expect(dot(s, normal)).toBeCloseTo(0);
|
||||
});
|
||||
Reference in New Issue
Block a user