mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
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 <[email protected]>
This commit is contained in:
1 parent
feedd88614
commit
98a100ed7e
6 files changed
+146
-50
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
+19
-26
@@ -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,
|
||||
|
||||
+69
-19
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user