Dragging the map walks the camera round the black hole (yaw) and raises or lowers it (lift); clicking the hole springs back to the default view. The shader takes an azimuth and an elevation, and the orbit overlay is projected through the same view (orbitPose, trailAngle and project take a View), so rings, stars, trails and rockets turn with the disk. A star behind the hole's shadow is hidden by it. Labels and moons wait until the camera rests. A camera at rest costs nothing, and the still quality tier still draws while it turns. Big-screen map labels sit on dark glass chips so the radar grid cannot swallow them, and the picked label and its status read as one chip. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
125 lines
5.9 KiB
JavaScript
125 lines
5.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { assignOrbitSlots, elevationOf, orbitPose, groupSnapshots, moonPoses, project, tiltOf, 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("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}`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("the default view is the map's own view, and a turned view is the same orbit seen from elsewhere", () => {
|
|
const slot = { radius: 190, angle: 0.4, speed: 0.033 };
|
|
assert.deepEqual(orbitPose(slot, 3, { yaw: 0, lift: 0 }), orbitPose(slot, 3));
|
|
assert.equal(tiltOf({ yaw: 0, lift: 0 }), 0.68);
|
|
// The orbit plane is a circle: turning the camera round it only moves a marker along its own ellipse.
|
|
const turned = orbitPose(slot, 3, { yaw: 1.1, lift: 0 });
|
|
const tilt = tiltOf({ yaw: 1.1, lift: 0 });
|
|
assert.ok(Math.abs((turned.x / 190) ** 2 + (turned.y / (190 * tilt)) ** 2 - 1) < 1e-9);
|
|
// Raising the camera opens the ellipse towards a circle; lowering it flattens it towards a line.
|
|
assert.ok(tiltOf({ yaw: 0, lift: 0.4 }) > 0.68);
|
|
assert.ok(tiltOf({ yaw: 0, lift: -0.5 }) < 0.4);
|
|
assert.ok(tiltOf({ yaw: 0, lift: 9 }) <= 1 && tiltOf({ yaw: 0, lift: -9 }) > 0);
|
|
});
|
|
|
|
test("project agrees with orbitPose for a point on the orbit", () => {
|
|
const slot = { radius: 128, angle: 1.9, speed: 0.047 };
|
|
const view = { yaw: -0.8, lift: 0.3 };
|
|
const angle = slot.angle + 2 * slot.speed;
|
|
const direct = orbitPose(slot, 2, view);
|
|
const projected = project(Math.cos(angle) * slot.radius, Math.sin(angle) * slot.radius, view);
|
|
assert.ok(Math.abs(direct.x - projected.x) < 1e-9 && Math.abs(direct.y - projected.y) < 1e-9);
|
|
});
|
|
|
|
test("a trail points back along the turned orbit", () => {
|
|
const slot = { radius: 190, angle: 0.4, speed: 0.033 };
|
|
const view = { yaw: 0.9, lift: 0.2 };
|
|
const now = orbitPose(slot, 5, view);
|
|
const before = orbitPose(slot, 5 - 0.01, view);
|
|
const tail = Math.atan2(before.y - now.y, before.x - now.x);
|
|
const diff = Math.atan2(Math.sin(trailAngle(slot, 5, view) - tail), Math.cos(trailAngle(slot, 5, view) - tail));
|
|
assert.ok(Math.abs(diff) < 0.05);
|
|
});
|
|
|
|
test("raising the camera raises the disk's view too, within bounds", () => {
|
|
assert.equal(elevationOf(0), (8 * Math.PI) / 180);
|
|
assert.ok(elevationOf(0.3) > elevationOf(0) && elevationOf(-0.3) < elevationOf(0));
|
|
assert.ok(elevationOf(-99) > 0 && elevationOf(99) < Math.PI / 2);
|
|
for (let lift = -0.55; lift < 0.7; lift += 0.05) assert.ok(elevationOf(lift + 0.05) > elevationOf(lift));
|
|
});
|