pocket-physics
Version:
Verlet physics extracted from pocket-ces demos
47 lines (46 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const v2_1 = require("./v2");
test("generics + nominal types", () => {
const v0 = (0, v2_1.v2)();
const v1 = (0, v2_1.v2)();
const out = (0, v2_1.v2)();
// @ts-expect-error
(0, v2_1.add)(out, v0, v1);
// @ts-expect-error
(0, v2_1.sub)(out, v0, v1);
// @ts-expect-error
(0, v2_1.dot)(v0, (0, v2_1.v2)());
// @ts-expect-error
(0, v2_1.copy)(out, v1);
const c = (0, v2_1.copy)((0, v2_1.v2)(), v1);
const s = (0, v2_1.sub)((0, v2_1.v2)(), v0, v1);
// @ts-expect-error
(0, v2_1.scale)(out, v0, 5);
// @ts-expect-error
(0, v2_1.distance)(v1, (0, v2_1.v2)());
// @ts-expect-error
(0, v2_1.distance2)(v1, (0, v2_1.v2)());
// @ts-expect-error
(0, v2_1.normalize)(v1, (0, v2_1.v2)());
// @ts-expect-error
(0, v2_1.normal)(out, v0, v1);
// @ts-expect-error
(0, v2_1.perpDot)(v1, (0, v2_1.v2)());
// @ts-expect-error
(0, v2_1.translate)(out, v0, v1);
// @ts-expect-error
(0, v2_1.rotate2d)(out, v0, v1, Math.PI / 2);
});
test("rotate", () => {
const out = (0, v2_1.v2)();
const origin = (0, v2_1.v2)();
const point = (0, v2_1.v2)(1, 0);
(0, v2_1.rotate2d)(out, point, origin, Math.PI / 2);
expect(out).toMatchInlineSnapshot(`
Object {
"x": 6.123233995736766e-17,
"y": 1,
}
`);
});