mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Merge pull request #1837 from bilawalsidhu/samehkhamis/rail-and-hud-cleanup
Keep the panel rails clear of an obstacle across the middle of a short window
This commit is contained in:
6 files changed
+332
-3
No files matched your search
@@ -0,0 +1,4 @@
|
||||
- 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).
|
||||
@@ -1198,7 +1198,15 @@ 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. Obstacles across the middle of the window (common in
|
||||
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`); 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 (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.
|
||||
|
||||
@@ -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);
|
||||
@@ -286,6 +287,143 @@ 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 leaves the band as it is when an obstacle across the midpoint 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.safeTop, 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 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]);
|
||||
// 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, 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', () => {
|
||||
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', () => {
|
||||
const layout = resolveHudRailLayout({
|
||||
viewportHeight: 1000,
|
||||
|
||||
+24
-1
@@ -5,6 +5,7 @@ import {
|
||||
resolvePanelStackCorridor,
|
||||
} from '../panelStackLayout.js';
|
||||
import { measurePanelNaturalHeight } from './panelMeasurement.js';
|
||||
import { bandBesideMidpointObstacles } from './panelRailGeometry.js';
|
||||
import { settleSideAccordion } from './panelAccordion.js';
|
||||
|
||||
/**
|
||||
@@ -114,10 +115,12 @@ 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 = [];
|
||||
const inLane = [];
|
||||
|
||||
for (const obstacle of obstacles) {
|
||||
if (stack.contains(obstacle)) continue;
|
||||
@@ -147,6 +150,7 @@ 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);
|
||||
@@ -155,6 +159,25 @@ export function layoutLeftPanelRail({
|
||||
bottomObstacles.push({ top: rect.top });
|
||||
}
|
||||
}
|
||||
// Obstacles across the midpoint (common in short windows) put the panels
|
||||
// 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: topInset,
|
||||
bottom: safeBottom,
|
||||
obstacles: inLane,
|
||||
gap: safeGap,
|
||||
// A side thinner than this holds no usable panel.
|
||||
minimum: viewportHeight * 0.08,
|
||||
});
|
||||
if (beside) {
|
||||
obstacleSafeTop = beside.top;
|
||||
safeTop = beside.top;
|
||||
bottomObstacles.length = 0;
|
||||
bottomObstacles.push({ top: beside.bottom + safeGap });
|
||||
}
|
||||
safeBottom = resolveLeftStackBottomBoundary({
|
||||
baseBottom: safeBottom,
|
||||
obstacles: bottomObstacles,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
/**
|
||||
* 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 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,
|
||||
@@ -29,6 +32,7 @@ export function resolveHudRailLayout({
|
||||
const midpoint = viewportHeight * 0.5;
|
||||
let safeTop = Math.max(0, baseTop);
|
||||
let safeBottom = Math.min(viewportHeight, baseBottom);
|
||||
const inLane = [];
|
||||
|
||||
for (const rect of obstacles) {
|
||||
if (
|
||||
@@ -41,10 +45,21 @@ 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);
|
||||
}
|
||||
const beside = bandBesideMidpointObstacles({
|
||||
midpoint,
|
||||
top: Math.max(0, baseTop),
|
||||
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);
|
||||
|
||||
safeBottom = Math.max(safeTop, safeBottom);
|
||||
const availableHeight = Math.max(0, safeBottom - safeTop);
|
||||
@@ -61,6 +76,74 @@ 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.
|
||||
* @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.
|
||||
*/
|
||||
export function bandBesideMidpointObstacles({
|
||||
midpoint,
|
||||
top,
|
||||
bottom,
|
||||
obstacles,
|
||||
gap,
|
||||
minimum = 0,
|
||||
}) {
|
||||
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: 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;
|
||||
const fits = (room) => room > 0 && room >= minimum;
|
||||
if (roomBelow > roomAbove && fits(roomBelow)) return below;
|
||||
return fits(roomAbove) ? 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
|
||||
|
||||
@@ -219,6 +219,79 @@ 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.
|
||||
const f = fixture('left');
|
||||
f.options.windowRef.innerHeight = 480;
|
||||
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);
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
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('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);
|
||||
// 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.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.
|
||||
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 <= 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 })];
|
||||
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', () => {
|
||||
const f = fixture('left');
|
||||
f.stack.rect.width = 360;
|
||||
|
||||
Reference in new issue
Block a user