import test from 'node:test'; import assert from 'node:assert/strict'; import { shadowFrame } from '../shadow-frame.js'; const sun = [-.5, .78, .37]; const clip = (m, p) => [0, 1, 2].map(i => m[i] * p[0] + m[i + 4] * p[1] + m[i + 8] * p[2] + m[i + 12]); test('shadow projection puts the camera neighborhood in range and light-facing objects closer', () => { for (const eye of [[0, 2, 8], [-123.5, 70, 400], [32700, 50, -32700]]) { const { matrix, center } = shadowFrame(eye, sun); assert.ok(clip(matrix, center).every(v => Math.abs(v) < 1e-4)); const near = clip(matrix, center.map((v, i) => v + sun[i] * 20)); const far = clip(matrix, center.map((v, i) => v - sun[i] * 20)); assert.ok(near[2] < far[2]); assert.ok([...near, ...far].every(v => v >= -1 && v <= 1)); } }); test('sub-texel camera movement keeps the shadow grid fixed', () => { const a = shadowFrame([0, 0, 0], sun).matrix; const b = shadowFrame([.001, .001, .001], sun).matrix; for (const i of [0, 1, 4, 5, 8, 9, 12, 13]) assert.equal(a[i], b[i]); });