Merge main (8d9c9071, #1750) into the renderer branch

Main brings satellites and vessels moving every frame, smooth rewind for
contacts, global clouds drawn to the level a feed names, and search for
degrees-minutes-seconds, UTM, MGRS and plus codes. They keep this branch's
renderer work: satellites write their reckoned positions into the points set
once a frame; vessels move every frame and ask for frames from the camera pose
and canvas, and a vessel not there yet is hidden through its icon; flights and
military keep the branch's rendering, with main's timeline fixes, trail top-up
and grounded lift; the cloud tiles keep their infrared transfer. The timeline
history module uses the geo helpers instead of Cesium, and main's new tests
use the draw port's items.
This commit is contained in:
Sameh Khamis committed 2026-11-15 11:00:24 -08:00
commit 4b47d5e058
49 files changed
+3367 -348

No files matched your search

+231 -4
View File
@@ -4,10 +4,11 @@ import { createVesselLayer } from './index.js';
import { VISIBILITY_UPDATE_MS } from './policy.js';
import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
import { layerPlacement } from '../../data/placementProvider.js';
import * as Cesium from 'cesium';
// Vessels move only when a poll lands, so the layer must let the scene idle:
// it asks for frames for forced passes and one trailing frame after the camera
// stops, and never schedules a frame from a pass the camera did not cause.
// The layer must let the scene idle: it asks for frames for forced passes,
// for vessels that move, and one trailing frame after the camera stops, and
// never schedules a frame from a pass nothing caused.
const noop = () => {};
@@ -78,7 +79,16 @@ function setup({ focusPassIsNeeded = () => false, placement = null } = {}) {
}
};
const frame = () => layer.testing._runVisibilityPassForTest();
return { layer, camera, requests, holds, timers, advance, frame };
return {
layer,
camera,
requests,
holds,
timers,
advance,
frame,
now: () => clock,
};
}
test('a parked camera schedules no frames after the cadence pass', () => {
@@ -117,6 +127,26 @@ test('a camera that stops inside the cadence gets exactly one trailing frame', (
assert.equal(timers.size, 0);
});
test('following the clock, a time moved inside the cadence gets one trailing frame', () => {
const { layer, requests, timers, advance, frame } = setup();
layer.testing._followClockForTest(1_000_000);
frame();
advance(100);
// A seek while paused: the camera is still, the time drawn is not.
layer.testing._followClockForTest(940_000);
frame();
assert.equal(timers.size, 1);
advance(VISIBILITY_UPDATE_MS);
assert.deepEqual(requests, ['ais-vessels-visibility']);
frame();
for (let i = 0; i < 20; i += 1) {
advance(100);
frame();
}
assert.deepEqual(requests, ['ais-vessels-visibility']);
assert.equal(timers.size, 0);
});
test('a forced pass requests its own frame', () => {
const { layer, requests } = setup();
layer.testing._runVisibilityPassForTest(true);
@@ -239,3 +269,200 @@ test('a placement that places nothing asks for no frames; one that places a draw
advance(1_000);
assert.deepEqual(requests, ['ais-vessels-placement']);
});
test('a vessel moving visibly asks for its next frame as soon as it moves half a pixel; a slow one once a second', (t) => {
let mono = 0;
t.mock.method(performance, 'now', () => mono);
const originalDocument = globalThis.document;
globalThis.document = { getElementById: () => null };
t.after(() => {
if (originalDocument === undefined) delete globalThis.document;
else globalThis.document = originalDocument;
});
let spot = { lat: 51.93, lon: 4.05 };
const { layer, camera, timers, advance, now } = setup({
placement: { layer: () => ({ place: () => spot }) },
});
// 20 km above the vessel, in a 1,000 px tall view about 57° tall.
camera.positionWC = Cesium.Cartesian3.fromDegrees(4.05, 51.93, 20_000);
camera.frustum = { fovy: 1 };
const record = { mmsi: '111', lat: 51.93, lon: 4.05 };
// Drawn: on the camera's side of the horizon.
const drawnVisual = (viewer) => {
bindFakeCesiumScene(viewer);
layer.testing._setVesselStateForTest({ viewer, records: [record] });
layer.testing._prepareVesselVisualForTest(record).visible = true;
};
drawnVisual({ camera, scene: {}, canvas: { clientHeight: 1000 } });
// How long after a pass the next frame is asked for, once the vessel moved
// `dLat` in the 16 ms since the pass before.
const waitAfterStep = (dLat) => {
layer.testing._runPlacementPassForTest();
advance(1_000); // whatever frame that asked for comes and goes
assert.equal(timers.size, 0);
mono += 16;
spot = { lat: spot.lat + dLat, lon: spot.lon };
layer.testing._runPlacementPassForTest();
assert.equal(timers.size, 1);
const [timer] = [...timers.values()];
return timer.at - now();
};
// About 11 m in a frame, 20 km away: over half a pixel, so the next frame
// is asked for within the frame.
assert.ok(waitAfterStep(0.0001) <= 16);
// About 1 cm in a frame: half a pixel takes seconds, so once a second.
assert.equal(waitAfterStep(0.0000001), 1000);
// A 2D view 40 km across in 1,000 px: 11 m is over a quarter pixel, so the
// next frame comes within two frames.
camera.frustum = new Cesium.OrthographicOffCenterFrustum({
left: -20_000,
right: 20_000,
bottom: -20_000,
top: 20_000,
near: 1,
far: 1e8,
});
camera.viewMatrix = Cesium.Matrix4.IDENTITY;
drawnVisual({ camera, scene: {}, canvas: { clientWidth: 1000 } });
assert.ok(waitAfterStep(0.0001) <= 32);
});
test('following the clock moves drawn vessels in place each world time, prepares missing ones and leaves hidden ones be', (t) => {
let mono = 0;
t.mock.method(performance, 'now', () => mono);
const originalDocument = globalThis.document;
globalThis.document = { getElementById: () => null };
t.after(() => {
if (originalDocument === undefined) delete globalThis.document;
else globalThis.document = originalDocument;
});
const { layer, camera, timers, advance } = setup();
camera.positionWC = Cesium.Cartesian3.fromDegrees(4.05, 51.93, 20_000);
camera.frustum = { fovy: 1 };
const motion = {
fromLat: 51.93,
fromLon: 4.05,
fromMs: 0,
toLat: 51.94,
toLon: 4.05,
toMs: 60_000,
};
const vessel = (mmsi) => ({
mmsi,
lat: 51.94,
lon: 4.05,
motion: { ...motion },
});
const drawn = vessel('111');
const hidden = vessel('222');
const owned = vessel('333');
const missing = vessel('444');
const viewer = { camera, scene: {}, canvas: { clientHeight: 1000 } };
bindFakeCesiumScene(viewer);
layer.testing._setVesselStateForTest({
viewer,
records: [drawn, hidden, owned, missing],
});
const visuals = [drawn, hidden, owned].map((record) =>
layer.testing._prepareVesselVisualForTest(record),
);
// Drawn as an icon (on the camera's side of the horizon), hidden, and
// drawn by its model.
visuals[0].visible = true;
visuals[1].visible = false;
visuals[2].visible = false;
visuals[2].modelOwnsVisual = true;
const before = visuals.map((visual) => ({ ...visual.position }));
const positions = visuals.map((visual) => visual.position);
// The first pass also moves hidden vessels, so the next stays within
// HIDDEN_FOLLOW_MS of it.
layer.testing._runClockPassForTest(10_000);
mono += 16;
layer.testing._runClockPassForTest(20_000);
assert.equal(visuals[0].position, positions[0], 'written in place');
assert.notDeepEqual({ ...visuals[0].position }, before[0]);
assert.notDeepEqual({ ...visuals[2].position }, before[2], 'model moves');
const hiddenAt = { ...visuals[1].position };
assert.ok(
layer.testing._vesselVisualForTest(missing).position,
'a missing visual is prepared',
);
assert.equal(timers.size, 1, 'moving vessels ask for a frame');
// The hidden vessel waits for HIDDEN_FOLLOW_MS.
mono += 16;
layer.testing._runClockPassForTest(30_000);
assert.deepEqual({ ...visuals[1].position }, hiddenAt);
mono += 250;
layer.testing._runClockPassForTest(40_000);
assert.notDeepEqual({ ...visuals[1].position }, hiddenAt);
// The same world time again moves nothing and asks for no frame.
advance(1_000);
assert.equal(timers.size, 0);
const still = { ...visuals[0].position };
mono += 16;
layer.testing._runClockPassForTest(40_000);
assert.deepEqual({ ...visuals[0].position }, still);
assert.equal(timers.size, 0);
// Scrubbed back, a vessel moves back.
mono += 16;
layer.testing._runClockPassForTest(20_000);
assert.notDeepEqual({ ...visuals[0].position }, still);
// Each vessel moves once per world time: new fixes at the same world time
// are drawn when the snapshot that brings them prepares the visual.
const backAt = { ...visuals[0].position };
drawn.motion = { ...motion, toLat: 52 };
mono += 16;
layer.testing._runClockPassForTest(20_000);
assert.deepEqual({ ...visuals[0].position }, backAt);
// Past the newest fix, vessels hold still and ask for nothing.
mono += 16;
layer.testing._runClockPassForTest(70_000);
advance(1_000);
mono += 16;
layer.testing._runClockPassForTest(80_000);
assert.equal(timers.size, 0);
});
test('following the clock, a vessel draws no icon before it was there, and draws it once the time comes', (t) => {
const originalDocument = globalThis.document;
globalThis.document = { getElementById: () => null };
t.after(() => {
if (originalDocument === undefined) delete globalThis.document;
else globalThis.document = originalDocument;
});
const { layer, camera } = setup();
const viewer = { camera, scene: {} };
const { draw } = bindFakeCesiumScene(viewer);
layer.testing._setVesselStateForTest({ viewer, icons: null });
const first = 1_000_000;
layer.testing._followClockForTest(first - 10 * 60_000);
layer.testing._reconcileVesselsForTest(viewer, [
{
mmsi: '111',
lat: 51.93,
lon: 4.05,
last_position_epoch: first / 1000,
fixes: [
{ atMs: first, lat: 51.93, lon: 4.05 },
{ atMs: first + 60_000, lat: 51.94, lon: 4.05 },
],
},
]);
const shown = () => {
const [set] = [...draw.sets.values()].filter(
(record) => record.kind === 'icons',
);
return set.items.get('111').show;
};
layer.testing._runVisibilityPassForTest(true);
assert.equal(shown(), false, 'ten minutes before its first fix');
layer.testing._followClockForTest(first - 30_000);
layer.testing._runVisibilityPassForTest(true);
assert.equal(shown(), true, 'half a minute before it: reaching it');
});