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

+11 -17
View File
@@ -17,7 +17,10 @@
import * as geo from '../../../geo/index.js';
import { GIZMO_ID_PREFIX } from '../../../data/cctvGizmo.js';
import { CAMERA_ICON, IDLE_CAMERA_COLOR } from '../policy.js';
import { bindCctvWorldClickGesture } from '../worldClick.js';
import {
bindTrackingClickGesture,
isTrackingClickGesture,
} from '../../../data/trackingGesture.js';
import { createCctvMeshes } from './meshes.js';
import {
COVERAGE_DASH,
@@ -40,13 +43,6 @@ import {
const GIZMO_POINT_SET_ID = `${GIZMO_ID_PREFIX}points`;
const GIZMO_POINT_CAPACITY = 16;
// The tracking click gesture's handler types, as engine.input types.
const CLICK_EVENT_TYPES = Object.freeze({
LEFT_DOWN: 'down',
MOUSE_MOVE: 'move',
LEFT_UP: 'up',
LEFT_CLICK: 'click',
});
const CORNERS = ['tl', 'tr', 'br', 'bl'];
const capRing = (p) => [p.tl, p.tr, p.br, p.bl, p.tl];
const sameDash = (a, b) =>
@@ -617,17 +613,15 @@ export function createCctvDisplay(engine, { state, services = {} } = {}) {
onMoveStart: (fn) =>
ownListener(engine.camera.moveStart.addEventListener(fn)),
bindClick(onClick, options = {}) {
const removes = [];
bindCctvWorldClickGesture(
{
setInputAction(fn, type) {
removes.push(engine.input.on(type, fn));
return ownListener(
bindTrackingClickGesture(
engine.input,
(click, gesture) => {
if (isTrackingClickGesture(gesture)) onClick(click);
},
},
onClick,
{ ...options, eventTypes: CLICK_EVENT_TYPES },
options,
),
);
return ownListener(() => removes.forEach((remove) => remove()));
},
createGizmoRenderer() {
const gizmo = createGizmoRenderer();
+8 -120
View File
@@ -1,14 +1,8 @@
// The CCTV display on the engine contract, on the fake engine and on the
// Cesium engine (Cesium's own collections, primitives and entities over a
// stub scene: they draw nothing but hold what the engine writes): the
// marker set and its batched writes, the coverage wedge lines and their
// styles, picks that need this layer's own objects, the monitor plane and
// its outline, the viewshed volume, the activation probe's ray, the world
// click, the credit, focus and teardown.
// Layer display behavior on the fake engine.
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import * as geo from '../../../geo/index.js';
import { viewshedColors } from '../../../data/cctvViewshed.js';
import { createFakeEngine } from '../../../globe/testing/fakeEngine.js';
@@ -90,30 +84,7 @@ for (const makeHarness of CCTV_HARNESSES) {
h.display.setMarkersVisible(false);
h.display.restoreOrder();
await h.settle();
if (h.cesium) {
const billboards = h.primitive('cctv');
const billboard = billboards.get(0);
assert.equal(billboard.width, 24);
assert.equal(billboard.height, 24);
assert.equal(
billboard.disableDepthTestDistance,
Number.POSITIVE_INFINITY,
);
assert.deepEqual(
[
billboard.scaleByDistance.near,
billboard.scaleByDistance.nearValue,
billboard.scaleByDistance.far,
billboard.scaleByDistance.farValue,
],
[350, 1.25, 4_000_000, 0.42],
);
assert.equal(billboard.id, 'a');
assert.equal(billboard.scale, 1.25);
near(billboard.color.alpha, ACTIVE_CAMERA_COLOR.alpha, 'alpha');
assert.equal(billboard.show, false);
assert.equal(billboards.get(1).show, false);
} else {
{
const set = h.engine.fake.moverSet('cctv');
assert.equal(set.options.order, 0, 'the bottom of the contact sprites');
assert.equal(set.options.depthTest, 'always');
@@ -178,14 +149,7 @@ for (const makeHarness of CCTV_HARNESSES) {
h.display.updateCoverage({ coverageEntities: lines }, moved);
assert.deepEqual(lines[0].polyline.positions, [moved.mount, moved.tl]);
assert.equal(lines[4].polyline.positions[0], moved.tl);
if (h.cesium) {
const drawn = h.primitive('cctv-a-cap');
assert.equal(
drawn.geometryInstances.geometry._arcType,
Cesium.ArcType.GEODESIC,
);
assert.equal(drawn.geometryInstances.geometry._width, 1.2);
} else {
{
const line = h.lineState('cctv-a-cap');
assert.equal(line.widthPx, 1.2);
assert.equal(line.arc, 'geodesic');
@@ -213,21 +177,7 @@ for (const makeHarness of CCTV_HARNESSES) {
dashed: true,
depthFail: hue.line.withAlpha(0.18),
});
if (h.cesium) {
const drawn = h.primitive(edge.id);
assert.equal(drawn.appearance.material.type, 'PolylineDash');
near(
drawn.appearance.material.uniforms.color.alpha,
hue.lineActive.alpha,
'line alpha',
);
near(
drawn.depthFailAppearance.material.uniforms.color.alpha,
0.18,
'depth-fail alpha',
);
assert.equal(drawn.geometryInstances.geometry._width, 1.8);
} else {
{
const line = h.lineState(edge.id);
assert.deepEqual(line.dash, { kind: 'pixels', lengthPx: 8, gapPx: 8 });
assert.equal(line.widthPx, 1.8);
@@ -237,12 +187,7 @@ for (const makeHarness of CCTV_HARNESSES) {
style(cap, { visible: false, width: 1, tint: IDLE_COVERAGE_CENTER_MUTED });
assert.equal(cap.show, false);
style(edge, { width: 0.9, tint: IDLE_COVERAGE_EDGE_MUTED });
if (h.cesium) {
const drawn = h.primitive(edge.id);
assert.equal(drawn.appearance.material.type, 'Color');
assert.equal(drawn.depthFailAppearance, undefined);
assert.equal(drawn.geometryInstances.geometry._width, 0.9);
} else {
{
const line = h.lineState(edge.id);
assert.equal(line.dash, null);
assert.equal(line.depthFailAlpha, 0);
@@ -354,23 +299,7 @@ for (const makeHarness of CCTV_HARNESSES) {
);
near(geo.cartesian3.distance(corners[index], expected), 0, 'corner');
}
if (h.cesium) {
const primitive = h.primitive('cctv-a-plane');
assert.equal(primitive.show, true);
assert.equal(primitive.appearance.material.uniforms.color.alpha, 0.95);
assert.equal(primitive.allowPicking, true);
h.scriptPicks({ native: { id: 'cctv-a-plane', primitive } });
assert.equal(
h.display.extractPickedCameraId(h.display.pick({ x: 1, y: 1 })),
null,
'a plane no record owns is not a camera',
);
record.projection = runtime;
assert.equal(
h.display.extractPickedCameraId(h.display.pick({ x: 1, y: 1 })),
'a',
);
} else {
{
const outline = h.lineState('cctv-a-plane-outline');
assert.equal(outline.widthPx, 1);
assert.equal(outline.pickId, 'cctv-a-plane');
@@ -394,7 +323,6 @@ for (const makeHarness of CCTV_HARNESSES) {
h.display.removePlane(runtime);
assert.equal(material.disposed, true);
assert.equal(h.engine.lines.list().length, 0);
if (h.cesium) assert.equal(h.viewer.entities.values.length, 0);
});
test(`the viewshed volume and the activation probe's ray (${name})`, (t) => {
@@ -422,37 +350,7 @@ for (const makeHarness of CCTV_HARNESSES) {
);
assert.equal(excludeObjects.length, 6);
const direction = p(0, 1, 0);
if (h.cesium) {
const primitive = h.primitive(volume.mesh.id);
assert.equal(primitive.allowPicking, false);
assert.equal(primitive.asynchronous, false);
assert.ok(primitive);
let query;
h.viewer.scene.pickFromRay = (ray, exclusions) => {
query = { ray, exclusions };
return {
position: Cesium.Cartesian3.add(
ray.origin,
new Cesium.Cartesian3(0, 20, 0),
new Cesium.Cartesian3(),
),
};
};
const exclude = [...record.coverageEntities, volume];
assert.equal(
h.display.obstructionRay(POSITIONS.mount, direction, exclude, 10),
undefined,
'a hit past the range is no obstruction',
);
assert.ok(
h.display.obstructionRay(POSITIONS.mount, direction, exclude, 30),
);
assert.ok(query.ray instanceof Cesium.Ray);
assert.equal(primitive.show, true, 'the excluded volume is restored');
assert.ok(query.exclusions.every((item) => typeof item !== 'string'));
h.display.removeVolume(volume);
assert.equal(h.primitive(volume.mesh.id), undefined);
} else {
{
assert.equal(
h.display.obstructionRay(POSITIONS.mount, direction, [], 30),
undefined,
@@ -558,16 +456,6 @@ for (const makeHarness of CCTV_HARNESSES) {
assert.deepEqual(credits.at(-1), ['hide', h.engine, 'cctv']);
assert.equal(h.engine.lines.list().length, 0);
assert.equal(h.engine.movers.list().length, 0);
if (h.cesium) {
assert.equal(h.viewer.entities.values.length, 0);
const drawn = [];
for (let i = 0; i < h.viewer.scene.primitives.length; i++)
drawn.push(h.viewer.scene.primitives.get(i));
assert.ok(
drawn.every((primitive) => !(primitive instanceof Cesium.Primitive)),
'the volume is gone',
);
}
});
}
+3 -41
View File
@@ -1,7 +1,4 @@
// The CCTV calibration gizmo drawn by the display, on the fake engine and
// on the Cesium engine: drags through engine.input that patch only the
// pinned record and hand the camera back, picks that need the gizmo's own
// handles, the handles' geometry, hover sizes, cancellation and teardown.
// Layer display behavior on the fake engine.
import test from 'node:test';
import assert from 'node:assert/strict';
@@ -185,40 +182,7 @@ for (const makeHarness of CCTV_HARNESSES) {
{ id: points.id, kind: points.kind, count: points.count },
{ id: 'cctv-gizmo-points', kind: 'point', count: 6 },
);
if (h.cesium) {
const ring = h.primitive('cctv-gizmo-ring-heading');
const first = ring.geometryInstances.geometry._positions[0];
assert.ok(
Math.abs(
geo.cartesian3.distance(first, h.record.frustumPositions.mount) - 12,
) < 1e-6,
);
const east = h.primitive('cctv-gizmo-move-east');
assert.equal(east.geometryInstances.geometry._width, 12);
assert.equal(east.appearance.material.type, 'PolylineArrow');
assert.ok(
Math.abs(
east.depthFailAppearance.material.uniforms.color.alpha - 0.45,
) < 1e-6,
);
const heading = h.primitive('cctv-gizmo-ring-heading');
assert.ok(
Math.abs(heading.appearance.material.uniforms.color.alpha - 0.9) < 1e-6,
);
assert.ok(
Math.abs(
heading.depthFailAppearance.material.uniforms.color.alpha - 0.45,
) < 1e-6,
);
const tips = h.primitive('cctv-gizmo-points');
const tip = tips.get(0);
near(tip.pixelSize, 14, 'tip size');
assert.equal(tip.outlineWidth, 2);
assert.ok(Math.abs(tip.outlineColor.alpha - 0.7) < 1e-6);
assert.equal(tip.disableDepthTestDistance, Number.POSITIVE_INFINITY);
assert.ok(Math.abs(tip.position.y - 19.2) < 1e-6);
near(tips.get(3).pixelSize, 13, 'range handle size');
} else {
{
const ring = h.engine.fake.line('cctv-gizmo-ring-heading');
assert.ok(
Math.abs(
@@ -262,9 +226,7 @@ for (const makeHarness of CCTV_HARNESSES) {
h.event('move');
assert.equal(h.canvas.style.cursor, 'grab');
const size = (index) =>
h.cesium
? h.primitive('cctv-gizmo-points').get(index).pixelSize
: h.engine.fake.moverSet('cctv-gizmo-points').store.scales[index] * 10;
h.engine.fake.moverSet('cctv-gizmo-points').store.scales[index] * 10;
near(size(3), 17, 'the hovered range handle');
near(size(0), 10, 'an arrow tip takes the handle size');
near(size(4), 10, 'a field-of-view handle');
+5 -17
View File
@@ -18,12 +18,7 @@ const positions = {
};
const identity = { x: 0, y: 0, z: 0, w: 1 };
import { createCesiumMoversEngine } from '../../../testSupport/cesiumMoversEngine.mjs';
for (const [name, make] of [
['fake', () => ({ engine: createFakeEngine() })],
['Cesium', createCesiumMoversEngine],
]) {
for (const [name, make] of [['fake', () => ({ engine: createFakeEngine() })]]) {
test(`CCTV mesh ownership, live image and geometry updates (${name})`, (t) => {
const h = make();
t.after(() => h.engine.destroy());
@@ -42,7 +37,7 @@ for (const [name, make] of [
assert.equal(meshes.planeFromPick({ id: plane.id }), null);
assert.equal(meshes.drawnBy(plane), plane.mesh);
assert.equal(meshes.drawnBy(volume), volume.mesh);
const image = new HTMLCanvasElement();
const image = {};
image.width = image.height = 8;
material.setImage(image);
const moved = {
@@ -50,16 +45,9 @@ for (const [name, make] of [
capCenter: { ...positions.capCenter, x: positions.capCenter.x + 3 },
};
meshes.updatePlane(plane, shape, moved, identity);
const state = h.engine.fake?.mesh(plane.id);
const primitive = h.primitive?.(plane.id);
const flat =
state?.positions ??
primitive.geometryInstances.geometry.attributes.position.values;
assert.equal(flat[0], moved.capCenter.x - shape.halfW);
assert.equal(
state?.image ?? primitive.appearance.material.uniforms.image,
image,
);
const state = h.engine.fake.mesh(plane.id);
assert.equal(state.positions[0], moved.capCenter.x - shape.halfW);
assert.equal(state.image, image);
assert.throws(
() => meshes.createPlane('b', {}, shape, positions, identity),
/not owned/,
-19
View File
@@ -1,19 +0,0 @@
// The CCTV world click: a tracking click over engine.input, shared by the
// display (render/display.js) and the application layer.
import {
bindTrackingClickGesture,
isTrackingClickGesture,
} from '../../data/trackingClickGesture.js';
/** The tracking click gesture over engine.input (the CCTV world click). */
export function bindCctvWorldClickGesture(handler, onClick, options = {}) {
bindTrackingClickGesture(
handler,
(click, gesture) => {
if (!isTrackingClickGesture(gesture)) return;
onClick(click);
},
options,
);
}