From 378df7b6136cc9ccdbb8f324f88ca7254ed6c01d Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:02:10 -0800 Subject: [PATCH] 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 })];