Move only the anchor's height when the floor height arrives

- The first height that replaces the entry frame's now moves only the
  anchor's height. The anchor keeps its place and its eased lift, so the
  camera no longer jumps to a corrected fix or steps back.
- A detail line is measured with the title's glyph widths. They are a
  little wide for its smaller type, so a long detail line is no longer
  clipped.
- The first aircraft update is checked in the existing test, and the copy
  is removed; test fixtures are simpler.
- Comments, the release note and CURRENT-STATE match the code.
This commit is contained in:
German Khokhlov committed 2026-11-19 00:26:57 +04:00
1 parent c190e662bc
commit 83081730c0
9 files changed
+176 -138

No files matched your search

+7 -21
View File
@@ -34,36 +34,22 @@ const stronger = (a, b) =>
const WIDE_GLYPHS =
/[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA960-\uA97F\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6]/g;
/** What a full-width glyph and any other UTF-16 unit take in a title (px). */
const TITLE_PX = Object.freeze({ wide: 10.6, narrow: 6.4 });
/** The same in a detail line (px). */
const DETAIL_PX = Object.freeze({
wide: 10 / 1.2 + 0.6,
narrow: 5.8 / 1.2 + 0.6,
});
/**
* One line's width (px) in `.cockpit-progress-label` type (cockpitSubject.css:
* 10 px, 0.06 em spacing) at the glyph widths `px`: about 1 em a full-width
* glyph and 0.58 em each UTF-16 unit of any other, so an astral glyph (an
* emoji, a CJK extension) counts as two and an emoji in the BMP (☕) as one,
* narrower than it is drawn. The detail line's `<small>` is 1/1.2 the size;
* the 0.6 px spacing it inherits is not scaled.
* 10 px, 0.06 em spacing): 10.6 px a full-width glyph and 6.4 px each UTF-16
* unit of any other, so an astral glyph (an emoji, a CJK extension) counts as
* two and an emoji in the BMP (☕) as one, narrower than it is drawn. The
* detail line's `<small>` draws smaller, so these widths only overestimate it.
*/
function lineWidthPx(line, px) {
function lineWidthPx(line) {
const text = String(line ?? '');
const wide = text.match(WIDE_GLYPHS)?.length ?? 0;
return wide * px.wide + (text.length - wide) * px.narrow;
return wide * 10.6 + (text.length - wide) * 6.4;
}
/** A label's width estimate (px): its wider line and 8 px of padding. */
export function estimateProgressLabelPx(label) {
return (
Math.max(
lineWidthPx(label?.text, TITLE_PX),
lineWidthPx(label?.detail, DETAIL_PX),
) + 8
);
return Math.max(lineWidthPx(label?.text), lineWidthPx(label?.detail)) + 8;
}
/**
+15 -15
View File
@@ -163,7 +163,7 @@ test('a CJK stop name gets the width its full-width glyphs need', () => {
);
});
test('emoji and other astral glyphs in a progress label get at least 1 em each', () => {
test('astral glyphs (emoji outside the BMP, supplementary kana) in a progress label get at least 1 em each', () => {
// About 1 em in 10 px type, 0.06 em apart.
const emPx = 10 + 0.6;
for (const [text, needPx] of [
@@ -183,21 +183,21 @@ test('emoji and other astral glyphs in a progress label get at least 1 em each',
});
test('a label is as wide as its wider line, its smaller detail line included', () => {
// The detail line's <small> is 1/1.2 of 10 px; its 0.6 px spacing is not.
const detailEmPx = 10 / 1.2 + 0.6;
const detail = '中央駅前'; // 4 full-width glyphs
const givenPx = estimateProgressLabelPx({ text: 'GATE', detail });
assert.ok(
givenPx > estimateProgressLabelPx({ text: 'GATE', detail: '' }),
estimateProgressLabelPx({ text: 'GATE', detail: '中央駅前' }) >
estimateProgressLabelPx({ text: 'GATE', detail: '' }),
'the wider detail line widens the label',
);
assert.ok(
givenPx >= detail.length * detailEmPx + 8,
`${givenPx} px given, about ${detail.length * detailEmPx} px needed`,
);
// A line takes less room as the smaller detail than as the title.
assert.ok(
estimateProgressLabelPx({ text: 'A', detail: 'CENTRAL STATION' }) <
estimateProgressLabelPx({ text: 'CENTRAL STATION', detail: '' }),
);
// As headless Chrome draws the detail's <small> (8.333 px JetBrains Mono,
// 0.6 px apart): 'WWWWMMMMWWWW' at 67.2 px, '中央駅前広場東口' at 72.9 px.
for (const [detail, needPx] of [
['W'.repeat(64), 64 * (67.2 / 12)],
['駅'.repeat(45), 45 * (72.9 / 8)],
]) {
const givenPx = estimateProgressLabelPx({ text: 'A', detail });
assert.ok(
givenPx >= needPx,
`${detail.length} × ${detail[0]}: ${givenPx} px given, ${needPx} px needed`,
);
}
});
+3 -3
View File
@@ -117,13 +117,14 @@ function lookOf(raw) {
});
}
/** Promises worded members gave, each one's rejection caught once. */
/** Promises already given a catch: a pending one is read again on every use. */
const caughtWords = new WeakSet();
/**
* A worded member as `read()` gives it, normalized: called on `provider`
* when it is a function (so it can follow the page's language); null when it
* is malformed (a promise too) or provider code throws.
* is malformed (a promise too) or provider code throws, its getter included
* (hence `read`).
*/
function worded(provider, read, normalize) {
try {
@@ -269,7 +270,6 @@ export function cockpitSubjectProviders(
*/
function keptProvider(provider, order, words) {
let { face, labels, look } = words;
// Look stays on or off, at its rest pitch, as read at registration.
const restPitchDeg = look?.restPitchDeg ?? 0;
return Object.freeze({
kind: provider.kind,
+14 -8
View File
@@ -403,11 +403,18 @@ function updateSubject(nowMs) {
this.surfaceWaitStartedMs = 0;
this.surfaceAcquiring = false;
if (!held) {
// The first height to replace the entry frame's places the anchor
// anew: an inertial one would close on it only at the horizontal
// correction's rate.
if (this.subjectHeightFromEntry && heightM !== this.subjectHeightM)
this.cockpitAnchorValid = false;
// The first height to replace the entry frame's is the anchor's at once
// (an inertial anchor would close on it only at the horizontal
// correction's rate); where the anchor stands, it stays.
if (
this.subjectHeightFromEntry &&
this.cockpitAnchorValid &&
heightM !== this.subjectHeightM
) {
const anchor = toCartographicRadians(this.cockpitAnchor);
if (anchor)
this.cockpitAnchor = fromRadians(anchor.lon, anchor.lat, heightM);
}
this.subjectHeightFromEntry = false;
}
this.subjectHeightM = heightM;
@@ -472,9 +479,8 @@ function updateSubject(nowMs) {
* Aircraft pass none and look along the heading at the profile pitch.
*/
function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
// An update that sets the anchor stands it on the target with no step:
// the first one (the time before it, an entry or a floor wait, moved
// nothing), and a subject's whose height replaced its entry frame's.
// The update that first sets the anchor stands it on the target: the time
// before it (an entry, a floor wait) moved nothing, so it has no step.
const anchoring = !this.cockpitAnchorValid;
if (anchoring) {
this.cockpitAnchorValid = true;
+3 -36
View File
@@ -444,10 +444,10 @@ test('Cockpit places the eye at its aircraft as the Cesium maths did', async ()
latitude: 30.19,
longitude: -97.67,
onGround: false,
stale: true,
stale: false,
};
const { owner, views } = cockpitOver({ info, target });
// Held on the target while the feed is stale.
// The first update stands the anchor on the target.
owner.update();
let expected = cesiumCockpitEye(Cesium, {
target,
@@ -456,13 +456,12 @@ test('Cockpit places the eye at its aircraft as the Cesium maths did', async ()
dtSec: 0,
liftM: 0,
});
near(views[0].destination, expected.eye, 1e-6, 'stale eye');
near(views[0].destination, expected.eye, 1e-6, 'first eye');
near(views[0].orientation.direction, expected.forward, 1e-12, 'direction');
near(views[0].orientation.up, expected.up, 1e-12, 'up');
// Live: the anchor coasts 80 ms along the heading and is pulled toward
// where the layer now shows the aircraft.
info.stale = false;
const anchor = Cesium.Cartesian3.clone(expected.anchor);
const moved = Cesium.Cartesian3.fromDegrees(-97.6698, 30.1901, 1210);
owner.trackedFollow.position = () => moved;
@@ -495,38 +494,6 @@ test('Cockpit places the eye at its aircraft as the Cesium maths did', async ()
}
});
test("a live aircraft's first Cockpit update stands the anchor on it", async () => {
const Cesium = await import('cesium');
const env = environment();
try {
const target = Cesium.Cartesian3.fromDegrees(-97.67, 30.19, 1200);
const info = {
icao24: 'abc123',
layerId: 'flights',
track: 72,
velocityMps: 200,
latitude: 30.19,
longitude: -97.67,
onGround: false,
stale: false,
};
const { owner, views } = cockpitOver({ info, target });
// Entry was a while ago: the step would carry the anchor 20 m ahead.
owner.update();
const expected = cesiumCockpitEye(Cesium, {
target,
info: { ...info, stale: true },
heading: 72,
dtSec: 0,
liftM: 0,
});
near(views[0].destination, expected.eye, 1e-6, 'first live eye');
owner.dispose();
} finally {
env.restore();
}
});
test('a grounded Cockpit probes the mesh from the camera and keeps the eye above the floor', async () => {
const Cesium = await import('cesium');
const env = environment();
+2 -2
View File
@@ -56,8 +56,8 @@ export function pushCockpitSignal(
{ inPlace = false } = {},
) {
if (!title || !detail) return;
// JSON keeps the fields apart: joined with `|`, a title or detail holding a
// `|` read as another pair. An in-place row also changes with its tone alone.
// JSON, not a joined string, so a separator inside a title or detail cannot
// make two rows match. An in-place row also changes with its tone alone.
const signature = JSON.stringify([
title,
detail,
+92 -15
View File
@@ -219,22 +219,20 @@ function fixture(
showBriefPage() {},
startBriefRotation() {},
stopBriefRotation() {},
pushCockpitSignal(key, tone, title, detail) {
signals.push({ key, tone, title, detail });
},
dropCockpitSignal(key) {
dropped.push(key);
},
scheduleContextLayout() {},
updateLocalPosition() {},
maybeRefreshRegionalBrief() {},
showContextCard() {},
});
if (realSignals) {
// The real Live Signals rows, published, not the recorder above.
delete cockpit.pushCockpitSignal;
delete cockpit.dropCockpitSignal;
}
if (!realSignals)
Object.assign(cockpit, {
pushCockpitSignal(key, tone, title, detail) {
signals.push({ key, tone, title, detail });
},
dropCockpitSignal(key) {
dropped.push(key);
},
});
t.after(() => {
cockpit.stop();
app.unmount();
@@ -297,7 +295,7 @@ const lastRelease = (calls) => calls.findLast(([name]) => name === 'release');
/**
* Move `ride`'s subject east at `speedMps` from `startMs` (the manual clock's
* start) on an inertial anchor, its frame otherwise as it was with `extra`
* on top; returns where it is now (longitude).
* on top; returns a function giving its longitude now.
*/
function movingEast(ride, startMs, speedMps, extra = {}) {
const eastNow = () =>
@@ -1355,9 +1353,7 @@ test("a moving vessel's first bridge update after entry stands the anchor on its
assert.equal(cockpit.enter(), true);
clock.advance(1000);
cockpit.update();
const anchor = Cesium.Cartographic.fromCartesian(
Cesium.Cartesian3.clone(cockpit.cockpitAnchor),
);
const anchor = Cesium.Cartographic.fromCartesian(cockpit.cockpitAnchor);
const fix = cockpit.vesselFix;
const gapM = Cesium.Cartesian3.distance(
Cesium.Cartesian3.fromRadians(anchor.longitude, anchor.latitude, 0),
@@ -1564,3 +1560,84 @@ test('an inertial subject placed at its entry height stands on the floor once it
`1 s after the floor came the eye is at ${heightM.toFixed(2)} m, not ${floorM + 3.5} m`,
);
});
/** How far east of LON the camera's last shot is (m). */
const shotEastM = (shots) =>
(Cesium.Math.toDegrees(
Cesium.Cartographic.fromCartesian(shots.at(-1).destination).longitude,
) -
LON) *
M_PER_DEG_LON;
test('the first floor after an entry height moves an inertial anchor as a cold floor does', async (t) => {
// The provider corrects its subject 100 m east as the floor arrives.
const run = (warm) => {
const clock = manualClock(t, 10_000);
const ride = subjectProvider();
ride.subject.frame = {
...ride.subject.frame,
heightM: FLOOR_M,
speedMps: 0,
anchor: 'inertial',
groundClamp: false,
};
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
setFloor(undefined);
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
ride.subject.frame = { ...ride.subject.frame, heightM: null };
clock.advance(100);
cockpit.update();
const beforeM = shotEastM(shots);
ride.subject.frame = { ...ride.subject.frame, longitude: eastM(100) };
if (warm) setFloor(FLOOR_M + 0.1);
clock.advance(100);
cockpit.update();
const stepM = shotEastM(shots) - beforeM;
const heightM = shotHeight(shots);
cockpit.stop();
return { stepM, heightM };
};
const cold = run(false);
const warm = run(true);
assert.ok(
Math.abs(warm.stepM - cold.stepM) < 0.02,
`east step ${warm.stepM.toFixed(3)} m with the floor arriving, ${cold.stepM.toFixed(3)} m with it cold`,
);
assert.ok(Math.abs(warm.heightM - (FLOOR_M + 0.1 + 3.5)) < 0.02);
});
test('the first floor after an entry height never steps an inertial anchor back to a held fix', async (t) => {
const startMs = 10_000;
const clock = manualClock(t, startMs);
const ride = subjectProvider();
const base = {
...ride.subject.frame,
heightM: FLOOR_M,
speedMps: 30,
anchor: 'inertial',
groundClamp: false,
};
ride.subject.frame = base;
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
setFloor(undefined);
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
// Telemetry that gives a new fix once a second, 30 m on each time.
ride.subject.frame = () => ({
...base,
heightM: null,
longitude: eastM(30 * Math.floor((performance.now() - startMs) / 1000)),
});
for (let i = 0; i < 17; i += 1) {
clock.advance(100);
cockpit.update();
}
const beforeM = shotEastM(shots);
// The floor arrives 1 cm off the entry height, between two fixes.
setFloor(FLOOR_M + 0.01);
clock.advance(100);
cockpit.update();
const stepM = shotEastM(shots) - beforeM;
assert.ok(stepM > 0, `the eye stepped ${stepM.toFixed(2)} m east`);
});