From 8b055a142335708b9fd70b43a9fd300eb5539da4 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:32:19 -0800 Subject: [PATCH 01/16] fix(ui): panel rails keep clear of an obstacle across the middle of the window An obstacle that crossed the middle of the window (the World Timeline, the voice control or a card in a window under about 520px tall) was neither above nor below it, so neither rail counted it and panels could be laid out over it. Such an obstacle now puts the panels on whichever side of it has more room. When neither side has room, the rails keep their existing minimum (the right rail's empty band, the left rail's minimum lane height). Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 6 ++++- src/cockpitMath.test.mjs | 52 +++++++++++++++++++++++++++++++++++++ src/ui/leftPanelRail.js | 20 ++++++++++++++ src/ui/panelRailGeometry.js | 14 +++++++++- src/ui/panelRails.test.mjs | 19 ++++++++++++++ 5 files changed, 109 insertions(+), 2 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 6b0cc95cdb..80e9f15833 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1197,7 +1197,11 @@ Cesium's credit box wraps from 1200px, as before; the phone shell, clean view, recording and scene playback lay the line out themselves. The left rail treats the centered World Timeline and voice control as obstacles only where they reach a laid-out panel, not the stack's -transparent gutter. +transparent gutter. Both rails keep clear of every obstacle they reach: one +above the middle of the window pushes the panels down, one below it pulls +them up, and one across the middle (common in short windows) puts them on +whichever side of it has more room. When neither side has room, the rails +keep their usual minimum height rather than overlap it. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index 3892d510b0..ee9c8ad541 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -286,6 +286,58 @@ test('HUD rail layout constrains an oversized panel to the safe corridor', () => assert.equal(layout.constrained, true); }); +test('HUD rail layout keeps a short window clear of an obstacle across its midpoint', () => { + // 480px window: midpoint 240. Each obstacle is neither wholly above nor + // wholly below the midpoint, and must still limit the band. + const above = resolveHudRailLayout({ + viewportHeight: 480, + panelHeight: 120, + laneLeft: 20, + laneRight: 340, + baseTop: 40, + baseBottom: 460, + gap: 10, + obstacles: [{ left: 0, right: 400, top: 200, bottom: 300 }], + }); + // Room above: 200 - 10 - 40 = 150; below: 460 - 310 = 150. A tie keeps the + // band above the obstacle. + assert.equal(above.safeTop, 40); + assert.equal(above.safeBottom, 190); + assert(above.top + Math.min(120, above.maxHeight) <= 190); + + const below = resolveHudRailLayout({ + viewportHeight: 480, + panelHeight: 120, + laneLeft: 20, + laneRight: 340, + baseTop: 40, + baseBottom: 460, + gap: 10, + obstacles: [{ left: 0, right: 400, top: 120, bottom: 260 }], + }); + // Room above: 70; below: 190. The band goes under the obstacle. + assert.equal(below.safeTop, 270); + assert.equal(below.safeBottom, 460); + assert(below.top >= 270); +}); + +test('HUD rail layout keeps its zero-height fallback when a straddling obstacle leaves no room', () => { + const layout = resolveHudRailLayout({ + viewportHeight: 480, + panelHeight: 120, + laneLeft: 20, + laneRight: 340, + baseTop: 100, + baseBottom: 400, + gap: 10, + obstacles: [{ left: 0, right: 400, top: 80, bottom: 420 }], + }); + assert.equal(layout.maxHeight, 0); + assert.equal(layout.constrained, true); + assert.equal(layout.safeTop, 100); + assert.equal(layout.safeBottom, 100); +}); + test('HUD rail layout can anchor controls to the start of the safe corridor', () => { const layout = resolveHudRailLayout({ viewportHeight: 1000, diff --git a/src/ui/leftPanelRail.js b/src/ui/leftPanelRail.js index 2d3edda5e1..e19012c61f 100644 --- a/src/ui/leftPanelRail.js +++ b/src/ui/leftPanelRail.js @@ -118,6 +118,7 @@ export function layoutLeftPanelRail({ let safeTop = baseTop; let safeBottom = viewportHeight - baseBottomInset; const bottomObstacles = []; + const straddling = []; for (const obstacle of obstacles) { if (stack.contains(obstacle)) continue; @@ -153,8 +154,27 @@ export function layoutLeftPanelRail({ safeTop = Math.max(safeTop, obstacleBottom); } else if (rect.top >= baseTop) { bottomObstacles.push({ top: rect.top }); + } else { + straddling.push(rect); } } + // An obstacle from above the corridor across the midpoint (common in short + // windows) still limits it: the panels go on whichever side of it leaves + // more room. + for (const rect of straddling) { + const roomAbove = rect.top - safeGap - obstacleSafeTop; + const lowerBottom = resolveLeftStackBottomBoundary({ + baseBottom: safeBottom, + obstacles: bottomObstacles, + safeGap, + }); + const roomBelow = lowerBottom - (rect.bottom + safeGap); + if (roomBelow > roomAbove) { + const obstacleBottom = rect.bottom + safeGap; + obstacleSafeTop = Math.max(obstacleSafeTop, obstacleBottom); + safeTop = Math.max(safeTop, obstacleBottom); + } else bottomObstacles.push({ top: rect.top }); + } safeBottom = resolveLeftStackBottomBoundary({ baseBottom: safeBottom, obstacles: bottomObstacles, diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index 673f4871e7..fc973a638a 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -1,6 +1,8 @@ /** * Resolve a vertically centered panel slot inside a HUD rail while respecting - * live rectangles that intersect that rail above or below the viewport center. + * live rectangles that intersect that rail. A rectangle above the viewport + * center lowers the top, one below it raises the bottom, and one across the + * center does whichever leaves the band more room. */ export function resolveHudRailLayout({ viewportHeight, @@ -29,6 +31,7 @@ export function resolveHudRailLayout({ const midpoint = viewportHeight * 0.5; let safeTop = Math.max(0, baseTop); let safeBottom = Math.min(viewportHeight, baseBottom); + const straddling = []; for (const rect of obstacles) { if ( @@ -44,6 +47,15 @@ export function resolveHudRailLayout({ if (rect.bottom <= midpoint) safeTop = Math.max(safeTop, rect.bottom + gap); else if (rect.top >= midpoint) safeBottom = Math.min(safeBottom, rect.top - gap); + else straddling.push(rect); + } + // An obstacle across the midpoint (common in short windows) still limits + // the band: the band goes on whichever side of it leaves more room. + for (const rect of straddling) { + const roomAbove = rect.top - gap - safeTop; + const roomBelow = safeBottom - (rect.bottom + gap); + if (roomBelow > roomAbove) safeTop = Math.max(safeTop, rect.bottom + gap); + else safeBottom = Math.min(safeBottom, rect.top - gap); } safeBottom = Math.max(safeTop, safeBottom); diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index 416079aec7..32e52a8083 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -219,6 +219,25 @@ test('left corridor respects a lower obstacle but ignores an obstacle hidden by assert.equal(Number(f.stack.dataset.safeBottomPct), 65.47); }); +test('in a short window the left corridor stays clear of an obstacle across the midpoint', () => { + // 480px window, midpoint 240. Neither card is wholly above or below it. + const f = fixture('left'); + f.options.windowRef.innerHeight = 480; + const low = element('card', { top: 100, height: 200 }); + f.options.obstacles = [low]; + f.run(); + // More room below the card than above it: the corridor starts under it. + assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300); + assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 480); + + const high = element('card', { top: 200, height: 200 }); + f.options.obstacles = [high]; + f.run(); + // More room above it: the corridor ends over it. + assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 200); + assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 0); +}); + test('a centered timeline only shortens the corridor when it reaches a laid-out panel', () => { const f = fixture('left'); f.stack.rect.width = 360; From 31a7b6a0a536e50d7be141987fc61e691c05f6d8 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:32:50 -0800 Subject: [PATCH 02/16] Add the changelog entry for #1837 Co-authored-by: Manjunath Paparaju --- changelog.d/1837-rail-short-window.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/1837-rail-short-window.md diff --git a/changelog.d/1837-rail-short-window.md b/changelog.d/1837-rail-short-window.md new file mode 100644 index 0000000000..2eed1e44e2 --- /dev/null +++ b/changelog.d/1837-rail-short-window.md @@ -0,0 +1,3 @@ +- Keep the left and right panel rails clear of an obstacle across the middle + of a short window, such as the World Timeline or a card: the panels take + the side of it with more room (manjunath22466, samehkhamis, #1837). From f414df97ebe9e438e3a0a8f8377fa33943b55b6b Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:23:25 -0800 Subject: [PATCH 03/16] fix(places): a small place in view comes before a far bigger namesake findPlace looked at the detail tiles only when no city had the typed name, so a village called Paris in view lost to Paris, France. With includeSmallPlaces it now reads the places near the view as well and takes the nearest place of the name there, city or not. With none near, the largest city of the name still wins. Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 8 ++- src/data/local_data/wikidata_cities/README.md | 5 ++ src/data/local_data/wikidata_places/README.md | 7 ++- src/data/wikidataCities.js | 44 +++++++++-------- src/data/wikidataCities.test.mjs | 49 +++++++++++++++++++ 5 files changed, 89 insertions(+), 24 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 6b0cc95cdb..724fa05523 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -966,7 +966,8 @@ the fleet set loaded at startup, so opening a card fetches no model. country and Wikidata id. `src/data/wikidataCities.js` reads it on the first lookup and answers `nearestCity` (the largest city within 12 km, else the nearest within 60 km), `citiesAround`, `findPlace` ("Paris, France", or the -nearest namesake within 150 km of the view, else the largest) and +nearest namesake within 150 km of the view, else the largest; asked to, it +counts the smaller places of the detail tiles near the view too) and `countryName`. Names match without case or accents ("lodz" finds Łódź). The app never calls Wikidata; `scripts/build-wikidata-cities.mjs` rebuilds the pack and fails if well-known cities are missing or a known grouping such as @@ -8249,7 +8250,10 @@ clears them but the browser's own site data. Setting `PHOTON_URL` empty turns the suggestions off along with it. Small places come from the bundled Wikidata packs and are never looked up online; a small place with the name of a city within 3 km in the same country is that city, and only -the city is listed. At most 64 detail tiles are kept in memory, the least +the city is listed. A place named in "villages near …" is the nearest of +that name within 150 km of the view, small places included, so a village in +view comes before a bigger namesake far away; with none near, the largest +city of the name. At most 64 detail tiles are kept in memory, the least recently used dropped first. ### Place-search providers diff --git a/src/data/local_data/wikidata_cities/README.md b/src/data/local_data/wikidata_cities/README.md index 8c2abf3818..ff80a6dc56 100644 --- a/src/data/local_data/wikidata_cities/README.md +++ b/src/data/local_data/wikidata_cities/README.md @@ -40,3 +40,8 @@ well-known cities is missing from the result, or a known grouping gets in. **Limits:** populations are whatever Wikidata states and differ in date and definition between places (city proper, municipality, urban district). Some districts and suburbs appear as their own rows. + +**Finding a place by name:** `findPlace` takes the nearest place of the name +within 150 km of the view, else the largest city of the name. When asked, +the smaller places of `../wikidata_places` near the view count too, so a +village in view comes before a bigger namesake far away. diff --git a/src/data/local_data/wikidata_places/README.md b/src/data/local_data/wikidata_places/README.md index 2831f89a56..0694fe5c5c 100644 --- a/src/data/local_data/wikidata_places/README.md +++ b/src/data/local_data/wikidata_places/README.md @@ -1,8 +1,11 @@ # Wikidata places detail tiles Smaller towns and villages, below the cut-off of the cities pack -(`../wikidata_cities`), for "places nearby" around one picked or named spot. Read by `placesNear` in `src/data/wikidataCities.js`. The app reads -these files; it does not call Wikidata or any place service for them. +(`../wikidata_cities`), for "places nearby" around one picked or named spot. Read by `placesNear` in `src/data/wikidataCities.js`, and by `findPlace` +when asked to look for a small place by name near the view: a place of that +name in view, or close to it, comes before a bigger city of the name far +away. The app reads these files; it does not call Wikidata or any place +service for them. | File | Contents | |------|----------| diff --git a/src/data/wikidataCities.js b/src/data/wikidataCities.js index 70dcb3e67a..1cc7eae468 100644 --- a/src/data/wikidataCities.js +++ b/src/data/wikidataCities.js @@ -339,12 +339,13 @@ export async function placesNear( const TWIN_KM = 3; /** - * The city with this name, or null. A qualifier after a comma that names a - * country ("Paris, France", "Paris, US") keeps only cities there, and finds + * The place with this name, or null. A qualifier after a comma that names a + * country ("Paris, France", "Paris, US") keeps only places there, and finds * nothing when none is; one that names no country ("Paris, Texas") is - * ignored. A city of that name within `radiusKm` of `near` (the view) wins, - * the nearest first, else the largest city of that name anywhere. Omnibar - * can also ask for a smaller place nearby when the cities pack has no match. + * ignored. A place of that name within `radiusKm` of `near` (the view) wins, + * the nearest first, else the largest city of that name anywhere. With + * `includeSmallPlaces`, the smaller places of the detail tiles near the view + * count too: a village in view comes before a far bigger city of its name. */ export async function findPlace( name, @@ -360,20 +361,6 @@ export async function findPlace( const cities = (names.get(wanted) || []).filter( (row) => !country || row[4] === country, ); - if (!cities.length) { - if (!includeSmallPlaces || !near) return null; - const nearby = await placesNear( - { ...near, radiusKm, limit: Infinity }, - fetchImpl, - ); - return ( - nearby.find( - (place) => - foldName(place.name) === wanted && - (!country || place.country === country), - ) ?? null - ); - } if (Number.isFinite(near?.latitude) && Number.isFinite(near?.longitude)) { let best = null; for (const row of cities) { @@ -381,7 +368,24 @@ export async function findPlace( if (km <= radiusKm && (!best || km < best.distanceKm)) best = toCity(row, km); } + if (includeSmallPlaces) { + const nearby = await placesNear( + { + latitude: near.latitude, + longitude: near.longitude, + radiusKm, + limit: Infinity, + }, + fetchImpl, + ); + const small = nearby.find( + (place) => + foldName(place.name) === wanted && + (!country || place.country === country), + ); + if (small && (!best || small.distanceKm < best.distanceKm)) best = small; + } if (best) return best; } - return toCity(cities[0], 0); + return cities.length ? toCity(cities[0], 0) : null; } diff --git a/src/data/wikidataCities.test.mjs b/src/data/wikidataCities.test.mjs index ae96f1e462..dd3259efa1 100644 --- a/src/data/wikidataCities.test.mjs +++ b/src/data/wikidataCities.test.mjs @@ -96,6 +96,55 @@ test('findPlace takes a country qualifier and prefers a namesake in view', async ); }); +test('a small place in view comes before a far bigger city of its name', async () => { + const module = await import(`./wikidataCities.js?small-${Date.now()}`); + // A village called Paris near Austin, in the 30_-100 detail tile. + const village = ['Paris', 30.4, -97.6, 1200, 'US', 'Q-village']; + const fetchImpl = async (url) => { + const file = url.pathname.split('/').at(-1); + const body = + file === 'cities.json' + ? { meta: {}, rows: PARIS } + : file === 'index.json' + ? { tiles: { '30_-100': 1 } } + : { rows: file === '30_-100.json' ? [village] : [] }; + return { ok: true, json: async () => body }; + }; + const find = (name, near) => + module.findPlace(name, { near, includeSmallPlaces: true }, fetchImpl); + const austin = { latitude: 30.27, longitude: -97.74 }; + assert.equal((await find('Paris', austin)).wikidata, 'Q-village'); + assert.ok((await find('Paris', austin)).distanceKm < 20); + // Only when small places are asked for. + assert.equal( + (await module.findPlace('Paris', { near: austin }, fetchImpl)).wikidata, + 'Q90', + ); + // A qualifier still decides. + assert.equal((await find('Paris, France', austin)).wikidata, 'Q90'); + // Nowhere near the village: the largest city of the name. + assert.equal( + (await find('Paris', { latitude: 0, longitude: 0 })).wikidata, + 'Q90', + ); + assert.equal( + (await module.findPlace('Paris', {}, fetchImpl)).wikidata, + 'Q90', + ); + // Paris, Texas is nearer a view over it than the village is. + const texas = { latitude: 33.6, longitude: -95.6 }; + assert.equal( + ( + await module.findPlace( + 'Paris', + { near: texas, radiusKm: 600, includeSmallPlaces: true }, + fetchImpl, + ) + ).wikidata, + 'Q830149', + ); +}); + test('a circle that reaches a pole spans every longitude', () => { assert.equal(lonHalfSpan(89, 150), 180); assert.ok(lonHalfSpan(60, 150) < 3); From 30ec362c13131113e23058cac39e3e2063803e64 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:34:54 -0800 Subject: [PATCH 04/16] fix(places): look for small places within 500 km, so a whole-globe view reads only the tiles near its centre Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 4 +- src/data/local_data/wikidata_places/README.md | 11 +++++- src/data/wikidataCities.js | 21 ++++++++-- src/data/wikidataCities.test.mjs | 39 +++++++++++++++++++ 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 724fa05523..f51d96efcb 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8253,7 +8253,9 @@ the name of a city within 3 km in the same country is that city, and only the city is listed. A place named in "villages near …" is the nearest of that name within 150 km of the view, small places included, so a village in view comes before a bigger namesake far away; with none near, the largest -city of the name. At most 64 detail tiles are kept in memory, the least +city of the name. Small places are looked for within 500 km at most, so a +view zoomed out to the whole globe reads only the detail tiles around its +centre. At most 64 detail tiles are kept in memory, the least recently used dropped first. ### Place-search providers diff --git a/src/data/local_data/wikidata_places/README.md b/src/data/local_data/wikidata_places/README.md index 0694fe5c5c..144f907209 100644 --- a/src/data/local_data/wikidata_places/README.md +++ b/src/data/local_data/wikidata_places/README.md @@ -20,7 +20,11 @@ entry in the index. **Loading:** nothing here loads with the app. A lookup reads `files.js` and the index once, then only the tiles its search box touches (one for a short radius well inside a tile, more near tile edges and for wider searches), -once each; at most 64 tiles are kept in memory, the least recently used +once each. The search box reaches 500 km at most (`PLACE_TILE_KM`), so a +view of the whole globe reads only the tiles around its centre: at most one +tile past the centre's own on each side, a few more columns toward the +poles, and never all 732. Cities still count to the full radius. At most +64 tiles are kept in memory, the least recently used dropped first. Rows whose name has no letter (one row, `380` in Nicaragua) are dropped when a tile is read. @@ -42,7 +46,10 @@ names from Wikidata (CC0)" as a courtesy once a name from the pack is shown. `node scripts/build-wikidata-cities.mjs --tiles --min-population 1000 --max-population 15000`. It writes only to this folder (tiles, `index.json`, `files.js`, through `scripts/wikidataPlaceTiles.mjs`) and leaves `../wikidata_cities` alone. It -runs one query at a time with pauses and takes a long while. +runs one query at a time with pauses and takes a long while. The new files +are all written before tiles that the new build has no rows for are +removed, and `meta.built` keeps its earlier date when nothing else in +`index.json` changed. **Reproducibility:** the step from rows to files is checked offline: `src/tooling/wikidataPlaceTiles.test.mjs` sorts the shipped rows as the diff --git a/src/data/wikidataCities.js b/src/data/wikidataCities.js index 1cc7eae468..2b62ac62b0 100644 --- a/src/data/wikidataCities.js +++ b/src/data/wikidataCities.js @@ -217,6 +217,14 @@ const TILE_DEG = 5; * far more than one lookup touches, and bounds what a long session keeps. */ const MAX_TILES = 64; +/** + * How far out small places are looked for, in km. 500 km is under the 556 km + * that 5 degrees of latitude span, so the search box reaches at most one tile + * past the point's own on each side: 3 rows, and 3 columns at the equator + * (more toward the poles, where tiles narrow). A wider view, out to the whole + * globe, still reads only those tiles; cities count to its full radius. + */ +export const PLACE_TILE_KM = 500; const NAMED = /\p{L}/u; const tiles = new Map(); let loadTileIndex; @@ -248,9 +256,11 @@ async function readPlaceTiles(latitude, longitude, radiusKm, fetchImpl) { readPlacePack(INDEX_URL(), fetchImpl), ); const index = await loadTileIndex(); - const keys = tileKeysAround(latitude, longitude, radiusKm).filter( - (key) => index.tiles[key], - ); + const keys = tileKeysAround( + latitude, + longitude, + Math.min(radiusKm, PLACE_TILE_KM), + ).filter((key) => index.tiles[key]); // A tile that cannot be read is left out: the places of the others, // and the cities, are still the answer. const settled = await Promise.allSettled( @@ -281,7 +291,10 @@ async function readPlacePack(url, fetchImpl) { return response.json(); } -/** Named cities and smaller places around one point, nearest first. */ +/** + * Named cities and smaller places around one point, nearest first. Smaller + * places are looked for within PLACE_TILE_KM only. + */ export async function placesNear( { latitude, longitude, radiusKm = 10, limit = 6 }, fetchImpl = (...args) => globalThis.fetch(...args), diff --git a/src/data/wikidataCities.test.mjs b/src/data/wikidataCities.test.mjs index dd3259efa1..10cec8c834 100644 --- a/src/data/wikidataCities.test.mjs +++ b/src/data/wikidataCities.test.mjs @@ -281,3 +281,42 @@ test('a tile that cannot be read leaves the other places and the cities', async assert.ok(near.some((place) => place.name === 'Austin')); assert.ok(near.some((place) => place.longitude > -95)); }); + +test('a view of the whole globe reads only the tiles near its centre', async () => { + const { placesNear, PLACE_TILE_KM } = + await import('./wikidataCities.js?globe'); + const fetched = []; + const fetchPack = async (url) => { + fetched.push(url.pathname.split('/').at(-1)); + return new Response(await readFile(url)); + }; + const near = await placesNear( + { latitude: 30.27, longitude: -97.74, radiusKm: 20000, limit: 50 }, + fetchPack, + ); + const tileReads = fetched + .filter((name) => /^-?\d+_-?\d+\.json$/.test(name)) + .sort(); + // 500 km around Austin: latitude 25.8 to 34.8, longitude -103 to -92.5. + assert.equal(PLACE_TILE_KM, 500); + assert.deepEqual(tileReads, [ + '25_-100.json', + '25_-105.json', + '25_-95.json', + '30_-100.json', + '30_-105.json', + '30_-95.json', + ]); + assert.equal(near.length, 50); + assert.ok(near.every((place) => place.distanceKm <= PLACE_TILE_KM)); + // Cities still count to the full radius. + const far = await placesNear( + { latitude: 30.27, longitude: -97.74, radiusKm: 20000, limit: Infinity }, + fetchPack, + ); + assert.ok(far.some((place) => place.wikidata === 'Q90')); + assert.equal( + fetched.filter((name) => /^-?\d+_-?\d+\.json$/.test(name)).length, + tileReads.length, + ); +}); From a2c86c0fed3d253342799cc200f57fbfef7f99bd Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:34:54 -0800 Subject: [PATCH 05/16] fix(places): a rebuild writes its files before removing stale tiles, and keeps the build date when nothing changed Co-authored-by: Manjunath Paparaju --- scripts/build-wikidata-cities.mjs | 24 +++++++++++++++---- scripts/wikidataPlaceTiles.mjs | 23 ++++++++++++++++++ src/data/local_data/wikidata_cities/README.md | 1 + src/tooling/wikidataPlaceTiles.test.mjs | 11 +++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/scripts/build-wikidata-cities.mjs b/scripts/build-wikidata-cities.mjs index a276062831..00dc36f0c0 100644 --- a/scripts/build-wikidata-cities.mjs +++ b/scripts/build-wikidata-cities.mjs @@ -39,6 +39,7 @@ import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { + keepBuiltIfUnchanged, placeTileFiles, withoutCities, withoutNearTwins, @@ -68,6 +69,8 @@ const outDir = path.join( : 'src/data/local_data/wikidata_cities', ); +/** A file's text, or undefined when there is none yet. */ +const readIfThere = (file) => readFile(file, 'utf8').catch(() => undefined); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const qid = (uri) => uri.slice(uri.lastIndexOf('/') + 1); @@ -499,17 +502,30 @@ if (tilesMode) { count: tileRows.length, maxPopulation, }); - // Tiles from an earlier build that this one has no rows for go. + // The new files are all written before tiles from an earlier build that + // this one has no rows for go, so a build that stops part way never leaves + // an index naming a removed tile. + const indexFile = path.join(outDir, 'index.json'); + files.set( + 'index.json', + keepBuiltIfUnchanged(files.get('index.json'), await readIfThere(indexFile)), + ); + for (const [name, text] of files) + await writeFile(path.join(outDir, name), text); for (const name of await readdir(outDir)) if (/^-?\d+_-?\d+\.json$/.test(name) && !files.has(name)) await rm(path.join(outDir, name)); - for (const [name, text] of files) - await writeFile(path.join(outDir, name), text); console.log( `Wrote ${tileRows.length} places in ${files.size - 2} tiles to ${path.relative(root, outDir)}`, ); process.exit(0); } const file = path.join(outDir, 'cities.json'); -await writeFile(file, `${JSON.stringify({ meta, rows })}\n`); +await writeFile( + file, + keepBuiltIfUnchanged( + `${JSON.stringify({ meta, rows })}\n`, + await readIfThere(file), + ), +); console.log(`Wrote ${rows.length} places to ${path.relative(root, file)}`); diff --git a/scripts/wikidataPlaceTiles.mjs b/scripts/wikidataPlaceTiles.mjs index 15f0c89e3a..bae1774bb7 100644 --- a/scripts/wikidataPlaceTiles.mjs +++ b/scripts/wikidataPlaceTiles.mjs @@ -89,6 +89,29 @@ export function placeTileFiles(rows, meta) { return files; } +/** + * A pack file's new text, keeping the earlier build's `meta.built` when + * nothing else in the file changed, so rebuilding unchanged data leaves the + * file as it was. + * @param {string} text The new file, JSON with a `meta.built` stamp. + * @param {string | undefined} earlier The file as it is now, if there is one. + */ +export function keepBuiltIfUnchanged(text, earlier) { + if (!earlier) return text; + let before; + try { + before = JSON.parse(earlier); + } catch { + return text; + } + const after = JSON.parse(text); + if (typeof before?.meta?.built !== 'string' || !after.meta) return text; + const unstamped = (value) => + JSON.stringify({ ...value, meta: { ...value.meta, built: null } }); + if (unstamped(before) !== unstamped(after)) return text; + return `${JSON.stringify({ ...after, meta: { ...after.meta, built: before.meta.built } })}\n`; +} + const kmBetween = (a, b) => greatCircleKm({ lat: a[1], lon: a[2] }, { lat: b[1], lon: b[2] }); diff --git a/src/data/local_data/wikidata_cities/README.md b/src/data/local_data/wikidata_cities/README.md index ff80a6dc56..026f412988 100644 --- a/src/data/local_data/wikidata_cities/README.md +++ b/src/data/local_data/wikidata_cities/README.md @@ -36,6 +36,7 @@ places without an English label. The build runs one query at a time with pauses and honours the service's Retry-After; it takes about ten minutes. It fails if a short list of well-known cities is missing from the result, or a known grouping gets in. +`meta.built` keeps its earlier date when the rows are unchanged. **Limits:** populations are whatever Wikidata states and differ in date and definition between places (city proper, municipality, urban district). Some diff --git a/src/tooling/wikidataPlaceTiles.test.mjs b/src/tooling/wikidataPlaceTiles.test.mjs index 9e9cf54179..10e77b8dd3 100644 --- a/src/tooling/wikidataPlaceTiles.test.mjs +++ b/src/tooling/wikidataPlaceTiles.test.mjs @@ -8,6 +8,7 @@ import { createHash } from 'node:crypto'; import { readdir, readFile } from 'node:fs/promises'; import test from 'node:test'; import { + keepBuiltIfUnchanged, placeTileFiles, tileKey, withoutCities, @@ -103,3 +104,13 @@ test('twins are found where longitude cells narrow, and across 180°', () => { ['Q1', 'Q3'], ); }); + +test('a rebuild of unchanged rows keeps the earlier build stamp', () => { + const earlier = `${JSON.stringify({ meta: { built: '2026-01-01T00:00:00.000Z', count: 2 }, rows: [1, 2] })}\n`; + const same = `${JSON.stringify({ meta: { built: '2026-11-18T00:00:00.000Z', count: 2 }, rows: [1, 2] })}\n`; + const changed = `${JSON.stringify({ meta: { built: '2026-11-18T00:00:00.000Z', count: 3 }, rows: [1, 2, 3] })}\n`; + assert.equal(keepBuiltIfUnchanged(same, earlier), earlier); + assert.equal(keepBuiltIfUnchanged(changed, earlier), changed); + assert.equal(keepBuiltIfUnchanged(same, undefined), same); + assert.equal(keepBuiltIfUnchanged(same, 'not json'), same); +}); From feedd886141adb2e755eb9444b227190e6552aab Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:39:29 -0800 Subject: [PATCH 06/16] fix(ui): rails take obstacles across the middle together, so their order never picks the side Co-authored-by: Manjunath Paparaju --- changelog.d/1837-rail-short-window.md | 7 +++--- docs/CURRENT-STATE.md | 10 ++++---- src/cockpitMarkup.test.mjs | 2 +- src/cockpitMath.test.mjs | 28 ++++++++++++++++++--- src/ui/leftPanelRail.js | 36 ++++++++++++++++----------- src/ui/panelRailGeometry.js | 27 ++++++++++++-------- src/ui/panelRails.test.mjs | 34 +++++++++++++++++++------ 7 files changed, 99 insertions(+), 45 deletions(-) diff --git a/changelog.d/1837-rail-short-window.md b/changelog.d/1837-rail-short-window.md index 2eed1e44e2..5a6662ca1a 100644 --- a/changelog.d/1837-rail-short-window.md +++ b/changelog.d/1837-rail-short-window.md @@ -1,3 +1,4 @@ -- Keep the left and right panel rails clear of an obstacle across the middle - of a short window, such as the World Timeline or a card: the panels take - the side of it with more room (manjunath22466, samehkhamis, #1837). +- Keep the left and right panel rails clear of obstacles across the middle + of a short window, such as the World Timeline or a card: both rails put + the panels on the side with more room, whatever order the obstacles come + in (manjunath22466, samehkhamis, #1837). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 80e9f15833..5e36fa9df4 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1197,11 +1197,11 @@ Cesium's credit box wraps from 1200px, as before; the phone shell, clean view, recording and scene playback lay the line out themselves. The left rail treats the centered World Timeline and voice control as obstacles only where they reach a laid-out panel, not the stack's -transparent gutter. Both rails keep clear of every obstacle they reach: one -above the middle of the window pushes the panels down, one below it pulls -them up, and one across the middle (common in short windows) puts them on -whichever side of it has more room. When neither side has room, the rails -keep their usual minimum height rather than overlap it. +transparent gutter. Obstacles across the middle of the window (common in +short windows) are taken together, from the highest top to the lowest +bottom, and both rails put their panels on whichever side of that span has +more room, above it on a tie, whatever order the obstacles come in. With no +room on either side the panels keep their place, as before. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/src/cockpitMarkup.test.mjs b/src/cockpitMarkup.test.mjs index 3a084af32f..2fa3c1aea4 100644 --- a/src/cockpitMarkup.test.mjs +++ b/src/cockpitMarkup.test.mjs @@ -1010,7 +1010,7 @@ test('an expanded Cockpit left panel stays above Contact, HUD, and attribution', assert.ok(leftLayout, 'left accordion layout pass is missing'); assert.match( leftLayout, - /rect\.top >= baseTop\) \{\s*\n\s*bottomObstacles\.push\(\{ top: rect\.top \}\);/, + /\} else \{\s*\n\s*bottomObstacles\.push\(\{ top: rect\.top \}\);\s*\n\s*\}\s*\n\s*\}/, 'every rendered lower-lane obstacle must constrain the panel corridor', ); assert.match( diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index ee9c8ad541..8754954d66 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -321,7 +321,7 @@ test('HUD rail layout keeps a short window clear of an obstacle across its midpo assert(below.top >= 270); }); -test('HUD rail layout keeps its zero-height fallback when a straddling obstacle leaves no room', () => { +test('HUD rail layout leaves the band as it is when an obstacle across the midpoint leaves no room', () => { const layout = resolveHudRailLayout({ viewportHeight: 480, panelHeight: 120, @@ -332,10 +332,30 @@ test('HUD rail layout keeps its zero-height fallback when a straddling obstacle gap: 10, obstacles: [{ left: 0, right: 400, top: 80, bottom: 420 }], }); - assert.equal(layout.maxHeight, 0); - assert.equal(layout.constrained, true); assert.equal(layout.safeTop, 100); - assert.equal(layout.safeBottom, 100); + assert.equal(layout.safeBottom, 400); +}); + +test('HUD rail layout reads several obstacles across the midpoint the same in any order', () => { + const a = { left: 0, right: 400, top: 100, bottom: 260 }; + const b = { left: 0, right: 400, top: 200, bottom: 470 }; + const layoutWith = (obstacles) => + resolveHudRailLayout({ + viewportHeight: 480, + panelHeight: 120, + laneLeft: 20, + laneRight: 340, + baseTop: 40, + baseBottom: 460, + gap: 10, + obstacles, + }); + // Together they cover 100 to 470: the only room is above, 40 to 90. + for (const layout of [layoutWith([a, b]), layoutWith([b, a])]) { + assert.equal(layout.safeTop, 40); + assert.equal(layout.safeBottom, 90); + assert.equal(layout.maxHeight, 50); + } }); test('HUD rail layout can anchor controls to the start of the safe corridor', () => { diff --git a/src/ui/leftPanelRail.js b/src/ui/leftPanelRail.js index e19012c61f..909ed1b660 100644 --- a/src/ui/leftPanelRail.js +++ b/src/ui/leftPanelRail.js @@ -118,7 +118,10 @@ export function layoutLeftPanelRail({ let safeTop = baseTop; let safeBottom = viewportHeight - baseBottomInset; const bottomObstacles = []; - const straddling = []; + // Obstacles across the midpoint all cover it, so together they cover one + // span: from the highest top to the lowest bottom. + let spanTop = Infinity; + let spanBottom = -Infinity; for (const obstacle of obstacles) { if (stack.contains(obstacle)) continue; @@ -152,28 +155,31 @@ export function layoutLeftPanelRail({ const obstacleBottom = rect.bottom + safeGap; obstacleSafeTop = Math.max(obstacleSafeTop, obstacleBottom); safeTop = Math.max(safeTop, obstacleBottom); - } else if (rect.top >= baseTop) { - bottomObstacles.push({ top: rect.top }); + } else if ( + rect.top < viewportHeight * 0.5 && + rect.bottom > viewportHeight * 0.5 + ) { + spanTop = Math.min(spanTop, rect.top); + spanBottom = Math.max(spanBottom, rect.bottom); } else { - straddling.push(rect); + bottomObstacles.push({ top: rect.top }); } } - // An obstacle from above the corridor across the midpoint (common in short - // windows) still limits it: the panels go on whichever side of it leaves - // more room. - for (const rect of straddling) { - const roomAbove = rect.top - safeGap - obstacleSafeTop; + // The panels go on whichever side of that span leaves more room (common in + // short windows), above it on a tie. With no room on either side the + // corridor stays as it is. + if (spanBottom > spanTop) { + const roomAbove = spanTop - safeGap - obstacleSafeTop; const lowerBottom = resolveLeftStackBottomBoundary({ baseBottom: safeBottom, obstacles: bottomObstacles, safeGap, }); - const roomBelow = lowerBottom - (rect.bottom + safeGap); - if (roomBelow > roomAbove) { - const obstacleBottom = rect.bottom + safeGap; - obstacleSafeTop = Math.max(obstacleSafeTop, obstacleBottom); - safeTop = Math.max(safeTop, obstacleBottom); - } else bottomObstacles.push({ top: rect.top }); + const roomBelow = lowerBottom - (spanBottom + safeGap); + if (roomBelow > roomAbove && roomBelow > 0) { + obstacleSafeTop = Math.max(obstacleSafeTop, spanBottom + safeGap); + safeTop = Math.max(safeTop, spanBottom + safeGap); + } else if (roomAbove > 0) bottomObstacles.push({ top: spanTop }); } safeBottom = resolveLeftStackBottomBoundary({ baseBottom: safeBottom, diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index fc973a638a..65c53729c9 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -2,7 +2,8 @@ * Resolve a vertically centered panel slot inside a HUD rail while respecting * live rectangles that intersect that rail. A rectangle above the viewport * center lowers the top, one below it raises the bottom, and one across the - * center does whichever leaves the band more room. + * center puts the band on whichever side of it has more room, or leaves the + * band as it is when neither side has any. */ export function resolveHudRailLayout({ viewportHeight, @@ -31,7 +32,10 @@ export function resolveHudRailLayout({ const midpoint = viewportHeight * 0.5; let safeTop = Math.max(0, baseTop); let safeBottom = Math.min(viewportHeight, baseBottom); - const straddling = []; + // Every obstacle across the midpoint covers it, so together they cover one + // span: from the highest top to the lowest bottom. + let spanTop = Infinity; + let spanBottom = -Infinity; for (const rect of obstacles) { if ( @@ -47,15 +51,18 @@ export function resolveHudRailLayout({ if (rect.bottom <= midpoint) safeTop = Math.max(safeTop, rect.bottom + gap); else if (rect.top >= midpoint) safeBottom = Math.min(safeBottom, rect.top - gap); - else straddling.push(rect); + else { + spanTop = Math.min(spanTop, rect.top); + spanBottom = Math.max(spanBottom, rect.bottom); + } } - // An obstacle across the midpoint (common in short windows) still limits - // the band: the band goes on whichever side of it leaves more room. - for (const rect of straddling) { - const roomAbove = rect.top - gap - safeTop; - const roomBelow = safeBottom - (rect.bottom + gap); - if (roomBelow > roomAbove) safeTop = Math.max(safeTop, rect.bottom + gap); - else safeBottom = Math.min(safeBottom, rect.top - gap); + // The band goes on whichever side of that span leaves more room, above it + // on a tie. With no room on either side the band stays as it is. + if (spanBottom > spanTop) { + const roomAbove = spanTop - gap - safeTop; + const roomBelow = safeBottom - (spanBottom + gap); + if (roomBelow > roomAbove && roomBelow > 0) safeTop = spanBottom + gap; + else if (roomAbove > 0) safeBottom = spanTop - gap; } safeBottom = Math.max(safeTop, safeBottom); diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index 32e52a8083..e51de287fa 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -220,22 +220,42 @@ test('left corridor respects a lower obstacle but ignores an obstacle hidden by }); test('in a short window the left corridor stays clear of an obstacle across the midpoint', () => { - // 480px window, midpoint 240. Neither card is wholly above or below it. + // 480px window, midpoint 240. const f = fixture('left'); f.options.windowRef.innerHeight = 480; - const low = element('card', { top: 100, height: 200 }); - f.options.obstacles = [low]; + f.options.obstacles = [element('card', { top: 100, height: 200 })]; f.run(); // More room below the card than above it: the corridor starts under it. assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300); - assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 480); - const high = element('card', { top: 200, height: 200 }); - f.options.obstacles = [high]; + // A card starting below the corridor's usual top (26%, 124.8px) that + // crosses the midpoint counts the same way: more room below it. + f.options.obstacles = [element('card', { top: 130, height: 120 })]; f.run(); + assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 250); + // More room above it: the corridor ends over it. + f.options.obstacles = [element('card', { top: 200, height: 250 })]; + f.run(); assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 200); - assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 0); +}); + +test('several cards across the midpoint give the left corridor the same room in any order', () => { + const f = fixture('left'); + f.options.windowRef.innerHeight = 480; + const a = element('card', { top: 100, height: 160 }); + const b = element('card', { top: 110, height: 360 }); + f.options.obstacles = [a, b]; + f.run(); + const first = [f.stack.dataset.safeTopPct, f.stack.dataset.safeBottomPct]; + f.options.obstacles = [b, a]; + f.run(); + assert.deepEqual( + [f.stack.dataset.safeTopPct, f.stack.dataset.safeBottomPct], + first, + ); + // Together they cover 100 to 470: the corridor ends above them. + assert(Number(first[1]) * 4.8 <= 100); }); test('a centered timeline only shortens the corridor when it reaches a laid-out panel', () => { From ecb7e7cd68df4b50e86933882bb6955147543e1c Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:41:36 -0800 Subject: [PATCH 07/16] Add the changelog entry for #1838 Co-authored-by: Manjunath Paparaju --- changelog.d/1838-nearby-places-namesake.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1838-nearby-places-namesake.md diff --git a/changelog.d/1838-nearby-places-namesake.md b/changelog.d/1838-nearby-places-namesake.md new file mode 100644 index 0000000000..a9efb54a0c --- /dev/null +++ b/changelog.d/1838-nearby-places-namesake.md @@ -0,0 +1,4 @@ +- "Villages near" a name picks the place of that name in view over a far + bigger namesake, a view of the whole globe reads only the place tiles + around its centre, and rebuilding the places pack never leaves it half + removed (manjunath22466, samehkhamis, #1838). From d2797dbad29aeb12460a99489fb9c02808f47ee8 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:44:12 -0800 Subject: [PATCH 08/16] fix(places): keep the places index's build date only when every tile is unchanged; say the 500 km cap is for wide lookups Co-authored-by: Manjunath Paparaju --- changelog.d/1838-nearby-places-namesake.md | 6 ++--- docs/CURRENT-STATE.md | 4 ++-- scripts/build-wikidata-cities.mjs | 22 +++++++++++++++---- scripts/wikidataPlaceTiles.mjs | 4 +++- src/data/local_data/wikidata_places/README.md | 9 ++++---- src/data/wikidataCities.js | 9 ++++---- src/data/wikidataCities.test.mjs | 2 +- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/changelog.d/1838-nearby-places-namesake.md b/changelog.d/1838-nearby-places-namesake.md index a9efb54a0c..ffda7e347e 100644 --- a/changelog.d/1838-nearby-places-namesake.md +++ b/changelog.d/1838-nearby-places-namesake.md @@ -1,4 +1,4 @@ - "Villages near" a name picks the place of that name in view over a far - bigger namesake, a view of the whole globe reads only the place tiles - around its centre, and rebuilding the places pack never leaves it half - removed (manjunath22466, samehkhamis, #1838). + bigger namesake, a place lookup reads the detail tiles within 500 km at + most, and rebuilding the places pack never leaves it half removed + (manjunath22466, samehkhamis, #1838). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index f51d96efcb..ff51fca9fe 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8254,8 +8254,8 @@ the city is listed. A place named in "villages near …" is the nearest of that name within 150 km of the view, small places included, so a village in view comes before a bigger namesake far away; with none near, the largest city of the name. Small places are looked for within 500 km at most, so a -view zoomed out to the whole globe reads only the detail tiles around its -centre. At most 64 detail tiles are kept in memory, the least +lookup asked for a wider radius reads only the detail tiles around its +centre (the search box asks for 150 km at most). At most 64 detail tiles are kept in memory, the least recently used dropped first. ### Place-search providers diff --git a/scripts/build-wikidata-cities.mjs b/scripts/build-wikidata-cities.mjs index 00dc36f0c0..1c66eea87b 100644 --- a/scripts/build-wikidata-cities.mjs +++ b/scripts/build-wikidata-cities.mjs @@ -505,11 +505,25 @@ if (tilesMode) { // The new files are all written before tiles from an earlier build that // this one has no rows for go, so a build that stops part way never leaves // an index naming a removed tile. - const indexFile = path.join(outDir, 'index.json'); - files.set( - 'index.json', - keepBuiltIfUnchanged(files.get('index.json'), await readIfThere(indexFile)), + // The index holds only row counts, so its build date is kept only when + // every tile is unchanged too and no earlier tile is left over. + const earlierTiles = (await readdir(outDir)).filter((name) => + /^-?\d+_-?\d+\.json$/.test(name), ); + let tilesUnchanged = earlierTiles.every((name) => files.has(name)); + for (const [name, text] of files) { + if (!tilesUnchanged) break; + if (name === 'index.json') continue; + tilesUnchanged = (await readIfThere(path.join(outDir, name))) === text; + } + if (tilesUnchanged) + files.set( + 'index.json', + keepBuiltIfUnchanged( + files.get('index.json'), + await readIfThere(path.join(outDir, 'index.json')), + ), + ); for (const [name, text] of files) await writeFile(path.join(outDir, name), text); for (const name of await readdir(outDir)) diff --git a/scripts/wikidataPlaceTiles.mjs b/scripts/wikidataPlaceTiles.mjs index bae1774bb7..98c2b10651 100644 --- a/scripts/wikidataPlaceTiles.mjs +++ b/scripts/wikidataPlaceTiles.mjs @@ -92,7 +92,9 @@ export function placeTileFiles(rows, meta) { /** * A pack file's new text, keeping the earlier build's `meta.built` when * nothing else in the file changed, so rebuilding unchanged data leaves the - * file as it was. + * file as it was. A file that does not hold all of its pack's data (the + * places index) is passed through this only when the rest of the pack is + * unchanged too. * @param {string} text The new file, JSON with a `meta.built` stamp. * @param {string | undefined} earlier The file as it is now, if there is one. */ diff --git a/src/data/local_data/wikidata_places/README.md b/src/data/local_data/wikidata_places/README.md index 144f907209..efad9ea1b3 100644 --- a/src/data/local_data/wikidata_places/README.md +++ b/src/data/local_data/wikidata_places/README.md @@ -20,8 +20,9 @@ entry in the index. **Loading:** nothing here loads with the app. A lookup reads `files.js` and the index once, then only the tiles its search box touches (one for a short radius well inside a tile, more near tile edges and for wider searches), -once each. The search box reaches 500 km at most (`PLACE_TILE_KM`), so a -view of the whole globe reads only the tiles around its centre: at most one +once each. A lookup reaches 500 km at most (`PLACE_TILE_KM`; the search box +asks for 150 km at most), so one asked for a wider radius reads only the +tiles around its centre: at most one tile past the centre's own on each side, a few more columns toward the poles, and never all 732. Cities still count to the full radius. At most 64 tiles are kept in memory, the least recently used @@ -48,8 +49,8 @@ It writes only to this folder (tiles, `index.json`, `files.js`, through `scripts/wikidataPlaceTiles.mjs`) and leaves `../wikidata_cities` alone. It runs one query at a time with pauses and takes a long while. The new files are all written before tiles that the new build has no rows for are -removed, and `meta.built` keeps its earlier date when nothing else in -`index.json` changed. +removed, and `meta.built` keeps its earlier date when no tile and +nothing else in `index.json` changed. **Reproducibility:** the step from rows to files is checked offline: `src/tooling/wikidataPlaceTiles.test.mjs` sorts the shipped rows as the diff --git a/src/data/wikidataCities.js b/src/data/wikidataCities.js index 2b62ac62b0..c36dd89c3a 100644 --- a/src/data/wikidataCities.js +++ b/src/data/wikidataCities.js @@ -219,10 +219,11 @@ const TILE_DEG = 5; const MAX_TILES = 64; /** * How far out small places are looked for, in km. 500 km is under the 556 km - * that 5 degrees of latitude span, so the search box reaches at most one tile - * past the point's own on each side: 3 rows, and 3 columns at the equator - * (more toward the poles, where tiles narrow). A wider view, out to the whole - * globe, still reads only those tiles; cities count to its full radius. + * that 5 degrees of latitude span, so a lookup's tile box reaches at most one + * tile past the point's own on each side: 3 rows, and 3 columns at the + * equator (more toward the poles, where tiles narrow). A lookup asked for a + * wider radius, up to the whole globe, still reads only those tiles; cities + * count to its full radius. */ export const PLACE_TILE_KM = 500; const NAMED = /\p{L}/u; diff --git a/src/data/wikidataCities.test.mjs b/src/data/wikidataCities.test.mjs index 10cec8c834..6e6f742007 100644 --- a/src/data/wikidataCities.test.mjs +++ b/src/data/wikidataCities.test.mjs @@ -282,7 +282,7 @@ test('a tile that cannot be read leaves the other places and the cities', async assert.ok(near.some((place) => place.longitude > -95)); }); -test('a view of the whole globe reads only the tiles near its centre', async () => { +test('a lookup asked for the whole globe reads only the tiles near its centre', async () => { const { placesNear, PLACE_TILE_KM } = await import('./wikidataCities.js?globe'); const fetched = []; From 75e345aa07a2a919815613c81ddb23210936497f Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:44:36 -0800 Subject: [PATCH 09/16] fix(places): small places stop at 500 km even in tiles that reach past it Co-authored-by: Manjunath Paparaju --- src/data/wikidataCities.js | 9 ++++++++- src/data/wikidataCities.test.mjs | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/data/wikidataCities.js b/src/data/wikidataCities.js index c36dd89c3a..e106d2bc4c 100644 --- a/src/data/wikidataCities.js +++ b/src/data/wikidataCities.js @@ -339,7 +339,14 @@ export async function placesNear( const found = [ ...cities.filter((city) => city.distanceKm <= radius), ...detail - .flatMap((source) => citiesWithin(source, latitude, longitude, radius)) + .flatMap((source) => + citiesWithin( + source, + latitude, + longitude, + Math.min(radius, PLACE_TILE_KM), + ), + ) .filter((place) => !twinOfCity(place)), ]; const seen = new Set(); diff --git a/src/data/wikidataCities.test.mjs b/src/data/wikidataCities.test.mjs index 6e6f742007..84c5a8c112 100644 --- a/src/data/wikidataCities.test.mjs +++ b/src/data/wikidataCities.test.mjs @@ -315,6 +315,14 @@ test('a lookup asked for the whole globe reads only the tiles near its centre', fetchPack, ); assert.ok(far.some((place) => place.wikidata === 'Q90')); + // Places from the tiles it read stop at 500 km too: Tahoka, Texas + // (Q982084), a town of about 2,500, is 500.6 km away. + assert.ok(!far.some((place) => place.wikidata === 'Q982084')); + assert.ok( + far + .filter((place) => place.distanceKm > PLACE_TILE_KM) + .every((place) => place.population >= 15000), + ); assert.equal( fetched.filter((name) => /^-?\d+_-?\d+\.json$/.test(name)).length, tileReads.length, From 98a100ed7ebd5c13a65b56eec86f793e2bc65ba9 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:51:42 -0800 Subject: [PATCH 10/16] fix(ui): rails count the obstacles beside those across the middle, and read them as before when neither side has room Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 10 +++-- src/cockpitMarkup.test.mjs | 2 +- src/cockpitMath.test.mjs | 31 +++++++++++++ src/ui/leftPanelRail.js | 45 ++++++++----------- src/ui/panelRailGeometry.js | 88 +++++++++++++++++++++++++++++-------- src/ui/panelRails.test.mjs | 20 +++++++++ 6 files changed, 146 insertions(+), 50 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 5e36fa9df4..d08d3ccb0b 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1198,10 +1198,12 @@ view, recording and scene playback lay the line out themselves. The left rail treats the centered World Timeline and voice control as obstacles only where they reach a laid-out panel, not the stack's transparent gutter. Obstacles across the middle of the window (common in -short windows) are taken together, from the highest top to the lowest -bottom, and both rails put their panels on whichever side of that span has -more room, above it on a tie, whatever order the obstacles come in. With no -room on either side the panels keep their place, as before. +short windows) form one block with any obstacle that leaves no room between +itself and them, and both rails put their panels on whichever side of that +block has more room up to the next obstacle, above it on a tie, whatever +order the obstacles come in (`bandBesideMidpointObstacles` in +`src/ui/panelRailGeometry.js`). With no room on either side the obstacles +are read as before. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/src/cockpitMarkup.test.mjs b/src/cockpitMarkup.test.mjs index 2fa3c1aea4..3a084af32f 100644 --- a/src/cockpitMarkup.test.mjs +++ b/src/cockpitMarkup.test.mjs @@ -1010,7 +1010,7 @@ test('an expanded Cockpit left panel stays above Contact, HUD, and attribution', assert.ok(leftLayout, 'left accordion layout pass is missing'); assert.match( leftLayout, - /\} else \{\s*\n\s*bottomObstacles\.push\(\{ top: rect\.top \}\);\s*\n\s*\}\s*\n\s*\}/, + /rect\.top >= baseTop\) \{\s*\n\s*bottomObstacles\.push\(\{ top: rect\.top \}\);/, 'every rendered lower-lane obstacle must constrain the panel corridor', ); assert.match( diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index 8754954d66..d01a66209d 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -358,6 +358,37 @@ test('HUD rail layout reads several obstacles across the midpoint the same in an } }); +test('HUD rail layout counts obstacles beside those across the midpoint', () => { + const band = (obstacles) => { + const layout = resolveHudRailLayout({ + viewportHeight: 480, + panelHeight: 120, + laneLeft: 20, + laneRight: 340, + baseTop: 40, + baseBottom: 460, + gap: 10, + obstacles: obstacles.map(([top, bottom]) => ({ + left: 0, + right: 400, + top, + bottom, + })), + }); + return [layout.safeTop, layout.safeBottom]; + }; + // One inside the span below the midpoint: 150px below the span, 50 above. + assert.deepEqual(band([[100, 300], [250, 280]]), [310, 460]); + // One touching the midpoint from below: 190px below, 100 above. + assert.deepEqual(band([[150, 260], [240, 250]]), [270, 460]); + // One inside the span above the midpoint: 150px above, 50 below. + assert.deepEqual(band([[200, 400], [210, 230]]), [40, 190]); + // A lower obstacle past the span limits the room below it: 100px between + // them against 70 above, and with a taller one only 60, so above. + assert.deepEqual(band([[120, 260], [380, 420]]), [270, 370]); + assert.deepEqual(band([[120, 260], [340, 420]]), [40, 110]); +}); + test('HUD rail layout can anchor controls to the start of the safe corridor', () => { const layout = resolveHudRailLayout({ viewportHeight: 1000, diff --git a/src/ui/leftPanelRail.js b/src/ui/leftPanelRail.js index 909ed1b660..c6e7f6d1f3 100644 --- a/src/ui/leftPanelRail.js +++ b/src/ui/leftPanelRail.js @@ -5,6 +5,7 @@ import { resolvePanelStackCorridor, } from '../panelStackLayout.js'; import { measurePanelNaturalHeight } from './panelMeasurement.js'; +import { bandBesideMidpointObstacles } from './panelRailGeometry.js'; import { settleSideAccordion } from './panelAccordion.js'; /** @@ -118,10 +119,7 @@ export function layoutLeftPanelRail({ let safeTop = baseTop; let safeBottom = viewportHeight - baseBottomInset; const bottomObstacles = []; - // Obstacles across the midpoint all cover it, so together they cover one - // span: from the highest top to the lowest bottom. - let spanTop = Infinity; - let spanBottom = -Infinity; + const inLane = []; for (const obstacle of obstacles) { if (stack.contains(obstacle)) continue; @@ -151,35 +149,30 @@ export function layoutLeftPanelRail({ ); if (!overlapsHorizontally) continue; + inLane.push(rect); if (rect.top < baseTop && rect.bottom <= viewportHeight * 0.5) { const obstacleBottom = rect.bottom + safeGap; obstacleSafeTop = Math.max(obstacleSafeTop, obstacleBottom); safeTop = Math.max(safeTop, obstacleBottom); - } else if ( - rect.top < viewportHeight * 0.5 && - rect.bottom > viewportHeight * 0.5 - ) { - spanTop = Math.min(spanTop, rect.top); - spanBottom = Math.max(spanBottom, rect.bottom); - } else { + } else if (rect.top >= baseTop) { bottomObstacles.push({ top: rect.top }); } } - // The panels go on whichever side of that span leaves more room (common in - // short windows), above it on a tie. With no room on either side the - // corridor stays as it is. - if (spanBottom > spanTop) { - const roomAbove = spanTop - safeGap - obstacleSafeTop; - const lowerBottom = resolveLeftStackBottomBoundary({ - baseBottom: safeBottom, - obstacles: bottomObstacles, - safeGap, - }); - const roomBelow = lowerBottom - (spanBottom + safeGap); - if (roomBelow > roomAbove && roomBelow > 0) { - obstacleSafeTop = Math.max(obstacleSafeTop, spanBottom + safeGap); - safeTop = Math.max(safeTop, spanBottom + safeGap); - } else if (roomAbove > 0) bottomObstacles.push({ top: spanTop }); + // Obstacles across the midpoint (common in short windows) put the panels + // on whichever side of them has more room; with no room on either side the + // obstacles are read as before. + const beside = bandBesideMidpointObstacles({ + midpoint: viewportHeight * 0.5, + top: viewportHeight * 0.04, + bottom: safeBottom, + obstacles: inLane, + gap: safeGap, + }); + if (beside) { + obstacleSafeTop = beside.top; + safeTop = Math.max(baseTop, beside.top); + bottomObstacles.length = 0; + bottomObstacles.push({ top: beside.bottom + safeGap }); } safeBottom = resolveLeftStackBottomBoundary({ baseBottom: safeBottom, diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index 65c53729c9..1d0821534f 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -1,9 +1,9 @@ /** * Resolve a vertically centered panel slot inside a HUD rail while respecting * live rectangles that intersect that rail. A rectangle above the viewport - * center lowers the top, one below it raises the bottom, and one across the - * center puts the band on whichever side of it has more room, or leaves the - * band as it is when neither side has any. + * center lowers the top and one below it raises the bottom. Rectangles across + * the center put the band beside them (bandBesideMidpointObstacles); with no + * room on either side they are left out, as before. */ export function resolveHudRailLayout({ viewportHeight, @@ -32,10 +32,7 @@ export function resolveHudRailLayout({ const midpoint = viewportHeight * 0.5; let safeTop = Math.max(0, baseTop); let safeBottom = Math.min(viewportHeight, baseBottom); - // Every obstacle across the midpoint covers it, so together they cover one - // span: from the highest top to the lowest bottom. - let spanTop = Infinity; - let spanBottom = -Infinity; + const inLane = []; for (const rect of obstacles) { if ( @@ -48,22 +45,19 @@ export function resolveHudRailLayout({ rect.bottom <= rect.top ) continue; + inLane.push(rect); if (rect.bottom <= midpoint) safeTop = Math.max(safeTop, rect.bottom + gap); else if (rect.top >= midpoint) safeBottom = Math.min(safeBottom, rect.top - gap); - else { - spanTop = Math.min(spanTop, rect.top); - spanBottom = Math.max(spanBottom, rect.bottom); - } - } - // The band goes on whichever side of that span leaves more room, above it - // on a tie. With no room on either side the band stays as it is. - if (spanBottom > spanTop) { - const roomAbove = spanTop - gap - safeTop; - const roomBelow = safeBottom - (spanBottom + gap); - if (roomBelow > roomAbove && roomBelow > 0) safeTop = spanBottom + gap; - else if (roomAbove > 0) safeBottom = spanTop - gap; } + const beside = bandBesideMidpointObstacles({ + midpoint, + top: Math.max(0, baseTop), + bottom: Math.min(viewportHeight, baseBottom), + obstacles: inLane, + gap, + }); + if (beside) ({ top: safeTop, bottom: safeBottom } = beside); safeBottom = Math.max(safeTop, safeBottom); const availableHeight = Math.max(0, safeBottom - safeTop); @@ -80,6 +74,62 @@ export function resolveHudRailLayout({ }; } +/** + * Where a rail's band goes when obstacles cross the viewport midpoint, as in + * short windows. Those obstacles, and any other that leaves no band between + * itself and them, form one block; the band takes whichever side of the block + * has more room between it and the next obstacle or the band's own edge, + * above on a tie. + * @param {object} input + * @param {number} input.midpoint The viewport's vertical midpoint. + * @param {number} input.top The band's highest top. + * @param {number} input.bottom The band's lowest bottom. + * @param {Array<{top: number, bottom: number}>} input.obstacles Rectangles that reach the rail. + * @param {number} input.gap Space kept between the band and an obstacle. + * @returns {{side: 'above' | 'below', top: number, bottom: number} | null} + * Null when nothing crosses the midpoint or neither side has room. + */ +export function bandBesideMidpointObstacles({ + midpoint, + top, + bottom, + obstacles, + gap, +}) { + const crossing = obstacles.filter( + (rect) => rect.top < midpoint && rect.bottom > midpoint, + ); + if (!crossing.length) return null; + let blockTop = Math.min(...crossing.map((rect) => rect.top)); + let blockBottom = Math.max(...crossing.map((rect) => rect.bottom)); + for (let grown = true; grown;) { + grown = false; + for (const rect of obstacles) { + const touches = + rect.top < blockBottom + 2 * gap && rect.bottom > blockTop - 2 * gap; + if (touches && (rect.top < blockTop || rect.bottom > blockBottom)) { + blockTop = Math.min(blockTop, rect.top); + blockBottom = Math.max(blockBottom, rect.bottom); + grown = true; + } + } + } + let aboveTop = top; + let belowBottom = bottom; + for (const rect of obstacles) { + if (rect.bottom <= blockTop) + aboveTop = Math.max(aboveTop, rect.bottom + gap); + else if (rect.top >= blockBottom) + belowBottom = Math.min(belowBottom, rect.top - gap); + } + const above = { side: 'above', top: aboveTop, bottom: blockTop - gap }; + const below = { side: 'below', top: blockBottom + gap, bottom: belowBottom }; + const roomAbove = above.bottom - above.top; + const roomBelow = below.bottom - below.top; + if (roomBelow > roomAbove && roomBelow > 0) return below; + return roomAbove > 0 ? above : null; +} + /** * Whether the Tactical layout hid collapsed right panels beside an expanded * one. The rail now enforces one open panel per side in every layout; this diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index e51de287fa..c58d7b0603 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -258,6 +258,26 @@ test('several cards across the midpoint give the left corridor the same room in assert(Number(first[1]) * 4.8 <= 100); }); +test('the left corridor counts cards beside those across the midpoint', () => { + const f = fixture('left'); + f.options.windowRef.innerHeight = 480; + // A card inside the span below the midpoint: more room below both. + f.options.obstacles = [ + element('card', { top: 100, height: 200 }), + element('card', { top: 250, height: 30 }), + ]; + f.run(); + assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300); + // No room on either side: the cards are read as before, and the corridor + // never runs down through the lower one. + f.options.obstacles = [ + element('card', { top: 50, height: 150 }), + element('card', { top: 150, height: 320 }), + ]; + f.run(); + assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 210); +}); + test('a centered timeline only shortens the corridor when it reaches a laid-out panel', () => { const f = fixture('left'); f.stack.rect.width = 360; From 50824c9a65bfe5d5be95e04467f2d152be405eef Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 22:54:53 -0800 Subject: [PATCH 11/16] test(places): pin the pack build-date rule and a nearer village beating a namesake inside a wide search Co-authored-by: Manjunath Paparaju --- scripts/build-wikidata-cities.mjs | 25 +++++---------------- scripts/wikidataPlaceTiles.mjs | 20 +++++++++++++++++ src/data/wikidataCities.test.mjs | 11 ++++++++++ src/tooling/wikidataPlaceTiles.test.mjs | 29 +++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/scripts/build-wikidata-cities.mjs b/scripts/build-wikidata-cities.mjs index 1c66eea87b..d2016fa3d7 100644 --- a/scripts/build-wikidata-cities.mjs +++ b/scripts/build-wikidata-cities.mjs @@ -40,6 +40,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { keepBuiltIfUnchanged, + keepPackBuiltIfUnchanged, placeTileFiles, withoutCities, withoutNearTwins, @@ -505,25 +506,11 @@ if (tilesMode) { // The new files are all written before tiles from an earlier build that // this one has no rows for go, so a build that stops part way never leaves // an index naming a removed tile. - // The index holds only row counts, so its build date is kept only when - // every tile is unchanged too and no earlier tile is left over. - const earlierTiles = (await readdir(outDir)).filter((name) => - /^-?\d+_-?\d+\.json$/.test(name), - ); - let tilesUnchanged = earlierTiles.every((name) => files.has(name)); - for (const [name, text] of files) { - if (!tilesUnchanged) break; - if (name === 'index.json') continue; - tilesUnchanged = (await readIfThere(path.join(outDir, name))) === text; - } - if (tilesUnchanged) - files.set( - 'index.json', - keepBuiltIfUnchanged( - files.get('index.json'), - await readIfThere(path.join(outDir, 'index.json')), - ), - ); + const earlier = new Map(); + for (const name of await readdir(outDir)) + if (/^-?\d+_-?\d+\.json$|^index\.json$|^files\.js$/.test(name)) + earlier.set(name, await readFile(path.join(outDir, name), 'utf8')); + keepPackBuiltIfUnchanged(files, earlier); for (const [name, text] of files) await writeFile(path.join(outDir, name), text); for (const name of await readdir(outDir)) diff --git a/scripts/wikidataPlaceTiles.mjs b/scripts/wikidataPlaceTiles.mjs index 98c2b10651..d3396937f6 100644 --- a/scripts/wikidataPlaceTiles.mjs +++ b/scripts/wikidataPlaceTiles.mjs @@ -114,6 +114,26 @@ export function keepBuiltIfUnchanged(text, earlier) { return `${JSON.stringify({ ...after, meta: { ...after.meta, built: before.meta.built } })}\n`; } +/** + * Keeps the earlier build's `meta.built` in the places pack's index when the + * rebuild changed nothing: every tile and `files.js` the same text, no tile + * of the earlier build left out, and nothing else in the index changed. The + * index holds only row counts, so it alone cannot tell. + * @param {Map} files The new pack, as placeTileFiles gives it; its index is replaced in place. + * @param {Map} earlier The pack's files on disk now, by name. + */ +export function keepPackBuiltIfUnchanged(files, earlier) { + for (const name of earlier.keys()) + if (name !== 'index.json' && !files.has(name)) return files; + for (const [name, text] of files) + if (name !== 'index.json' && earlier.get(name) !== text) return files; + files.set( + 'index.json', + keepBuiltIfUnchanged(files.get('index.json'), earlier.get('index.json')), + ); + return files; +} + const kmBetween = (a, b) => greatCircleKm({ lat: a[1], lon: a[2] }, { lat: b[1], lon: b[2] }); diff --git a/src/data/wikidataCities.test.mjs b/src/data/wikidataCities.test.mjs index 84c5a8c112..4c62b1b65b 100644 --- a/src/data/wikidataCities.test.mjs +++ b/src/data/wikidataCities.test.mjs @@ -115,6 +115,17 @@ test('a small place in view comes before a far bigger city of its name', async ( const austin = { latitude: 30.27, longitude: -97.74 }; assert.equal((await find('Paris', austin)).wikidata, 'Q-village'); assert.ok((await find('Paris', austin)).distanceKm < 20); + // A bigger namesake inside a wider search: the nearer village still wins. + assert.equal( + ( + await module.findPlace( + 'Paris', + { near: austin, radiusKm: 600, includeSmallPlaces: true }, + fetchImpl, + ) + ).wikidata, + 'Q-village', + ); // Only when small places are asked for. assert.equal( (await module.findPlace('Paris', { near: austin }, fetchImpl)).wikidata, diff --git a/src/tooling/wikidataPlaceTiles.test.mjs b/src/tooling/wikidataPlaceTiles.test.mjs index 10e77b8dd3..9f807c20e5 100644 --- a/src/tooling/wikidataPlaceTiles.test.mjs +++ b/src/tooling/wikidataPlaceTiles.test.mjs @@ -9,6 +9,7 @@ import { readdir, readFile } from 'node:fs/promises'; import test from 'node:test'; import { keepBuiltIfUnchanged, + keepPackBuiltIfUnchanged, placeTileFiles, tileKey, withoutCities, @@ -114,3 +115,31 @@ test('a rebuild of unchanged rows keeps the earlier build stamp', () => { assert.equal(keepBuiltIfUnchanged(same, undefined), same); assert.equal(keepBuiltIfUnchanged(same, 'not json'), same); }); + +test('the places index keeps its build stamp only when no tile changed', () => { + const rows = [ + ['Aa', 31, -98, 2000, 'US', 'Q1'], + ['Bb', 41, -88, 1500, 'US', 'Q2'], + ]; + const meta = (built) => ({ + source: 's', + license: 'l', + built, + minPopulation: 1000, + maxPopulation: 15000, + columns: [], + }); + const earlier = placeTileFiles(rows, meta('2026-01-01T00:00:00.000Z')); + const built = (files) => JSON.parse(files.get('index.json')).meta.built; + const rebuild = (newRows) => + keepPackBuiltIfUnchanged( + placeTileFiles(newRows, meta('2026-11-18T00:00:00.000Z')), + earlier, + ); + assert.equal(built(rebuild(rows)), '2026-01-01T00:00:00.000Z'); + // Same row count in every tile, new population: a new stamp. + const changed = [['Aa', 31, -98, 2100, 'US', 'Q1'], rows[1]]; + assert.equal(built(rebuild(changed)), '2026-11-18T00:00:00.000Z'); + // A tile of the earlier build left out: a new stamp. + assert.equal(built(rebuild([rows[0]])), '2026-11-18T00:00:00.000Z'); +}); From 81df2c8c42bad49216bf7f1627f96fdd6d63de9d Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:01:47 -0800 Subject: [PATCH 12/16] fix(ui): the left rail's panels use all the room it counted above an obstacle across the middle Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 5 +++-- src/ui/leftPanelRail.js | 10 ++++++---- src/ui/panelRails.test.mjs | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index d08d3ccb0b..91655cb712 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1202,8 +1202,9 @@ short windows) form one block with any obstacle that leaves no room between itself and them, and both rails put their panels on whichever side of that block has more room up to the next obstacle, above it on a tie, whatever order the obstacles come in (`bandBesideMidpointObstacles` in -`src/ui/panelRailGeometry.js`). With no room on either side the obstacles -are read as before. +`src/ui/panelRailGeometry.js`); on the left rail the panels may then rise +above the corridor's usual top to use all the room above. With no room on +either side the obstacles are read as before. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/src/ui/leftPanelRail.js b/src/ui/leftPanelRail.js index c6e7f6d1f3..4def1dcfc6 100644 --- a/src/ui/leftPanelRail.js +++ b/src/ui/leftPanelRail.js @@ -115,7 +115,8 @@ export function layoutLeftPanelRail({ const baseTop = viewportHeight * 0.26; const baseBottomInset = viewportHeight * 0.04; const safeGap = viewportHeight * 0.012; - let obstacleSafeTop = viewportHeight * 0.04; + const topInset = viewportHeight * 0.04; + let obstacleSafeTop = topInset; let safeTop = baseTop; let safeBottom = viewportHeight - baseBottomInset; const bottomObstacles = []; @@ -159,18 +160,19 @@ export function layoutLeftPanelRail({ } } // Obstacles across the midpoint (common in short windows) put the panels - // on whichever side of them has more room; with no room on either side the + // on whichever side of them has more room, and the panels may use all of + // it, above the corridor's usual top too; with no room on either side the // obstacles are read as before. const beside = bandBesideMidpointObstacles({ midpoint: viewportHeight * 0.5, - top: viewportHeight * 0.04, + top: topInset, bottom: safeBottom, obstacles: inLane, gap: safeGap, }); if (beside) { obstacleSafeTop = beside.top; - safeTop = Math.max(baseTop, beside.top); + safeTop = beside.top; bottomObstacles.length = 0; bottomObstacles.push({ top: beside.bottom + safeGap }); } diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index c58d7b0603..32f972775c 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -268,14 +268,27 @@ test('the left corridor counts cards beside those across the midpoint', () => { ]; f.run(); assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300); - // No room on either side: the cards are read as before, and the corridor - // never runs down through the lower one. + // Only a little room above the cards: the corridor stays there rather + // than run down through the lower one. f.options.obstacles = [ element('card', { top: 50, height: 150 }), element('card', { top: 150, height: 320 }), ]; f.run(); - assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 210); + assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 50); + // The room above a card is all the panels' to use, above the corridor's + // usual top (26%) too: 700px window, card 300 to 420, about 263px above + // against 244 below. + f.options.windowRef.innerHeight = 700; + f.options.obstacles = [element('card', { top: 300, height: 120 })]; + f.run(); + assert(Number(f.stack.dataset.safeBottomPct) * 7 <= 300); + assert(Number(f.stack.dataset.safeTopPct) * 7 < 0.26 * 700); + // No room on either side: the card is read as before. + f.options.windowRef.innerHeight = 480; + f.options.obstacles = [element('card', { top: 0, height: 480 })]; + f.run(); + assert.equal(Number(f.stack.dataset.safeTopPct), 26); }); test('a centered timeline only shortens the corridor when it reaches a laid-out panel', () => { From 378df7b6136cc9ccdbb8f324f88ca7254ed6c01d Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:02:10 -0800 Subject: [PATCH 13/16] fix(ui): neighbours exactly two gaps from a midpoint obstacle join its block, and the band beside it stays inside the rail's own edges Co-authored-by: Manjunath Paparaju --- src/cockpitMath.test.mjs | 18 ++++++++++++++++++ src/ui/panelRailGeometry.js | 14 +++++++++++--- src/ui/panelRails.test.mjs | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index d01a66209d..cda54d2c6a 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -387,6 +387,24 @@ test('HUD rail layout counts obstacles beside those across the midpoint', () => // them against 70 above, and with a taller one only 60, so above. assert.deepEqual(band([[120, 260], [380, 420]]), [270, 370]); assert.deepEqual(band([[120, 260], [340, 420]]), [40, 110]); + // Neighbours exactly two gaps away leave no room between: one block, 100 + // to 400, and a tie (50px a side) goes above. + assert.deepEqual(band([[100, 180], [200, 300], [320, 400]]), [40, 90]); +}); + +test('HUD rail layout keeps a band beside a midpoint obstacle inside its own edges', () => { + const layout = resolveHudRailLayout({ + viewportHeight: 480, + panelHeight: 80, + laneLeft: 20, + laneRight: 340, + baseTop: 350, + baseBottom: 460, + gap: 10, + obstacles: [{ left: 0, right: 400, top: 100, bottom: 260 }], + }); + assert.equal(layout.safeTop, 350); + assert.equal(layout.safeBottom, 460); }); test('HUD rail layout can anchor controls to the start of the safe corridor', () => { diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index 1d0821534f..b845a1a5c5 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -106,7 +106,7 @@ export function bandBesideMidpointObstacles({ grown = false; for (const rect of obstacles) { const touches = - rect.top < blockBottom + 2 * gap && rect.bottom > blockTop - 2 * gap; + rect.top <= blockBottom + 2 * gap && rect.bottom >= blockTop - 2 * gap; if (touches && (rect.top < blockTop || rect.bottom > blockBottom)) { blockTop = Math.min(blockTop, rect.top); blockBottom = Math.max(blockBottom, rect.bottom); @@ -122,8 +122,16 @@ export function bandBesideMidpointObstacles({ else if (rect.top >= blockBottom) belowBottom = Math.min(belowBottom, rect.top - gap); } - const above = { side: 'above', top: aboveTop, bottom: blockTop - gap }; - const below = { side: 'below', top: blockBottom + gap, bottom: belowBottom }; + const above = { + side: 'above', + top: aboveTop, + bottom: Math.min(bottom, blockTop - gap), + }; + const below = { + side: 'below', + top: Math.max(top, blockBottom + gap), + bottom: belowBottom, + }; const roomAbove = above.bottom - above.top; const roomBelow = below.bottom - below.top; if (roomBelow > roomAbove && roomBelow > 0) return below; diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index 32f972775c..1b67600b88 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -283,7 +283,7 @@ test('the left corridor counts cards beside those across the midpoint', () => { f.options.obstacles = [element('card', { top: 300, height: 120 })]; f.run(); assert(Number(f.stack.dataset.safeBottomPct) * 7 <= 300); - assert(Number(f.stack.dataset.safeTopPct) * 7 < 0.26 * 700); + assert(Number(f.stack.dataset.safeTopPct) * 7 <= 30); // No room on either side: the card is read as before. f.options.windowRef.innerHeight = 480; f.options.obstacles = [element('card', { top: 0, height: 480 })]; From 10dbd2f937b77e349c2d96707775dd0d69bf5780 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:14:26 -0800 Subject: [PATCH 14/16] fix(ui): a side of a midpoint block thinner than 8% of the window holds no panel; pin the lower merge edge Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 3 ++- src/cockpitMath.test.mjs | 6 ++++++ src/ui/leftPanelRail.js | 2 ++ src/ui/panelRailGeometry.js | 10 ++++++++-- src/ui/panelRails.test.mjs | 7 ++++--- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 91655cb712..6cd948e474 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1204,7 +1204,8 @@ block has more room up to the next obstacle, above it on a tie, whatever order the obstacles come in (`bandBesideMidpointObstacles` in `src/ui/panelRailGeometry.js`); on the left rail the panels may then rise above the corridor's usual top to use all the room above. With no room on -either side the obstacles are read as before. +either side (a side under 8% of the window's height counts as none) the +obstacles are read as before. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index cda54d2c6a..dd4d55a689 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -390,6 +390,12 @@ test('HUD rail layout counts obstacles beside those across the midpoint', () => // Neighbours exactly two gaps away leave no room between: one block, 100 // to 400, and a tie (50px a side) goes above. assert.deepEqual(band([[100, 180], [200, 300], [320, 400]]), [40, 90]); + // A neighbour exactly two gaps below joins it too: 150 to 300, 110px + // above against 150 below. + assert.deepEqual(band([[150, 250], [270, 300]]), [310, 460]); + // A side under 8% of the window (38.4px) is no room: 30px above, none + // below, so the band stays as it is. + assert.deepEqual(band([[80, 455]]), [40, 460]); }); test('HUD rail layout keeps a band beside a midpoint obstacle inside its own edges', () => { diff --git a/src/ui/leftPanelRail.js b/src/ui/leftPanelRail.js index 4def1dcfc6..5b6af7be0f 100644 --- a/src/ui/leftPanelRail.js +++ b/src/ui/leftPanelRail.js @@ -169,6 +169,8 @@ export function layoutLeftPanelRail({ bottom: safeBottom, obstacles: inLane, gap: safeGap, + // A side thinner than this holds no usable panel. + minimum: viewportHeight * 0.08, }); if (beside) { obstacleSafeTop = beside.top; diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index b845a1a5c5..c7266d8c72 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -56,6 +56,8 @@ export function resolveHudRailLayout({ bottom: Math.min(viewportHeight, baseBottom), obstacles: inLane, gap, + // A side thinner than this holds no usable panel. + minimum: viewportHeight * 0.08, }); if (beside) ({ top: safeTop, bottom: safeBottom } = beside); @@ -86,6 +88,8 @@ export function resolveHudRailLayout({ * @param {number} input.bottom The band's lowest bottom. * @param {Array<{top: number, bottom: number}>} input.obstacles Rectangles that reach the rail. * @param {number} input.gap Space kept between the band and an obstacle. + * @param {number} [input.minimum=0] The least room a side needs to count; + * a thinner side is no room at all. * @returns {{side: 'above' | 'below', top: number, bottom: number} | null} * Null when nothing crosses the midpoint or neither side has room. */ @@ -95,6 +99,7 @@ export function bandBesideMidpointObstacles({ bottom, obstacles, gap, + minimum = 0, }) { const crossing = obstacles.filter( (rect) => rect.top < midpoint && rect.bottom > midpoint, @@ -134,8 +139,9 @@ export function bandBesideMidpointObstacles({ }; const roomAbove = above.bottom - above.top; const roomBelow = below.bottom - below.top; - if (roomBelow > roomAbove && roomBelow > 0) return below; - return roomAbove > 0 ? above : null; + const least = Math.max(minimum, Number.EPSILON); + if (roomBelow > roomAbove && roomBelow >= least) return below; + return roomAbove >= least ? above : null; } /** diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index 1b67600b88..d4a67ed523 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -268,14 +268,15 @@ test('the left corridor counts cards beside those across the midpoint', () => { ]; f.run(); assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300); - // Only a little room above the cards: the corridor stays there rather - // than run down through the lower one. + // About 25px above the cards is under the least usable room (8% of the + // window): they are read as before, the upper card pushing the corridor + // down past it rather than into a sliver at the top. f.options.obstacles = [ element('card', { top: 50, height: 150 }), element('card', { top: 150, height: 320 }), ]; f.run(); - assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 50); + assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 200); // The room above a card is all the panels' to use, above the corridor's // usual top (26%) too: 700px window, card 300 to 420, about 263px above // against 244 below. From fd64a78aca68f1e2faa1ebac302761478db1f265 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:26:10 -0800 Subject: [PATCH 15/16] test(ui): pin the midpoint band's exact minimum, and correct a test comment Co-authored-by: Manjunath Paparaju --- src/cockpitMath.test.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index dd4d55a689..3f8d396211 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -31,6 +31,7 @@ import { speedRulerStep, speedRulerTicks, } from './cockpitMath.js'; +import { bandBesideMidpointObstacles } from './ui/panelRailGeometry.js'; test('cockpit presentation updates are throttled independently of camera frames', () => { assert.equal(cockpitUiUpdateDue(1000, 0, 100), true); @@ -390,12 +391,22 @@ test('HUD rail layout counts obstacles beside those across the midpoint', () => // Neighbours exactly two gaps away leave no room between: one block, 100 // to 400, and a tie (50px a side) goes above. assert.deepEqual(band([[100, 180], [200, 300], [320, 400]]), [40, 90]); - // A neighbour exactly two gaps below joins it too: 150 to 300, 110px + // A neighbour exactly two gaps below joins it too: 150 to 300, 100px // above against 150 below. assert.deepEqual(band([[150, 250], [270, 300]]), [310, 460]); // A side under 8% of the window (38.4px) is no room: 30px above, none // below, so the band stays as it is. assert.deepEqual(band([[80, 455]]), [40, 460]); + // Exactly the minimum is enough. + const exact = bandBesideMidpointObstacles({ + midpoint: 240, + top: 40, + bottom: 460, + obstacles: [{ top: 90, bottom: 465 }], + gap: 10, + minimum: 40, + }); + assert.deepEqual([exact?.top, exact?.bottom], [40, 80]); }); test('HUD rail layout keeps a band beside a midpoint obstacle inside its own edges', () => { From c1e58b72b90cb99bfef069849aae11e1a890cf54 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:26:22 -0800 Subject: [PATCH 16/16] fix(ui): any positive room counts when a midpoint band asks for no minimum Co-authored-by: Manjunath Paparaju --- src/ui/panelRailGeometry.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index c7266d8c72..0cc2f0db25 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -139,9 +139,9 @@ export function bandBesideMidpointObstacles({ }; const roomAbove = above.bottom - above.top; const roomBelow = below.bottom - below.top; - const least = Math.max(minimum, Number.EPSILON); - if (roomBelow > roomAbove && roomBelow >= least) return below; - return roomAbove >= least ? above : null; + const fits = (room) => room > 0 && room >= minimum; + if (roomBelow > roomAbove && fits(roomBelow)) return below; + return fits(roomAbove) ? above : null; } /**