mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
## Changes Follow-up to #596 from the owner's look: a parked transit vehicle turned with the camera. Moving vehicles project their world course into screen space on every camera change, but a vehicle that had never moved on screen could have no display course and was skipped by that pass, leaving its billboard at a screen-anchored angle; rotation invalidation also relied on camera events that a pose change without a revision could miss. Now every visible vehicle with any usable course (derived, held, or the feed's reported bearing) is re-projected at the existing 5 Hz cadence on camera pose changes. Moving playback and the 120°/s course limiter are unchanged. ## How it was verified - `npm run format:check` (861 files), `npm run check:boundaries` (109 groups), `npm test` (4,068 passing), `npm run build` clean; tracking regression 109/109 in a real browser on Google 3D tiles. - Node tests: a stationary vehicle with a held course, and one with only a reported bearing, under a camera at heading 0° then 90° yield screen rotations 90° apart. - Browser harness (`scripts/qa-transit.mjs`, keyed on Google 3D tiles): a parked scripted vehicle orbited by 90° rotates 90.000° on screen; a moving vehicle's rotation still matches its rendered travel; both checks fail on main and pass here. Full keyed run: 201 pass; the nine failures are the per-frame allocation gate already recorded as a follow-up and threshold-edge readability lines on the Boston matrix, both unchanged from #596.
157 lines
5.7 KiB
JavaScript
157 lines
5.7 KiB
JavaScript
import puppeteer from 'puppeteer';
|
|
|
|
/** Prove parked and moving headings in the real scene, without live feeds. */
|
|
export async function runTransitHeadingRegression(base, check) {
|
|
const browser = await puppeteer.launch({
|
|
headless: true,
|
|
executablePath:
|
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
args: ['--no-sandbox', '--disable-background-timer-throttling'],
|
|
});
|
|
try {
|
|
const page = await browser.newPage();
|
|
await page.setViewport({ width: 1280, height: 800 });
|
|
await page.goto(
|
|
`${base}/?welcome=0#lat=42.3601&lon=-71.0589&alt=1200&heading=0&pitch=-90`,
|
|
{ waitUntil: 'domcontentloaded' },
|
|
);
|
|
await page.waitForFunction(
|
|
() => window.__godsEyeView?.dataManager?.layers?.has('transit'),
|
|
{ timeout: 90000 },
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, 6000));
|
|
await page.evaluate(async () => {
|
|
const app = window.__godsEyeView;
|
|
await app.dataManager.setEnabled('transit', true, { source: 'qa' });
|
|
const layer = app.dataManager.layers.get('transit').module;
|
|
layer._loadTransitFleetForTest(4, { lat: 42.3601, lon: -71.0589 }, 100);
|
|
const state = layer._transitStateForTest(),
|
|
parts = layer._transitPartsForTest();
|
|
const { destroyTrack } = await import('/src/data/contactPlayback.js');
|
|
const {
|
|
initializePlayback,
|
|
recordFix,
|
|
updatePlayback,
|
|
attachFloorToPlace,
|
|
} = await import('/src/layers/transit/movement.js');
|
|
// The first three are parked: held east, reported east only, unknown.
|
|
for (let i = 0; i < 3; i++) {
|
|
const entry = state._vehicles.get(`mbta:qa-${i}`);
|
|
state._moving.delete(entry);
|
|
destroyTrack(entry.track);
|
|
initializePlayback(entry, state._historyBudget);
|
|
recordFix(entry, {
|
|
t: Date.now() - 30000,
|
|
lat: entry.record.lat,
|
|
lon: entry.record.lon,
|
|
});
|
|
attachFloorToPlace(entry, entry.record, 20);
|
|
updatePlayback(entry, Date.now(), performance.now());
|
|
entry.courseDeg = i === 0 ? 90 : null;
|
|
entry.record.bearing = i === 1 ? 90 : null;
|
|
entry.displayPaths.clear();
|
|
parts.rendering.placeSample(entry);
|
|
parts.rendering.schedulePlayback(entry);
|
|
}
|
|
parts.rendering.syncRenderHold();
|
|
window.__headingErrors = [];
|
|
app.viewer.scene.renderError.addEventListener((scene, error) =>
|
|
window.__headingErrors.push(error.message),
|
|
);
|
|
});
|
|
const pose = async (heading) => {
|
|
await page.evaluate((heading) => {
|
|
const camera = window.__godsEyeView.viewer.camera;
|
|
const C = camera.positionCartographic.constructor;
|
|
camera.setView({
|
|
destination: C.toCartesian(C.fromDegrees(-71.0589, 42.3601, 1200)),
|
|
orientation: { heading, pitch: -Math.PI / 2, roll: 0 },
|
|
});
|
|
}, heading);
|
|
await new Promise((resolve) => setTimeout(resolve, 700));
|
|
};
|
|
const sample = () =>
|
|
page.evaluate(async () => {
|
|
const app = window.__godsEyeView,
|
|
scene = app.viewer.scene;
|
|
const state = app.dataManager.layers
|
|
.get('transit')
|
|
.module._transitStateForTest();
|
|
const mul = (m, v) =>
|
|
[0, 1, 2, 3].map(
|
|
(r) =>
|
|
m[r] * v[0] +
|
|
m[r + 4] * v[1] +
|
|
m[r + 8] * v[2] +
|
|
m[r + 12] * v[3],
|
|
);
|
|
const project = (p) => {
|
|
const clip = mul(
|
|
scene.camera.frustum.projectionMatrix,
|
|
mul(scene.camera.viewMatrix, [p.x, p.y, p.z, 1]),
|
|
);
|
|
return {
|
|
x: ((clip[0] / clip[3] + 1) * scene.canvas.clientWidth) / 2,
|
|
y: ((1 - clip[1] / clip[3]) * scene.canvas.clientHeight) / 2,
|
|
};
|
|
};
|
|
return [0, 1, 2, 3].map((i) => {
|
|
const entry = state._vehicles.get(`mbta:qa-${i}`);
|
|
const p = project(entry.marker.position);
|
|
return {
|
|
rotation: entry.marker.rotation,
|
|
course: entry.courseDeg,
|
|
moving: state._moving.has(entry),
|
|
visible: entry.marker.show,
|
|
x: p.x,
|
|
y: p.y,
|
|
};
|
|
});
|
|
});
|
|
await pose(0);
|
|
const before = await sample();
|
|
await pose(Math.PI / 2);
|
|
const after = await sample();
|
|
const deltaDeg = (a, b) =>
|
|
(Math.atan2(Math.sin(b - a), Math.cos(b - a)) * 180) / Math.PI;
|
|
for (const [i, label] of ['held course', 'reported bearing'].entries()) {
|
|
const delta = deltaDeg(before[i].rotation, after[i].rotation);
|
|
check(
|
|
`parked ${label} reprojects through a 90 degree camera orbit`,
|
|
before[i].visible &&
|
|
after[i].visible &&
|
|
!before[i].moving &&
|
|
!after[i].moving &&
|
|
Math.abs(delta - 90) <= 5,
|
|
JSON.stringify({ before: before[i], after: after[i], delta }),
|
|
);
|
|
}
|
|
check(
|
|
'unknown parked course remains screen-up',
|
|
before[2].rotation === 0 && after[2].rotation === 0,
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, 1200));
|
|
const moved = (await sample())[3];
|
|
const dx = moved.x - after[3].x,
|
|
dy = moved.y - after[3].y;
|
|
const travelRotation = Math.atan2(-dx, -dy);
|
|
const error = Math.abs(deltaDeg(travelRotation, moved.rotation));
|
|
check(
|
|
'moving vehicle still points along its rendered travel after orbit',
|
|
moved.visible && moved.moving && Math.hypot(dx, dy) > 0.5 && error <= 5,
|
|
JSON.stringify({
|
|
pixels: Math.hypot(dx, dy),
|
|
error,
|
|
after: after[3],
|
|
moved,
|
|
}),
|
|
);
|
|
check(
|
|
'heading regression has no scene render errors',
|
|
(await page.evaluate(() => window.__headingErrors)).length === 0,
|
|
);
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
}
|