import assert from "node:assert/strict"; import test from "node:test"; import { layoutFor } from "../src/lib/blackhole/layout.ts"; import { SCENE_WIDTH } from "../src/lib/galaxyLayout.ts"; import { CRITICAL_IMPACT } from "../src/lib/blackhole/geodesic.ts"; const panel = { left: 100, top: 50, width: 800, height: 600 }; test("the hole sits at the centre of the galaxy frame, relative to the panel", () => { const frame = { left: 100 + 70, top: 50 + 60, width: 660, height: 480 }; const { centerX, centerY } = layoutFor(frame, panel); assert.ok(Math.abs(centerX - (70 + 330) / 800) < 1e-9); assert.ok(Math.abs(centerY - (60 + 240) / 600) < 1e-9); }); test("the shadow has a fixed radius in scene units and scales with the frame", () => { const atNative = layoutFor({ left: 0, top: 0, width: SCENE_WIDTH, height: 480 }, panel); assert.ok(Math.abs(atNative.pxPerM * CRITICAL_IMPACT - 34) < 1e-9); const doubled = layoutFor({ left: 0, top: 0, width: SCENE_WIDTH * 2, height: 960 }, panel); assert.ok(Math.abs(doubled.pxPerM - atNative.pxPerM * 2) < 1e-9); }); test("a frame moving under a transition moves the hole with it", () => { const before = layoutFor({ left: 200, top: 100, width: 600, height: 436 }, panel); const after = layoutFor({ left: 240, top: 140, width: 600, height: 436 }, panel); assert.ok(Math.abs(after.centerX - before.centerX - 40 / 800) < 1e-9); assert.ok(Math.abs(after.centerY - before.centerY - 40 / 600) < 1e-9); assert.equal(after.pxPerM, before.pxPerM); });