import { test } from 'node:test'; import assert from 'node:assert/strict'; import { Camera } from './camera.js'; const close = (a,b) => assert.ok(Math.abs(a-b)<1e-8,`${a} != ${b}`); test('fit preserves sheet aspect ratio without padding',()=> { const c = new Camera({x:0,y:-760,width:1150,height:760},1920,1080); close(c.scale,1080/760); close(c.y,1080); const center = c.world(960,540); close(center.x,575); close(center.y,-380); }); test('zoom retains exact world coordinate under cursor',()=> { const c = new Camera({x:0,y:-760,width:1150,height:760},1000,800); const p = c.world(121,534); c.zoom(3.2,121,534); const q = c.world(121,534); close(p.x,q.x); close(p.y,q.y); c.pan(12,-8); const r=c.world(133,526); close(r.x,p.x); close(r.y,p.y); }); test('zoom is bounded for hostile wheel deltas',()=> { const c = new Camera({x:0,y:0,width:100,height:100},1000,800); c.zoom(1e30,0,0); close(c.scale,c.fitScale*200); c.zoom(1e-30,0,0); close(c.scale,c.fitScale*.05); });