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 <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 23:02:10 -08:00
1 parent 81df2c8c42
commit 378df7b613
3 files changed
+30 -4

No files matched your search

+11 -3
View File
@@ -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;
+1 -1
View File
@@ -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 })];