Name the neighbours, from inside the system

A system view could say everything about the star it was inside and nothing
about where that star was. The four nearest catalogue stars are now named
around the edge of it, each with its distance, each a button that flies there
— so a chain of neighbours can be walked without pulling back out to the field
between hops.

These are bearings, not sky positions, and that is the one deliberate
compromise here. A true direction was tried first and does not work: at this
field of view the visible cone is about 30 degrees, so on average one
neighbour in fifteen falls inside the frame — measured, not guessed, at one
label of four in Sol and none at all after a small orbit. What survives the
ring is the half of the direction a viewer can act on, which way to turn to
face it, and the ring reads as instrument rather than as scene because it sits
at a fixed radius. Real distance was never an option: Proxima is 268 000 AU
from Sol, thirteen far planes out, so the distance goes on the type line.

Proximity is answered by a new pure module rather than by a scan. A uniform
grid over the catalogue answers both "the k nearest to this star" and "every
star within n parsecs", the second being what the jump-link graph in the next
PR is built from — one scan per node, and the quadratic would show. Its spec
pins the grid against a brute-force sweep of a pseudo-random cloud, because a
spatial index is an optimisation and never a different answer.

Where the ring meets the HUD, the HUD wins: placement is given the boxes the
readout, the strip and the object card occupy, and slides a name along the
ring until it clears them, or drops it rather than print it half hidden. That
rule is a pure function with its own spec.

Four defects found while verifying this, three of them older than it:

The dock's flex column was pointer-events-auto and as wide as its strip, so
an invisible band above the strip swallowed every click in it — including,
but not only, a neighbour's. The column is transparent now and each surface
opts back in.

The ring was sized against the frame's height alone, which on a phone held
upright put it a viewport and a half wide: no neighbour was reachable on any
portrait screen. It is sized against the shorter side.

Picking a search result reopened the readout, which on a narrow viewport is a
sheet over most of the scene — reopening it onto whatever was just flown to.
Below sm it now folds away.

A selectable label's two lines are adjacent spans, so it announced as
"Sirius2.64 pc"; it carries an explicit label saying what it does.

Verified: build clean, 558/558 unit, 7/7 end-to-end including a new spec that
flies Sol to Barnard's Star by its label, design detector clean, screenshots
at 1440x900 and 390x844 in Sol and Proxima Centauri, and the keyboard path
walked: both names are in the tab order, focusable, with the accent ring.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016jxMkwA2rbicdGxHosecYi
This commit is contained in:
2026-08-20 17:06:25 +02:00
co-authored by Claude Fable 5
parent 7591bcc0ea
commit 44c6a1f15e
12 changed files with 822 additions and 22 deletions
@@ -0,0 +1,108 @@
import { describe, expect, it } from 'vitest';
import { StarNeighbourhood, StarPoint } from './star-neighbourhood';
/** A line of stars one parsec apart along x, so every expected distance is an integer. */
function line(count: number): StarPoint[] {
return Array.from({ length: count }, (_, i) => ({ id: i, x: i, y: 0, z: 0 }));
}
function ids(found: { id: number }[]): number[] {
return found.map((neighbour) => neighbour.id);
}
describe('StarNeighbourhood', () => {
it('names the nearest stars in order, and never the star itself', () => {
const index = new StarNeighbourhood(line(10));
expect(ids(index.nearest(4, 3))).toEqual([3, 5, 2]);
});
it('measures the separation it found each star by', () => {
const index = new StarNeighbourhood([
{ id: 1, x: 0, y: 0, z: 0 },
{ id: 2, x: 3, y: 4, z: 0 }
]);
expect(index.nearest(1, 1)[0].distancePc).toBeCloseTo(5);
});
it('reaches past its own cell for a star sitting alone in one', () => {
// 5 pc cells: these three are in three different cells, and the nearest is 12 pc out.
const index = new StarNeighbourhood([
{ id: 1, x: 0, y: 0, z: 0 },
{ id: 2, x: 12, y: 0, z: 0 },
{ id: 3, x: 40, y: 0, z: 0 }
]);
expect(ids(index.nearest(1, 2))).toEqual([2, 3]);
});
it('does not stop at the first ring that fills the list, where the next holds something closer', () => {
// The diagonal neighbour is in the ring-1 shell but 8.7 pc away; the one straight along x is
// in the ring-2 shell and only 6 pc away. Stopping at the first full ring would miss it.
const index = new StarNeighbourhood([
{ id: 1, x: 0, y: 0, z: 0 },
{ id: 2, x: 5, y: 5, z: 5 },
{ id: 3, x: 6, y: 0, z: 0 }
]);
expect(ids(index.nearest(1, 1))).toEqual([3]);
});
it('agrees with a brute-force scan over a pseudo-random cloud', () => {
// The property that matters: the grid is an optimisation, never a different answer.
let seed = 7;
const random = () => ((seed = (seed * 1103515245 + 12345) % 2147483648) / 2147483648) * 100 - 50;
const cloud: StarPoint[] = Array.from({ length: 400 }, (_, id) => ({ id, x: random(), y: random(), z: random() }));
const index = new StarNeighbourhood(cloud);
for (const origin of [cloud[0], cloud[199], cloud[399]]) {
const brute = cloud
.filter((point) => point.id !== origin.id)
.map((point) => ({ id: point.id, distancePc: Math.hypot(point.x - origin.x, point.y - origin.y, point.z - origin.z) }))
.sort((a, b) => a.distancePc - b.distancePc);
expect(ids(index.nearest(origin.id, 5))).toEqual(ids(brute.slice(0, 5)));
expect(ids(index.within(origin.id, 20))).toEqual(ids(brute.filter((neighbour) => neighbour.distancePc <= 20)));
}
});
it('takes only the stars a filter accepts', () => {
const index = new StarNeighbourhood(line(10));
expect(ids(index.nearest(4, 2, (point) => point.id % 2 === 0))).toEqual([2, 6]);
});
it('answers nothing for a star it has never heard of', () => {
const index = new StarNeighbourhood(line(3));
expect(index.nearest(99, 3)).toEqual([]);
expect(index.within(99, 10)).toEqual([]);
expect(index.point(99)).toBeUndefined();
});
it('asks for nothing and gets nothing', () => {
const index = new StarNeighbourhood(line(5));
expect(index.nearest(0, 0)).toEqual([]);
expect(index.within(0, 0)).toEqual([]);
});
it('finds every star inside a radius and none on the far side of it', () => {
const index = new StarNeighbourhood(line(20));
expect(ids(index.within(10, 2.5))).toEqual([9, 11, 8, 12]);
});
it('holds stars that share a position without losing either', () => {
// Real catalogue rows do this: Gl 65 A and B are one binary, two entries, one position.
const index = new StarNeighbourhood([
{ id: 1, x: 0, y: 0, z: 0 },
{ id: 2, x: 2.63, y: 0, z: 0 },
{ id: 3, x: 2.63, y: 0, z: 0 }
]);
expect(ids(index.nearest(1, 2)).sort()).toEqual([2, 3]);
});
});