import { describe, it, expect } from 'vitest'; import { _test } from '../src/lib/pinball.js'; const { closestOnSeg, clamp } = _test; describe('clamp', () => { it('bounds a value', () => { expect(clamp(5, 0, 10)).toBe(5); expect(clamp(-3, 0, 10)).toBe(0); expect(clamp(99, 0, 10)).toBe(10); }); }); describe('closestOnSeg', () => { it('projects onto the segment interior', () => { const [x, y, t] = closestOnSeg(5, 5, 0, 0, 10, 0); expect([x, y]).toEqual([5, 0]); expect(t).toBeCloseTo(0.5); }); it('clamps to the endpoints', () => { expect(closestOnSeg(-4, 2, 0, 0, 10, 0).slice(0, 2)).toEqual([0, 0]); expect(closestOnSeg(20, -1, 0, 0, 10, 0).slice(0, 2)).toEqual([10, 0]); }); it('handles a degenerate (zero-length) segment', () => { expect(closestOnSeg(3, 4, 1, 1, 1, 1).slice(0, 2)).toEqual([1, 1]); }); });