Test layers on one engine and share selection and shader helpers

Layer display tests no longer re-check Cesium primitives in every layer:
they run on the fake engine, and one Cesium translation check per ground
kind lives in the Cesium engine's ground tests. Their harnesses are shared,
and the fake-engine, Cesium-engine and flights tests that repeated the
contract suite are gone, 340 tests in all.

The press-travel measurement is shared by the selection dispatcher and
CCTV, which loses its ScreenSpaceEventHandler shim and world-click module.
ALPR, installations and bikeshare share one selection keeper and selected
marker write. Layers with their own click rules keep their handlers.

Navara's pulse is a class like the ground pass, the ground and imagery
passes share the surface uniforms, and the colour, log-depth and occlusion
GLSL lives in one chunk module, each caller keeping its depth bias. The
ground suite runs inside the contract suite (--only=ground:), and fixture
and script names say what they test.

Behaviour is unchanged on both engines.
This commit is contained in:
German Khokhlov committed 2026-11-08 17:06:10 +04:00
1 parent 7f478e3815
commit b4556f9763
101 files changed
+1095 -4071

No files matched your search

-2
View File
@@ -52,7 +52,6 @@ export const _viewRecordIdsForTest = layer._viewRecordIdsForTest;
export const clearProbeClampOnDeactivation =
layer.clearProbeClampOnDeactivation;
export const cctvRecordNeedsActivation = layer.cctvRecordNeedsActivation;
export const bindCctvWorldClickGesture = layer.bindCctvWorldClickGesture;
export const setActiveCamera = layer.setActiveCamera;
export const deactivateActiveCamera = layer.deactivateActiveCamera;
export const cctvEmptyClickDeselects = layer.cctvEmptyClickDeselects;
@@ -65,7 +64,6 @@ export const materializeCctvVisibleCoverageEntities =
export const _extractPickedCameraIdForTest =
layer._extractPickedCameraIdForTest;
export const _setCctvCoverageStateForTest = layer._setCctvCoverageStateForTest;
export const focusCctvRecord = layer.focusCctvRecord;
export const maybeAutoHop = layer.maybeAutoHop;
export const cctvCycleIndex = layer.cctvCycleIndex;
export {
+30 -31
View File
@@ -39,7 +39,6 @@ import cctvLayer, {
_pushAmbientCardEntriesForTest,
_setCctvOverlayHostForTest,
activationProbeClampRange,
bindCctvWorldClickGesture,
clearProbeClampOnDeactivation,
computeFrustumGeometry,
cctvCycleIndex,
@@ -60,7 +59,6 @@ import cctvLayer, {
createGeometryProgressNotifier,
normalizeCoverageMode,
frameSignatureFromPixels,
focusCctvRecord,
hideCctvRecordVisuals,
materializeCctvActiveCoverageEntities,
materializeCctvVisibleCoverageEntities,
@@ -85,30 +83,28 @@ import {
} from '../layers/cctv/policy.js';
import { loadLayerRenderers } from '../app/layers/renderers.js';
import { createNavigation } from '../layers/cctv/navigation.js';
import { createCctvDisplay } from '../layers/cctv/render/display.js';
function focusCctvRecord(engine, record, duration) {
const display = engine
? createCctvDisplay(engine, { services: {}, state: {} })
: null;
display?.attach();
try {
return createNavigation({}).focusCctvRecord(display, record, duration);
} finally {
display?.destroy();
}
}
// The layers draw with the manifest's displays, which load through
// import() (src/app/layers/renderers.js).
await loadLayerRenderers('cesium');
const ASPECT = 16 / 9;
const toRad = (deg) => (deg * Math.PI) / 180;
const GESTURE_TYPES = {
LEFT_DOWN: 'left-down',
MOUSE_MOVE: 'mouse-move',
LEFT_UP: 'left-up',
LEFT_CLICK: 'left-click',
};
function makeGestureHandler() {
const actions = new Map();
return {
setInputAction(callback, type) {
actions.set(type, callback);
},
fire(type, event) {
actions.get(type)?.(event);
},
};
}
// Same spherical earth radius projectPoint uses (R = 6371 km) so the
// lat/lon→metres conversion in the assertions matches the module's math.
const M_PER_DEG = (Math.PI / 180) * 6371000;
@@ -1383,14 +1379,16 @@ test('active CCTV camera is absent from host by default and protected only when
test('CCTV drag-then-release over a camera is inert, while a clean tap activates and dispatches', () => {
let timeMs = 0;
let activationCalls = 0;
const handler = makeGestureHandler();
const engine = createFakeEngine();
const display = createCctvDisplay(engine, { state: {} });
display.attach();
const handler = { fire: (type, event) => engine.fake.input(type, event) };
const target = new EventTarget();
const requests = [];
target.addEventListener(CCTV_FOCUS_REQUEST_EVENT, (event) =>
requests.push(event.detail),
);
bindCctvWorldClickGesture(
handler,
display.bindClick(
() => {
activateCctvCameraFromWorldClick(
'atx-cam-3',
@@ -1403,28 +1401,29 @@ test('CCTV drag-then-release over a camera is inert, while a clean tap activates
},
{
now: () => timeMs,
eventTypes: GESTURE_TYPES,
},
);
handler.fire(GESTURE_TYPES.LEFT_DOWN, { position: { x: 10, y: 10 } });
handler.fire('down', { position: { x: 10, y: 10 } });
timeMs = 20;
handler.fire(GESTURE_TYPES.MOUSE_MOVE, { endPosition: { x: 14, y: 10 } });
handler.fire('move', { endPosition: { x: 14, y: 10 } });
timeMs = 40;
handler.fire(GESTURE_TYPES.MOUSE_MOVE, { endPosition: { x: 10, y: 10 } });
handler.fire('move', { endPosition: { x: 10, y: 10 } });
timeMs = 60;
handler.fire(GESTURE_TYPES.LEFT_UP, { position: { x: 10, y: 10 } });
handler.fire(GESTURE_TYPES.LEFT_CLICK, { position: { x: 10, y: 10 } });
handler.fire('up', { position: { x: 10, y: 10 } });
handler.fire('click', { position: { x: 10, y: 10 } });
assert.equal(activationCalls, 0);
assert.deepEqual(requests, []);
timeMs = 100;
handler.fire(GESTURE_TYPES.LEFT_DOWN, { position: { x: 10, y: 10 } });
handler.fire('down', { position: { x: 10, y: 10 } });
timeMs = 180;
handler.fire(GESTURE_TYPES.LEFT_UP, { position: { x: 11, y: 11 } });
handler.fire(GESTURE_TYPES.LEFT_CLICK, { position: { x: 11, y: 11 } });
handler.fire('up', { position: { x: 11, y: 11 } });
handler.fire('click', { position: { x: 11, y: 11 } });
assert.equal(activationCalls, 1);
assert.deepEqual(requests, [{ cameraId: 'atx-cam-3' }]);
display.destroy();
engine.destroy();
});
test('CCTV auto-hop remains activation-only and never dispatches a focus request', () => {
+3 -8
View File
@@ -114,22 +114,17 @@ test('every scene click handler consults ownership before it picks', () => {
// find and edit each of these. If a layer grows a click handler it has to
// appear here too.
const guarded = [
['src/data/trackingClickGesture.js', 'onClick(click, gesture);'],
['src/data/trackingGesture.js', 'onClick(click, gesture);'],
[
'src/layers/infrastructure/render/display.js',
'const picked = event.picked;',
],
['src/data/cctvGizmo.js', 'pickGizmoPart(event)'],
// ALPR and bikeshare take the engine's click with its pick.
['src/layers/alpr/render/display.js', 'overlay.pick(position) ||'],
['src/layers/shared/selectionKeeper.js', 'const id = pickId(event);'],
['src/layers/bikeshare/render/display.js', 'const picked = event.picked;'],
// FIRMS takes the engine dispatcher's click with its pick.
['src/layers/firms/selection.js', 'const picked = click.picked;'],
// Mapped Installations take the engine's click with its pick.
[
'src/layers/installations/render/display.js',
"const id = typeof picked?.id === 'string' ? picked.id : null;",
],
['src/layers/launches/render/display.js', '[ctx.picked, ...ctx.drilled]'],
[
'src/layers/radio/interaction.js',
@@ -173,7 +168,7 @@ test('ambient selection handlers never claim the pointer themselves', () => {
// Claiming from a selection handler would deadlock every other layer the
// moment a user clicked anything. Only tools claim.
for (const file of [
'src/data/trackingClickGesture.js',
'src/data/trackingGesture.js',
'src/layers/infrastructure/render/display.js',
'src/data/cctvGizmo.js',
'src/layers/vessels/selection.js',
+14 -61
View File
@@ -1,34 +1,17 @@
import { sceneServicesFor } from './sceneServices.js';
// One selection dispatcher for the layers that draw through the globe
// engine: one click subscription with picks
// (engine.input.on('click', …, { pick: true, drill: 8 })), the press
// gesture and one Escape listener, instead of a ScreenSpaceEventHandler
// per layer. Owners register as with pickRegistry (registerPickOwner, so
// layers still on their own handlers keep seeing the ownership) plus
// handlers:
// onSelect(id, ctx) a click whose first pick it owns;
// onEmptyClick(ctx) a clean click (short, no drag) on the map or nothing;
// onEscape() Escape.
// The rules are the old handlers': a pick another layer owns is not empty
// space (a pick nobody owns is); `passThrough` picks (trails) never take the
// click, the next pick does; a `drillThrough` owner takes its object from
// under another layer's; a drag selects nothing; a pointer owned by a tool
// (inputOwnership) selects nothing. Layers not moved yet keep their own
// handlers: the dispatcher never acts on an id it does not own.
// A `lookUnder` owner (local ADS-B) keeps its own old click rule instead:
// its object on top, or under picks no layer owns and picks it looks under
// (`lookUnder(id)`: trails), is selected; another layer's object on top, or
// nothing, is empty space for it (it releases its selection); a click that
// only meets what it looks under does nothing; no gesture rule (its old
// handler took every click). To the others it is another layer.
// An own-rule owner (`onClick(ctx)`: vessels) keeps its whole old click
// handler: it gets every click with the top pick and decides itself (no
// gesture rule, as its old LEFT_CLICK handler); to the others it is another
// layer.
// Shared selection for registered owners, with one pick subscription and
// press accumulator. Normal owners select their first pick, clear on a short
// empty click, and retain selection on another owner's pick. Pass-through
// picks yield to the next hit; drill-through owners may select below an
// unregistered owner's hit. Pointer claims suppress selection.
// Look-under owners select below unowned picks or their declared pass-through
// ids, clear on other owners, and ignore clicks containing only those ids.
// Own-rule owners receive every pointer-free click and apply their own rules.
import { isPointerFree as pointerFree } from './inputOwnership.js';
import { pickRegistryFor, resolvePickId } from './pickRegistry.js';
import {
createPressGesture,
isTrackingClickGesture,
isTrackingSelectionGesture,
} from './trackingGesture.js';
@@ -58,27 +41,7 @@ export function createSelectionDispatcher(
let removers = [];
let destroyed = false;
// The press gesture, as bindTrackingClickGesture measures it.
let press = null;
let completed = null;
const travel = (position) => {
if (!press || !position) return;
if (press.last)
press.travelPx += Math.hypot(
position.x - press.last.x,
position.y - press.last.y,
);
press.last = { x: position.x, y: position.y };
};
const finish = (position) => {
if (!press) return;
travel(position);
completed = {
travelPx: press.travelPx,
durationMs: Math.max(0, now() - press.startedAt),
};
press = null;
};
const press = createPressGesture(now);
const ownerOf = (picked) => {
const id = resolvePickId(picked);
@@ -116,9 +79,7 @@ export function createSelectionDispatcher(
typeof owner.lookUnder !== 'function' && !ownRule(owner);
const onClick = (event) => {
if (press) finish(event.position);
const gesture = completed ?? { travelPx: 0, durationMs: 0 };
completed = null;
const gesture = press.click(event.position);
if (!isPointerFree()) return;
const picked = nearbyContact(
event.picked,
@@ -204,17 +165,9 @@ export function createSelectionDispatcher(
const attach = () => {
if (removers.length || destroyed) return;
removers = [
engine.input.on('down', (event) => {
press = {
startedAt: now(),
travelPx: 0,
last: null,
};
completed = null;
travel(event.position);
}),
engine.input.on('move', (event) => travel(event.endPosition)),
engine.input.on('up', (event) => finish(event.position)),
engine.input.on('down', (event) => press.down(event.position)),
engine.input.on('move', (event) => press.move(event.endPosition)),
engine.input.on('up', (event) => press.up(event.position)),
engine.input.on('click', onClick, { pick: true, drill: SELECTION_DRILL }),
];
keyTarget?.addEventListener?.('keydown', onKey);
-85
View File
@@ -1,85 +0,0 @@
import { trackingEventTypes } from '../globe/cesium/screenEvents.js';
import { isPointerFree } from './inputOwnership.js';
export {
MAX_TRACKING_CLICK_TRAVEL_PX,
MAX_TRACKING_CLICK_DURATION_MS,
isTrackingSelectionGesture,
isTrackingClickGesture,
} from './trackingGesture.js';
/**
* Bind LEFT_DOWN/MOUSE_MOVE/LEFT_UP accounting ahead of a scene click.
* Travel is accumulated segment-by-segment, so an orbit nudge that returns to
* its starting pixel cannot masquerade as a zero-distance click. Every scene
* click reaches `onClick` with its gesture metadata; the caller decides whether
* selection (travel-only) or deselection (travel + duration) is allowed.
* @param {Cesium.ScreenSpaceEventHandler|Object} handler - Input handler.
* @param {(click: Object, gesture: {travelPx: number, durationMs: number}) => void} onClick - Scene-click callback.
* @param {{now?: () => number, eventTypes?: Object, onMouseMove?: (event: Object) => void}} [options] - Test/interop seams.
* @returns {void}
*/
export function bindTrackingClickGesture(handler, onClick, options = {}) {
const now = options.now || (() => performance.now());
const eventTypes = options.eventTypes || trackingEventTypes();
let pressActive = false;
let pressStartedAt = 0;
let previousPosition = null;
let travelPx = 0;
let completedGesture = null;
const appendTravel = (position) => {
if (
!pressActive ||
!Number.isFinite(position?.x) ||
!Number.isFinite(position?.y)
)
return;
if (previousPosition) {
travelPx += Math.hypot(
position.x - previousPosition.x,
position.y - previousPosition.y,
);
}
previousPosition = { x: position.x, y: position.y };
};
const finishPress = (position) => {
if (!pressActive) return;
appendTravel(position);
completedGesture = {
travelPx,
durationMs: Math.max(0, now() - pressStartedAt),
};
pressActive = false;
previousPosition = null;
};
handler.setInputAction((event) => {
pressActive = true;
pressStartedAt = now();
previousPosition = null;
travelPx = 0;
completedGesture = null;
appendTravel(event?.position);
}, eventTypes.LEFT_DOWN);
handler.setInputAction((event) => {
appendTravel(event?.endPosition ?? event?.position);
options.onMouseMove?.(event);
}, eventTypes.MOUSE_MOVE);
handler.setInputAction((event) => {
finishPress(event?.position);
}, eventTypes.LEFT_UP);
handler.setInputAction((click) => {
if (pressActive) finishPress(click?.position);
const gesture = completedGesture || { travelPx: 0, durationMs: 0 };
completedGesture = null;
// A tool owns the pointer: a draw vertex placed over an aircraft is a
// vertex, not a track request (src/data/inputOwnership.js).
if (!isPointerFree()) return;
onClick(click, gesture);
}, eventTypes.LEFT_CLICK);
}
+6 -8
View File
@@ -6,21 +6,21 @@ import {
bindTrackingClickGesture,
isTrackingClickGesture,
isTrackingSelectionGesture,
} from './trackingClickGesture.js';
} from './trackingGesture.js';
import { TRACKED_MODEL_MAX_PX as CIVIL_TRACKED_MODEL_MAX_PX } from './flights.js';
import { TRACKED_MODEL_MAX_PX as MILITARY_TRACKED_MODEL_MAX_PX } from './militaryFlights.js';
const TYPES = {
LEFT_DOWN: 'left-down',
MOUSE_MOVE: 'mouse-move',
LEFT_UP: 'left-up',
LEFT_CLICK: 'left-click',
LEFT_DOWN: 'down',
MOUSE_MOVE: 'move',
LEFT_UP: 'up',
LEFT_CLICK: 'click',
};
function makeHandler() {
const actions = new Map();
return {
setInputAction(callback, type) { actions.set(type, callback); },
on(type, callback) { actions.set(type, callback); return () => actions.delete(type); },
fire(type, event) { actions.get(type)?.(event); },
};
}
@@ -49,7 +49,6 @@ test('synthetic drag-then-click sequence does not reach the untrack callback', (
if (isTrackingClickGesture(gesture)) untrackCalls += 1;
}, {
now: () => timeMs,
eventTypes: TYPES,
});
handler.fire(TYPES.LEFT_DOWN, { position: { x: 10, y: 10 } });
@@ -81,7 +80,6 @@ test('slow clean sprite clicks select, while long presses and orbit nudges canno
if (isTrackingClickGesture(gesture)) untracks += 1;
}, {
now: () => timeMs,
eventTypes: TYPES,
});
handler.fire(TYPES.LEFT_DOWN, { position: { x: 0, y: 0 } });
+69
View File
@@ -1,3 +1,5 @@
import { isPointerFree } from './inputOwnership.js';
export const MAX_TRACKING_CLICK_TRAVEL_PX = 6;
export const MAX_TRACKING_CLICK_DURATION_MS = 400;
@@ -30,3 +32,70 @@ export function isTrackingClickGesture(gesture = {}) {
durationMs <= MAX_TRACKING_CLICK_DURATION_MS
);
}
/** Accumulate press travel and duration, consuming the result on click. */
export function createPressGesture(now = () => performance.now()) {
let press = null;
let completed = null;
const travel = (position) => {
if (
!press ||
!Number.isFinite(position?.x) ||
!Number.isFinite(position?.y)
)
return;
if (press.last)
press.travelPx += Math.hypot(
position.x - press.last.x,
position.y - press.last.y,
);
press.last = { x: position.x, y: position.y };
};
const finish = (position) => {
if (!press) return;
travel(position);
completed = {
travelPx: press.travelPx,
durationMs: Math.max(0, now() - press.startedAt),
};
press = null;
};
return {
down(position) {
press = { startedAt: now(), travelPx: 0, last: null };
completed = null;
travel(position);
},
move: travel,
up: finish,
click(position) {
finish(position);
const gesture = completed ?? { travelPx: 0, durationMs: 0 };
completed = null;
return gesture;
},
};
}
/** Bind engine input with press metadata; the caller chooses its click rule. */
export function bindTrackingClickGesture(
input,
onClick,
{ now, onMouseMove } = {},
) {
const press = createPressGesture(now);
const removes = [
input.on('down', (event) => press.down(event?.position)),
input.on('move', (event) => {
press.move(event?.endPosition ?? event?.position);
onMouseMove?.(event);
}),
input.on('up', (event) => press.up(event?.position)),
input.on('click', (click) => {
const gesture = press.click(click?.position);
if (!isPointerFree()) return;
onClick(click, gesture);
}),
];
return () => removes.forEach((remove) => remove());
}