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
87 lines
3.4 KiB
TypeScript
87 lines
3.4 KiB
TypeScript
/**
|
|
* Where a name goes on the ring around the view, given the direction it stands for and the
|
|
* panels already occupying the frame.
|
|
*
|
|
* Pure and in screen space, so the rule can be read and tested without a scene: the caller turns
|
|
* a direction into an angle, this decides where on the ring that angle can actually be printed,
|
|
* and the caller turns the answer back into a point the renderer can project.
|
|
*/
|
|
|
|
/** A box the ring must not print into, in pixels from the top-left of the viewport. */
|
|
export interface ReservedBox {
|
|
readonly left: number;
|
|
readonly top: number;
|
|
readonly right: number;
|
|
readonly bottom: number;
|
|
}
|
|
|
|
export interface RingViewport {
|
|
readonly width: number;
|
|
readonly height: number;
|
|
}
|
|
|
|
/** A place on the ring, in normalised device coordinates (-1..1, y up). */
|
|
export interface RingPlacement {
|
|
readonly x: number;
|
|
readonly y: number;
|
|
/** The angle actually used, which is the requested one unless a panel was in the way. */
|
|
readonly angle: number;
|
|
}
|
|
|
|
/**
|
|
* How far the bearing may be bent to get out from behind a panel, and in what steps. Bending is
|
|
* a lie about the direction, so it is kept small and always tried in the smallest amount that
|
|
* works, alternating sides so the name ends up on whichever side of the panel is nearer.
|
|
*/
|
|
const MAX_NUDGE_RADIANS = Math.PI / 3;
|
|
const NUDGE_STEP_RADIANS = Math.PI / 24;
|
|
|
|
/**
|
|
* The label's text runs this far from its anchor, as a fraction of the viewport width, and this
|
|
* tall. A name clears a panel only if the whole line does, not just the point it hangs from.
|
|
*/
|
|
const LABEL_REACH_FRACTION = 0.13;
|
|
const LABEL_HEIGHT_PX = 30;
|
|
|
|
function overlaps(x: number, y: number, viewport: RingViewport, reserved: readonly ReservedBox[]): boolean {
|
|
const px = ((x + 1) / 2) * viewport.width;
|
|
const py = ((1 - y) / 2) * viewport.height;
|
|
const reach = viewport.width * LABEL_REACH_FRACTION;
|
|
// Either side, because which side the text hangs on is decided later, by the label pass.
|
|
const left = px - reach;
|
|
const right = px + reach;
|
|
const top = py - LABEL_HEIGHT_PX / 2;
|
|
const bottom = py + LABEL_HEIGHT_PX / 2;
|
|
return reserved.some((box) => left < box.right && right > box.left && top < box.bottom && bottom > box.top);
|
|
}
|
|
|
|
/**
|
|
* Places one name on the ring at `angle`, moved along the ring if a panel is in the way, or
|
|
* `null` if the whole neighbourhood of that angle is covered — better absent than half hidden
|
|
* behind a readout.
|
|
*
|
|
* `radius` is a fraction of the frame's shorter side, so the ring is a circle on screen — and
|
|
* fits whichever way up the frame is. Sizing it against the height alone puts the ring a
|
|
* viewport and a half wide on a phone held upright, which is to say off both edges.
|
|
*/
|
|
export function ringPlacement(
|
|
angle: number,
|
|
radius: number,
|
|
viewport: RingViewport,
|
|
reserved: readonly ReservedBox[] = []
|
|
): RingPlacement | null {
|
|
const shorterSide = Math.min(viewport.width, viewport.height);
|
|
const scaleX = viewport.width === 0 ? radius : (radius * shorterSide) / viewport.width;
|
|
const scaleY = viewport.height === 0 ? radius : (radius * shorterSide) / viewport.height;
|
|
for (let nudge = 0; nudge <= MAX_NUDGE_RADIANS; nudge += NUDGE_STEP_RADIANS) {
|
|
for (const candidate of nudge === 0 ? [angle] : [angle + nudge, angle - nudge]) {
|
|
const x = Math.cos(candidate) * scaleX;
|
|
const y = Math.sin(candidate) * scaleY;
|
|
if (!overlaps(x, y, viewport, reserved)) {
|
|
return { x, y, angle: candidate };
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|