Files
tessera/web/scripts/galaxy.test.mjs
Adnan Zahir d0f22c4ad0 feat: draw orbits as stars in the realistic look and follow the radar wave
The orbit overlay fit the radar look but read as a diagram laid over the
realistic one. Give each look its own grammar over the same data.

- Realistic look: each orbit is a star with a bright core, a status-tinted
  glow and four tapered diffraction spikes, which the sky's own stars never
  have. Status still shows by shape as well as colour. Tracks recede to a faint
  trace, hovering a marker reveals its shell, and the selected orbit keeps its
  dashed ring. Moving markers trail a tapered comet tail along their orbit.
- Stars shimmer out of phase on the scene loop that already runs, more for
  working and failed ones. A stopped map is still, and reduced motion turns it
  off. Hovering a star enlarges it with the shared spring.
- Radar look: plain instrument dots and full-strength tracks, as before.
- The overlay takes the look at each marker's and ring's own distance from the
  hole, so it changes as the radar wave front passes. The renderer exposes this
  as signal.lookAt and calls signal.onLook while the wave runs.
- Slow the wave spring so the front takes about 0.4 s to cross the orbit area
  instead of 0.2 s, and end it at 99.5% progress.
- Test that a marker's trail points back along its motion.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-13 22:11:49 +07:00

100 lines
4.4 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { capturePhases, assignOrbitSlots, orbitPose, groupSnapshots, moonPoses, trailAngle } from "../src/lib/galaxyLayout.ts";
import { placeLabels } from "../src/lib/galaxyLabelLayout.ts";
test("slot identities survive reordering, insertion and removal", () => {
const first = assignOrbitSlots(["a", "b", "c"]);
const next = assignOrbitSlots(["new", "c", "a"], first);
assert.equal(next.get("a"), first.get("a"));
assert.equal(next.get("c"), first.get("c"));
assert.equal(next.get("new"), first.get("b"));
});
test("overview fits 50 distinct orbits and promotes a selected orbit beyond capacity", () => {
const ids = Array.from({ length: 75 }, (_, i) => String(i));
const slots = assignOrbitSlots(ids);
assert.ok(slots.size >= 50);
assert.equal(new Set(slots.values()).size, slots.size);
const promoted = assignOrbitSlots(ids, slots, "74");
assert.ok(promoted.has("74"));
assert.equal(promoted.get("0"), slots.get("0"));
for (const slot of promoted.values()) {
const point = orbitPose(slot, 7);
assert.ok(Math.abs(point.x) < 320 && Math.abs(point.y) < 220);
}
});
test("snapshot ownership uses IDs and only falls back to an unambiguous name", () => {
const orbits = [
{ id: "a", name: "daily" }, { id: "b", name: "daily" }, { id: "c", name: "archive" },
];
const snapshot = (id, orbit_name, taken_at, orbit_id) =>
({ id, orbit_name, taken_at, orbit_id, size_bytes: 1 });
const groups = groupSnapshots(orbits, [
snapshot("old", "renamed", "2026-10-01", "a"),
snapshot("ambiguous", "daily", "2026-10-03"),
snapshot("new", "daily", "2026-10-03", "a"),
snapshot("legacy", "archive", "2026-10-02"),
snapshot("orphan", "archive", "2026-10-02", "deleted"),
]);
assert.deepEqual(groups.get("a").map((s) => s.id), ["new", "old"]);
assert.equal(groups.has("b"), false);
assert.deepEqual(groups.get("c").map((s) => s.id), ["legacy"]);
});
test("moon fan opens away from the vault and separates touch targets", () => {
const moons = moonPoses({ x: 150, y: 0 }, 3, 55);
assert.equal(moons.length, 3);
assert.ok(moons.every((p) => p.x > 150));
assert.ok(Math.hypot(moons[0].x - moons[1].x, moons[0].y - moons[1].y) >= 55);
const shifted = moonPoses({ x: 150, y: 0 }, 3, 55, moons);
assert.equal(shifted.length, 3);
assert.ok(shifted.every((moon) => moons.every((star) => Math.hypot(star.x - moon.x, star.y - moon.y) >= 14)));
});
test("labels respect screen bounds and preserve priority in a crowded scene", () => {
const candidates = [
{ id: "focused", x: 70, y: 60, width: 72 },
{ id: "other", x: 70, y: 60, width: 200 },
];
const labels = placeLabels(candidates, 140, 120, []);
assert.deepEqual(labels.map((l) => l.id), ["focused"]);
assert.ok(labels[0].x >= 0 && labels[0].x + 72 <= 140);
});
test("capture flares before flight, then absorbs and highlights the snapshot", () => {
const flare = capturePhases(0.06);
assert.equal(flare.flare, 1);
assert.equal(flare.flight, 0);
assert.equal(flare.highlight, 0);
const arrival = capturePhases(0.84);
assert.equal(arrival.flight, 1);
assert.equal(arrival.absorption, 1);
assert.equal(arrival.highlight, 0);
assert.equal(capturePhases(0.94).absorption, 0);
assert.equal(capturePhases(0.94).highlight, 0);
assert.equal(capturePhases(0.97).highlight, 1);
assert.deepEqual(capturePhases(1), { flare: 0, flight: 1, absorption: 0, highlight: 0, failure: 0 });
});
test("the selected label searches farther when nearby orbit markers crowd it out", () => {
const selected = { id: "focused", x: 140, y: 140, width: 60 };
const cluster = { x: 61, y: 61, width: 158, height: 158 };
assert.deepEqual(placeLabels([selected], 300, 300, [cluster]), []);
assert.equal(placeLabels([selected], 300, 300, [cluster], selected.id)[0]?.id, selected.id);
});
test("a marker's trail points back along the direction it came from", () => {
const slots = assignOrbitSlots(Array.from({ length: 30 }, (_, i) => String(i)));
for (const slot of slots.values()) {
for (const time of [0, 3.7, 41]) {
const now = orbitPose(slot, time);
const next = orbitPose(slot, time + 0.01);
const tail = Math.atan2(-(next.y - now.y), -(next.x - now.x));
const diff = Math.atan2(Math.sin(trailAngle(slot, time) - tail), Math.cos(trailAngle(slot, time) - tail));
assert.ok(Math.abs(diff) < 0.01, `trail off by ${diff}`);
}
}
});