import { describe, expect, it } from 'vitest'; import { piecesInBody } from '../../src/runtime/physics/bodyGeometry'; describe('a collider as the engine builds it', () => { const origin = { x: 100, y: 50, angle: 0 }; const capsule = (a: { x: number; y: number }, b: { x: number; y: number }) => ({ kind: 'capsule', x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, angle: 0, a, b, r: 5 }) as const; it('a standing capsule is the engine capsule unturned, since that one lies along its y axis', () => { const [piece] = piecesInBody(origin, capsule({ x: 100, y: 30 }, { x: 100, y: 70 })); expect(piece).toMatchObject({ kind: 'capsule', x: 0, y: 0, half: 20, r: 5 }); expect(piece?.kind === 'capsule' && Math.abs(Math.sin(piece.angle))).toBeCloseTo(0); }); it('a lying capsule is turned a quarter, in the frame of the body it hangs on', () => { const [piece] = piecesInBody(origin, capsule({ x: 90, y: 60 }, { x: 130, y: 60 })); expect(piece).toMatchObject({ kind: 'capsule', x: 10, y: 10, half: 20 }); expect(piece?.kind === 'capsule' && Math.abs(Math.cos(piece.angle))).toBeCloseTo(0); }); });