mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Draw nine layers' fills through engine.ground, one display each
Earthquakes, air quality, GNSS Integrity, fire perimeters, Prohibited & Restricted Airspace, Active Fires, S2 GhostMaps, cyclone advisories and submarine cables each have one render/display.js on the globe contract; their render/cesium* and render/navara* files go. Their discs, cells, polygons and corridors are engine.ground sets, so on Navara they come from the one ground screen pass with exact colours instead of nine hand-written classification passes and lit SDK vector layers. Cesium's look stays the reference: - Earthquake and air-quality discs have no outline (Cesium drew none on clamped ellipses); earthquake discs can now be picked on Navara too. - Perimeters, drone zones and GhostMaps polygons outline their outer ring only, as Cesium did. - GNSS cells stay out of the pick pass; cyclone cones, tracks and centres are culled by a port of Cesium's horizon occluder. - Submarine cables are one ground corridor set, as Cesium batched them; landing points, tips and stems are movers and lines. - FIRMS glows are a sprite set and its cells a ground set. The far-zoom heat raster, which no primitive draws yet, sits behind one seam, render/heatField.js, with a Cesium and a Navara backend. The shared Navara ground helpers that only these layers used go (navaraGroundCells, the cell and ground geometry, the zone renderers), as does the ground prototype script. Coupling: layer renderer lines fall from 1636/6953 to 1011/4832 (Cesium/Navara), Navara ground passes from 7 to 5, Cesium-importing files from 65 to 53, engine.extensions reads from 26 to 19.
This commit is contained in:
1 parent
974a0b6361
commit
54fe0aea40
124 files changed
+8407
-9576
No files matched your search
+417
-143
@@ -7,14 +7,22 @@ import {
|
||||
fireCullPosition,
|
||||
} from './firmsHeatmap.js';
|
||||
import { FIRE_ANCHOR_LIFT_M } from './fireAnchors.js';
|
||||
import { FIRMS_AMBIENT_COHORT_LIMIT, FIRMS_OVERLAY_SOURCE_ID } from './firmsLabels.js';
|
||||
import {
|
||||
FIRMS_AMBIENT_COHORT_LIMIT,
|
||||
FIRMS_OVERLAY_SOURCE_ID,
|
||||
} from './firmsLabels.js';
|
||||
import {
|
||||
_clearMeshFloorCellsForTest,
|
||||
reportMeshFloorCell,
|
||||
setMeshFloorPreferred,
|
||||
} from './groundFloor.js';
|
||||
import { unregisterSpriteCollection } from './spriteOrder.js';
|
||||
import { isOverlayPointVisible, normalizeOverlayEntry } from '../overlays/worldOverlay.js';
|
||||
import { createCesiumMoversEngine } from '../testSupport/cesiumMoversEngine.mjs';
|
||||
import { createFakeEventHandlers } from '../globe/cesium/testing/fakeViewer.mjs';
|
||||
import { createFirmsDisplay } from '../layers/firms/render/display.js';
|
||||
import {
|
||||
isOverlayPointVisible,
|
||||
normalizeOverlayEntry,
|
||||
} from '../overlays/worldOverlay.js';
|
||||
|
||||
const AUSTIN = { lon: -97.7, lat: 30.2 };
|
||||
/** Antipode of Austin — as far behind the limb as a point on Earth can be. */
|
||||
@@ -38,8 +46,13 @@ function billboard(position, show = true) {
|
||||
position,
|
||||
_show: show,
|
||||
writes: 0,
|
||||
get show() { return this._show; },
|
||||
set show(value) { this._show = value; this.writes += 1; },
|
||||
get show() {
|
||||
return this._show;
|
||||
},
|
||||
set show(value) {
|
||||
this._show = value;
|
||||
this.writes += 1;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,17 +75,36 @@ function occluderOverAustin(heightM) {
|
||||
|
||||
test('applyHorizonCull: far-side fires are hidden, near-side fires stay visible', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const near = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0));
|
||||
const nearby = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon + 6, AUSTIN.lat + 4, 0));
|
||||
const far = billboard(Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0));
|
||||
const otherSide = billboard(Cesium.Cartesian3.fromDegrees(TOKYO.lon, TOKYO.lat, 0));
|
||||
const near = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
);
|
||||
const nearby = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon + 6, AUSTIN.lat + 4, 0),
|
||||
);
|
||||
const far = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0),
|
||||
);
|
||||
const otherSide = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(TOKYO.lon, TOKYO.lat, 0),
|
||||
);
|
||||
|
||||
const visible = applyHorizonCull(collection([near, nearby, far, otherSide]), occluder);
|
||||
const visible = applyHorizonCull(
|
||||
collection([near, nearby, far, otherSide]),
|
||||
occluder,
|
||||
);
|
||||
|
||||
assert.equal(near.show, true, 'the fire under the camera renders');
|
||||
assert.equal(nearby.show, true, 'a fire well inside the horizon renders');
|
||||
assert.equal(far.show, false, 'the antipodal fire must not shine through the planet');
|
||||
assert.equal(otherSide.show, false, 'Tokyo is beyond the limb from Austin at 1.5 Mm');
|
||||
assert.equal(
|
||||
far.show,
|
||||
false,
|
||||
'the antipodal fire must not shine through the planet',
|
||||
);
|
||||
assert.equal(
|
||||
otherSide.show,
|
||||
false,
|
||||
'Tokyo is beyond the limb from Austin at 1.5 Mm',
|
||||
);
|
||||
assert.equal(visible, 2, 'returns the surviving count');
|
||||
});
|
||||
|
||||
@@ -81,15 +113,26 @@ test('applyHorizonCull: raising the camera reveals fires the low camera hid', ()
|
||||
|
||||
const low = paris();
|
||||
applyHorizonCull(collection([low]), occluderOverAustin(REPRO_HEIGHT_M));
|
||||
assert.equal(low.show, false, 'Paris is over the horizon from a 1.5 Mm Austin camera');
|
||||
assert.equal(
|
||||
low.show,
|
||||
false,
|
||||
'Paris is over the horizon from a 1.5 Mm Austin camera',
|
||||
);
|
||||
|
||||
const high = paris();
|
||||
applyHorizonCull(collection([high]), occluderOverAustin(35_000_000));
|
||||
assert.equal(high.show, true, 'from geostationary height the same fire is in view');
|
||||
assert.equal(
|
||||
high.show,
|
||||
true,
|
||||
'from geostationary height the same fire is in view',
|
||||
);
|
||||
});
|
||||
|
||||
test('applyHorizonCull: a hidden fire is restored when it swings back into view', () => {
|
||||
const revealed = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0), false);
|
||||
const revealed = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
false,
|
||||
);
|
||||
applyHorizonCull(collection([revealed]), occluderOverAustin(REPRO_HEIGHT_M));
|
||||
assert.equal(revealed.show, true, 'the cull un-hides as well as hides');
|
||||
assert.equal(revealed.writes, 1);
|
||||
@@ -97,25 +140,56 @@ test('applyHorizonCull: a hidden fire is restored when it swings back into view'
|
||||
|
||||
test('applyHorizonCull: only flipped billboards are written (vertex-buffer churn)', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const stays = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0), true);
|
||||
const flips = billboard(Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0), true);
|
||||
const stays = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
true,
|
||||
);
|
||||
const flips = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0),
|
||||
true,
|
||||
);
|
||||
|
||||
applyHorizonCull(collection([stays, flips]), occluder);
|
||||
applyHorizonCull(collection([stays, flips]), occluder);
|
||||
|
||||
assert.equal(stays.writes, 0, 'an already-visible billboard is never re-assigned');
|
||||
assert.equal(flips.writes, 1, 'a hidden billboard is written once, not once per pass');
|
||||
assert.equal(
|
||||
stays.writes,
|
||||
0,
|
||||
'an already-visible billboard is never re-assigned',
|
||||
);
|
||||
assert.equal(
|
||||
flips.writes,
|
||||
1,
|
||||
'a hidden billboard is written once, not once per pass',
|
||||
);
|
||||
});
|
||||
|
||||
test('applyHorizonCull: missing collection/occluder/holes are no-ops, not throws', () => {
|
||||
assert.equal(applyHorizonCull(null, occluderOverAustin(REPRO_HEIGHT_M)), 0);
|
||||
assert.equal(applyHorizonCull({ length: 3 }, occluderOverAustin(REPRO_HEIGHT_M)), 0, 'non-collection shape');
|
||||
const item = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0));
|
||||
assert.equal(applyHorizonCull(collection([item]), null), 0, 'no occluder → leave the layer alone');
|
||||
assert.equal(applyHorizonCull(collection([item]), {}), 0, 'occluder without isPointVisible');
|
||||
assert.equal(
|
||||
applyHorizonCull({ length: 3 }, occluderOverAustin(REPRO_HEIGHT_M)),
|
||||
0,
|
||||
'non-collection shape',
|
||||
);
|
||||
const item = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
);
|
||||
assert.equal(
|
||||
applyHorizonCull(collection([item]), null),
|
||||
0,
|
||||
'no occluder → leave the layer alone',
|
||||
);
|
||||
assert.equal(
|
||||
applyHorizonCull(collection([item]), {}),
|
||||
0,
|
||||
'occluder without isPointVisible',
|
||||
);
|
||||
assert.equal(item.writes, 0, 'a skipped pass must not touch show');
|
||||
assert.equal(
|
||||
applyHorizonCull(collection([undefined, item]), occluderOverAustin(REPRO_HEIGHT_M)),
|
||||
applyHorizonCull(
|
||||
collection([undefined, item]),
|
||||
occluderOverAustin(REPRO_HEIGHT_M),
|
||||
),
|
||||
1,
|
||||
'sparse slots are skipped, surviving neighbours still counted',
|
||||
);
|
||||
@@ -127,22 +201,42 @@ test('applyHorizonCull: missing collection/occluder/holes are no-ops, not throws
|
||||
|
||||
test('applyHorizonCull: an index-aligned cull position overrides the render anchor', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const sunken = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, -22));
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, 12);
|
||||
const sunken = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, -22),
|
||||
);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(
|
||||
AUSTIN.lon + LIMB_DLON,
|
||||
AUSTIN.lat,
|
||||
12,
|
||||
);
|
||||
|
||||
applyHorizonCull(collection([sunken]), occluder);
|
||||
assert.equal(sunken.show, false, 'baseline: the raw sub-ellipsoid anchor false-hides at the limb');
|
||||
assert.equal(
|
||||
sunken.show,
|
||||
false,
|
||||
'baseline: the raw sub-ellipsoid anchor false-hides at the limb',
|
||||
);
|
||||
|
||||
applyHorizonCull(collection([sunken]), occluder, [lifted]);
|
||||
assert.equal(sunken.show, true, 'the lifted cull point keeps the near-limb fire on screen');
|
||||
assert.equal(
|
||||
sunken.show,
|
||||
true,
|
||||
'the lifted cull point keeps the near-limb fire on screen',
|
||||
);
|
||||
});
|
||||
|
||||
test('applyHorizonCull: a lifted cull point does NOT resurrect a genuinely far-side fire', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const far = billboard(Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, -22));
|
||||
const far = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, -22),
|
||||
);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 12);
|
||||
applyHorizonCull(collection([far]), occluder, [lifted]);
|
||||
assert.equal(far.show, false, '12 m of lift must not defeat the actual horizon cull');
|
||||
assert.equal(
|
||||
far.show,
|
||||
false,
|
||||
'12 m of lift must not defeat the actual horizon cull',
|
||||
);
|
||||
});
|
||||
|
||||
test('fireCullPosition: negative-geoid anchor renders at the datum but culls lifted', () => {
|
||||
@@ -160,15 +254,34 @@ test('fireCullPosition: negative-geoid anchor renders at the datum but culls lif
|
||||
`render anchor stays datum-correct at ${-27 + FIRE_ANCHOR_LIFT_M} m, got ${renderCarto.height}`,
|
||||
);
|
||||
|
||||
assert.notEqual(cull, render, 'a sub-ellipsoid anchor gets a separate cull point');
|
||||
assert.notEqual(
|
||||
cull,
|
||||
render,
|
||||
'a sub-ellipsoid anchor gets a separate cull point',
|
||||
);
|
||||
const cullCarto = Cesium.Cartographic.fromCartesian(cull);
|
||||
assert.ok(Math.abs(cullCarto.height - 12) < 0.5, `cull point lifted to 12 m, got ${cullCarto.height}`);
|
||||
assert.equal(fireCullPosition(fire), cull, 'the lifted point is cached, not re-allocated per call');
|
||||
assert.ok(
|
||||
Math.abs(cullCarto.height - 12) < 0.5,
|
||||
`cull point lifted to 12 m, got ${cullCarto.height}`,
|
||||
);
|
||||
assert.equal(
|
||||
fireCullPosition(fire),
|
||||
cull,
|
||||
'the lifted point is cached, not re-allocated per call',
|
||||
);
|
||||
|
||||
// The whole point: the datum-correct point would be culled here, the lifted one is not.
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
assert.equal(occluder.isPointVisible(render), false, 'baseline defect: −22 m reads beyond the horizon');
|
||||
assert.equal(occluder.isPointVisible(cull), true, 'lifted cull point reads correctly as in view');
|
||||
assert.equal(
|
||||
occluder.isPointVisible(render),
|
||||
false,
|
||||
'baseline defect: −22 m reads beyond the horizon',
|
||||
);
|
||||
assert.equal(
|
||||
occluder.isPointVisible(cull),
|
||||
true,
|
||||
'lifted cull point reads correctly as in view',
|
||||
);
|
||||
} finally {
|
||||
_clearMeshFloorCellsForTest();
|
||||
setMeshFloorPreferred(false);
|
||||
@@ -183,7 +296,11 @@ test('fireCullPosition: a healthy above-ellipsoid anchor is its own cull point',
|
||||
try {
|
||||
const fire = { index: 2, lat, lon, frp: 10, position: null };
|
||||
const cull = fireCullPosition(fire);
|
||||
assert.equal(cull, fire.position, 'no second Cartesian is allocated for the common case');
|
||||
assert.equal(
|
||||
cull,
|
||||
fire.position,
|
||||
'no second Cartesian is allocated for the common case',
|
||||
);
|
||||
} finally {
|
||||
_clearMeshFloorCellsForTest();
|
||||
setMeshFloorPreferred(false);
|
||||
@@ -197,23 +314,50 @@ test('fireCullPosition: a healthy above-ellipsoid anchor is its own cull point',
|
||||
test('isOverlayPointVisible: horizon test prefers entry.cullPosition when present', () => {
|
||||
const viewport = { width: 800, height: 600 };
|
||||
const screen = { x: 400, y: 300 };
|
||||
const render = Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, -22);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, 12);
|
||||
const render = Cesium.Cartesian3.fromDegrees(
|
||||
AUSTIN.lon + LIMB_DLON,
|
||||
AUSTIN.lat,
|
||||
-22,
|
||||
);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(
|
||||
AUSTIN.lon + LIMB_DLON,
|
||||
AUSTIN.lat,
|
||||
12,
|
||||
);
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
|
||||
assert.equal(
|
||||
isOverlayPointVisible({ horizonCull: true }, render, screen, viewport, occluder),
|
||||
isOverlayPointVisible(
|
||||
{ horizonCull: true },
|
||||
render,
|
||||
screen,
|
||||
viewport,
|
||||
occluder,
|
||||
),
|
||||
false,
|
||||
'baseline: the render anchor alone false-hides the card',
|
||||
);
|
||||
assert.equal(
|
||||
isOverlayPointVisible({ horizonCull: true, cullPosition: lifted }, render, screen, viewport, occluder),
|
||||
isOverlayPointVisible(
|
||||
{ horizonCull: true, cullPosition: lifted },
|
||||
render,
|
||||
screen,
|
||||
viewport,
|
||||
occluder,
|
||||
),
|
||||
true,
|
||||
'the supplied cull position is what the horizon test uses',
|
||||
);
|
||||
assert.equal(
|
||||
isOverlayPointVisible(
|
||||
{ horizonCull: true, cullPosition: Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 12) },
|
||||
{
|
||||
horizonCull: true,
|
||||
cullPosition: Cesium.Cartesian3.fromDegrees(
|
||||
ANTIPODE.lon,
|
||||
ANTIPODE.lat,
|
||||
12,
|
||||
),
|
||||
},
|
||||
render,
|
||||
screen,
|
||||
viewport,
|
||||
@@ -227,37 +371,80 @@ test('isOverlayPointVisible: horizon test prefers entry.cullPosition when presen
|
||||
test('normalizeOverlayEntry: carries a valid cullPosition, nulls a junk one', () => {
|
||||
const position = { x: 1, y: 2, z: 3 };
|
||||
const source = { x: 4, y: 5, z: 6 };
|
||||
const kept = normalizeOverlayEntry('firms', { id: 'a', position, cullPosition: source });
|
||||
assert.notEqual(kept.cullPosition, source, 'stored as a host-owned copy (a geo Cartesian3)');
|
||||
assert.ok(!(kept.cullPosition instanceof Cesium.Cartesian3), 'not a Cesium value');
|
||||
const kept = normalizeOverlayEntry('firms', {
|
||||
id: 'a',
|
||||
position,
|
||||
cullPosition: source,
|
||||
});
|
||||
assert.notEqual(
|
||||
kept.cullPosition,
|
||||
source,
|
||||
'stored as a host-owned copy (a geo Cartesian3)',
|
||||
);
|
||||
assert.ok(
|
||||
!(kept.cullPosition instanceof Cesium.Cartesian3),
|
||||
'not a Cesium value',
|
||||
);
|
||||
assert.deepEqual(
|
||||
[kept.cullPosition.x, kept.cullPosition.y, kept.cullPosition.z],
|
||||
[4, 5, 6],
|
||||
);
|
||||
const dropped = normalizeOverlayEntry('firms', { id: 'b', position, cullPosition: { x: NaN, y: 5, z: 6 } });
|
||||
assert.equal(dropped.cullPosition, null, 'a malformed cull point falls back to the render position');
|
||||
const notAnObject = normalizeOverlayEntry('firms', { id: 'b2', position, cullPosition: 42 });
|
||||
assert.equal(notAnObject.cullPosition, null, 'a non-object cull point is rejected');
|
||||
const dropped = normalizeOverlayEntry('firms', {
|
||||
id: 'b',
|
||||
position,
|
||||
cullPosition: { x: NaN, y: 5, z: 6 },
|
||||
});
|
||||
assert.equal(
|
||||
dropped.cullPosition,
|
||||
null,
|
||||
'a malformed cull point falls back to the render position',
|
||||
);
|
||||
const notAnObject = normalizeOverlayEntry('firms', {
|
||||
id: 'b2',
|
||||
position,
|
||||
cullPosition: 42,
|
||||
});
|
||||
assert.equal(
|
||||
notAnObject.cullPosition,
|
||||
null,
|
||||
'a non-object cull point is rejected',
|
||||
);
|
||||
// Non-adopting sources keep their existing BEHAVIOUR and steady-frame
|
||||
// allocation profile; the normalized record does gain an enumerable
|
||||
// `cullPosition: null` field, which is why this asserts null rather than
|
||||
// absence.
|
||||
const absent = normalizeOverlayEntry('firms', { id: 'c', position });
|
||||
assert.equal(absent.cullPosition, null, 'sources that do not opt in resolve to no cull anchor');
|
||||
assert.equal(
|
||||
absent.cullPosition,
|
||||
null,
|
||||
'sources that do not opt in resolve to no cull anchor',
|
||||
);
|
||||
});
|
||||
|
||||
test('normalizeOverlayEntry: the stored cull anchor is a snapshot, not the caller object', () => {
|
||||
const position = { x: 1, y: 2, z: 3 };
|
||||
const caller = new Cesium.Cartesian3(4, 5, 6);
|
||||
const normalized = normalizeOverlayEntry('firms', { id: 'a', position, cullPosition: caller });
|
||||
assert.notEqual(normalized.cullPosition, caller, 'the host must not retain the caller reference');
|
||||
const normalized = normalizeOverlayEntry('firms', {
|
||||
id: 'a',
|
||||
position,
|
||||
cullPosition: caller,
|
||||
});
|
||||
assert.notEqual(
|
||||
normalized.cullPosition,
|
||||
caller,
|
||||
'the host must not retain the caller reference',
|
||||
);
|
||||
|
||||
// Sources legitimately recycle scratch vectors between publishes; a mutation
|
||||
// after normalization must never reach the per-frame occluder.
|
||||
caller.x = NaN;
|
||||
caller.y = 999;
|
||||
assert.deepEqual(
|
||||
[normalized.cullPosition.x, normalized.cullPosition.y, normalized.cullPosition.z],
|
||||
[
|
||||
normalized.cullPosition.x,
|
||||
normalized.cullPosition.y,
|
||||
normalized.cullPosition.z,
|
||||
],
|
||||
[4, 5, 6],
|
||||
'post-normalize mutation of the source vector has no effect',
|
||||
);
|
||||
@@ -277,7 +464,11 @@ test('normalizeOverlayEntry: an accessor-backed cullPosition is read exactly onc
|
||||
const normalized = normalizeOverlayEntry('firms', entry);
|
||||
assert.equal(reads, 1, 'one property read — not one per validated component');
|
||||
assert.deepEqual(
|
||||
[normalized.cullPosition.x, normalized.cullPosition.y, normalized.cullPosition.z],
|
||||
[
|
||||
normalized.cullPosition.x,
|
||||
normalized.cullPosition.y,
|
||||
normalized.cullPosition.z,
|
||||
],
|
||||
[4, 5, 6],
|
||||
);
|
||||
});
|
||||
@@ -288,11 +479,21 @@ test('normalizeOverlayEntry: a throwing cullPosition accessor does not abort nor
|
||||
id: 'a',
|
||||
position,
|
||||
title: 'still normalized',
|
||||
get cullPosition() { throw new Error('hostile accessor'); },
|
||||
get cullPosition() {
|
||||
throw new Error('hostile accessor');
|
||||
},
|
||||
};
|
||||
const normalized = normalizeOverlayEntry('firms', entry);
|
||||
assert.equal(normalized.cullPosition, null, 'the bad anchor degrades to null');
|
||||
assert.equal(normalized.title, 'still normalized', 'the rest of the entry survives');
|
||||
assert.equal(
|
||||
normalized.cullPosition,
|
||||
null,
|
||||
'the bad anchor degrades to null',
|
||||
);
|
||||
assert.equal(
|
||||
normalized.title,
|
||||
'still normalized',
|
||||
'the rest of the entry survives',
|
||||
);
|
||||
assert.equal(normalized.id, 'a');
|
||||
});
|
||||
|
||||
@@ -300,12 +501,6 @@ test('normalizeOverlayEntry: a throwing cullPosition accessor does not abort nor
|
||||
// Layer integration: the three production hooks
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class MockEvent {
|
||||
constructor() { this.listeners = new Set(); }
|
||||
addEventListener(listener) { this.listeners.add(listener); return () => this.listeners.delete(listener); }
|
||||
emit() { for (const listener of [...this.listeners]) listener(); }
|
||||
}
|
||||
|
||||
/** Canvas stub good enough for the pre-baked glow sprites. */
|
||||
function canvasStub() {
|
||||
return {
|
||||
@@ -337,9 +532,10 @@ function rawFire(lat, lon, frp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Boots the REAL layer against a headless viewer stub with a REAL
|
||||
* Cesium.BillboardCollection, so the production hooks (not just the pure
|
||||
* predicate) are what the assertions exercise.
|
||||
* Boots the REAL layer on the Cesium engine over a stub scene with a REAL
|
||||
* Cesium.Camera and the engine's REAL Cesium.BillboardCollection, so the
|
||||
* production hooks (not just the pure predicate) are what the assertions
|
||||
* exercise.
|
||||
*/
|
||||
function createHarness(rawFires) {
|
||||
const originalFetch = globalThis.fetch;
|
||||
@@ -357,9 +553,14 @@ function createHarness(rawFires) {
|
||||
|
||||
// Deterministic projection: every distinct world position gets its own
|
||||
// 200 px grid slot (well clear of LABEL_MIN_SEP_PX) inside a 2000×2000
|
||||
// canvas, so declutter geometry never decides these assertions.
|
||||
// canvas, so declutter geometry never decides these assertions. The
|
||||
// engine's projector reads it when the engine is made.
|
||||
const slots = new Map();
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = (scene, position, result) => {
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = (
|
||||
scene,
|
||||
position,
|
||||
result,
|
||||
) => {
|
||||
if (!slots.has(position)) slots.set(position, slots.size);
|
||||
const slot = slots.get(position);
|
||||
const out = result || new Cesium.Cartesian2();
|
||||
@@ -368,30 +569,21 @@ function createHarness(rawFires) {
|
||||
return out;
|
||||
};
|
||||
|
||||
const preRender = new MockEvent();
|
||||
const moveEnd = new MockEvent();
|
||||
const primitives = [];
|
||||
const { engine, viewer, primitive, frame } = createCesiumMoversEngine({
|
||||
engineOptions: { createEventHandler: createFakeEventHandlers().create },
|
||||
});
|
||||
viewer.scene.groundPrimitives = new Cesium.PrimitiveCollection();
|
||||
Object.assign(viewer.scene.canvas, { clientWidth: 2000, clientHeight: 2000 });
|
||||
// No view rectangle (Cesium's answer for a view of the sky or the whole
|
||||
// globe): the layer draws the globally strongest detections, so far-side
|
||||
// fires are drawn and only the horizon pass decides what shows.
|
||||
viewer.camera.computeViewRectangle = () => undefined;
|
||||
const moveCameraTo = (lon, lat, height = REPRO_HEIGHT_M) =>
|
||||
engine.camera.setView({
|
||||
destination: Cesium.Cartesian3.fromDegrees(lon, lat, height),
|
||||
});
|
||||
moveCameraTo(AUSTIN.lon, AUSTIN.lat);
|
||||
const entryCalls = [];
|
||||
const viewer = {
|
||||
dataSources: { add: (value) => value, remove: () => {} },
|
||||
camera: {
|
||||
moveEnd,
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, REPRO_HEIGHT_M),
|
||||
directionWC: new Cesium.Cartesian3(0, 0, -1),
|
||||
positionCartographic: { height: REPRO_HEIGHT_M },
|
||||
},
|
||||
scene: {
|
||||
canvas: { clientWidth: 2000, clientHeight: 2000 },
|
||||
preRender,
|
||||
primitives: {
|
||||
add: (value) => { primitives.push(value); return value; },
|
||||
remove: () => {},
|
||||
contains: () => false,
|
||||
},
|
||||
frameState: { mode: Cesium.SceneMode.SCENE3D, mapProjection: new Cesium.GeographicProjection() },
|
||||
mapProjection: new Cesium.GeographicProjection(),
|
||||
},
|
||||
};
|
||||
|
||||
const layer = createFirmsHeatmapLayer({
|
||||
id: 'firms',
|
||||
@@ -401,36 +593,58 @@ function createHarness(rawFires) {
|
||||
setVisible: () => {},
|
||||
clearSource: () => {},
|
||||
},
|
||||
screenSpaceEventHandlerFactory: () => ({ setInputAction() {}, destroy() {} }),
|
||||
// The display the registry gives every engine, with image seams.
|
||||
renderer: {
|
||||
create: ({ engine: target, ...options }) =>
|
||||
createFirmsDisplay(target, {
|
||||
...options,
|
||||
loadImage: async () => ({ width: 16, height: 16 }),
|
||||
createCanvas: () => ({ getContext: () => ({ drawImage() {} }) }),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const settle = async () => {
|
||||
for (let i = 0; i < 4; i++)
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
};
|
||||
const drawnCount = () =>
|
||||
engine.movers.list().find((set) => set.id === 'firms:firms')?.count ?? 0;
|
||||
|
||||
return {
|
||||
layer,
|
||||
viewer,
|
||||
preRender,
|
||||
moveEnd,
|
||||
/** The real BillboardCollection the layer created. */
|
||||
billboards: () => primitives[0],
|
||||
engine,
|
||||
/** Attaches the layer to the engine and enables it; markers drawn. */
|
||||
async start() {
|
||||
layer.init(null, { engine });
|
||||
await layer.enable();
|
||||
await settle();
|
||||
},
|
||||
settle,
|
||||
/** The real BillboardCollection the engine drew the markers with. */
|
||||
billboards: () => primitive('firms:firms'),
|
||||
drawnCount,
|
||||
/** Latest entry list published to the overlay host. */
|
||||
latestEntries: () => entryCalls[entryCalls.length - 1] || [],
|
||||
/** `show` flags keyed by billboard pick id. */
|
||||
/** `show` flags of the drawn markers, keyed by billboard pick id. */
|
||||
showById() {
|
||||
const bb = primitives[0];
|
||||
const bb = primitive('firms:firms');
|
||||
const out = new Map();
|
||||
for (let i = 0; i < bb.length; i += 1) out.set(bb.get(i).id, bb.get(i).show);
|
||||
for (let i = 0; i < drawnCount(); i += 1)
|
||||
out.set(bb.get(i).id, bb.get(i).show);
|
||||
return out;
|
||||
},
|
||||
moveCameraTo(lon, lat, height = REPRO_HEIGHT_M) {
|
||||
viewer.camera.positionWC = Cesium.Cartesian3.fromDegrees(lon, lat, height);
|
||||
viewer.camera.positionCartographic = { height };
|
||||
},
|
||||
moveCameraTo,
|
||||
moveEnd: () => viewer.camera.moveEnd.raiseEvent(),
|
||||
preRender: () => frame(),
|
||||
cleanup() {
|
||||
layer.destroy(viewer);
|
||||
unregisterSpriteCollection('firms');
|
||||
layer.destroy();
|
||||
engine.destroy();
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = originalProject;
|
||||
globalThis.fetch = originalFetch;
|
||||
if (originalWindow === undefined) delete globalThis.window; else globalThis.window = originalWindow;
|
||||
if (originalDocument === undefined) delete globalThis.document; else globalThis.document = originalDocument;
|
||||
if (originalWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = originalWindow;
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = originalDocument;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -442,14 +656,25 @@ test('layer: a detection rebuild culls its own freshly-added sprites', async ()
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
// No camera event has fired — only renderDetections ran.
|
||||
const show = harness.showById();
|
||||
assert.equal(show.size, 3, 'all three detections were rendered');
|
||||
assert.equal(show.get('firms-0'), true, 'the Austin fire under the camera is visible');
|
||||
assert.equal(show.get('firms-1'), false, 'the antipodal fire is culled at build time');
|
||||
assert.equal(show.get('firms-2'), false, 'the Tokyo fire is culled at build time');
|
||||
assert.equal(
|
||||
show.get('firms-0'),
|
||||
true,
|
||||
'the Austin fire under the camera is visible',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
false,
|
||||
'the antipodal fire is culled at build time',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-2'),
|
||||
false,
|
||||
'the Tokyo fire is culled at build time',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
@@ -461,15 +686,23 @@ test('layer: camera moveEnd re-culls without a rebuild', async () => {
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
assert.equal(harness.showById().get('firms-1'), false, 'precondition: Tokyo hidden from Austin');
|
||||
await harness.start();
|
||||
assert.equal(
|
||||
harness.showById().get('firms-1'),
|
||||
false,
|
||||
'precondition: Tokyo hidden from Austin',
|
||||
);
|
||||
|
||||
harness.moveCameraTo(TOKYO.lon, TOKYO.lat);
|
||||
harness.moveEnd.emit();
|
||||
harness.moveEnd();
|
||||
await harness.settle();
|
||||
|
||||
const show = harness.showById();
|
||||
assert.equal(show.get('firms-1'), true, 'Tokyo becomes visible once the camera is over it');
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
true,
|
||||
'Tokyo becomes visible once the camera is over it',
|
||||
);
|
||||
assert.equal(show.get('firms-0'), false, 'Austin drops behind the limb');
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
@@ -482,20 +715,30 @@ test('layer: the throttled preRender watcher re-culls on a camera move', async (
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
harness.moveCameraTo(TOKYO.lon, TOKYO.lat);
|
||||
// The watcher is throttled to LOD_CHECK_MS (650 ms) against
|
||||
// performance.now(), whose value at this point depends on process
|
||||
// start-up — so emit, wait out the full throttle window, and emit again.
|
||||
// Whichever tick passes the gate, one of them must run the pass.
|
||||
harness.preRender.emit();
|
||||
await new Promise((resolve) => { setTimeout(resolve, 700); });
|
||||
harness.preRender.emit();
|
||||
harness.preRender();
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 700);
|
||||
});
|
||||
harness.preRender();
|
||||
await harness.settle();
|
||||
|
||||
const show = harness.showById();
|
||||
assert.equal(show.get('firms-1'), true, 'Tokyo revealed by the preRender pass');
|
||||
assert.equal(show.get('firms-0'), false, 'Austin culled by the preRender pass');
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
true,
|
||||
'Tokyo revealed by the preRender pass',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-0'),
|
||||
false,
|
||||
'Austin culled by the preRender pass',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
@@ -507,23 +750,35 @@ test('layer: re-enabling after the camera moved does not expose stale far-side s
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
assert.equal(harness.showById().get('firms-1'), false, 'precondition: Tokyo hidden from Austin');
|
||||
await harness.start();
|
||||
assert.equal(
|
||||
harness.showById().get('firms-1'),
|
||||
false,
|
||||
'precondition: Tokyo hidden from Austin',
|
||||
);
|
||||
|
||||
harness.layer.disable();
|
||||
// The camera moves while the layer is OFF: moveEnd is not being listened
|
||||
// to, and the preRender watcher is inert. Nothing re-culls on its own.
|
||||
harness.moveCameraTo(TOKYO.lon, TOKYO.lat);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.layer.enable();
|
||||
await harness.settle();
|
||||
|
||||
// Assert with NO camera event fired and NO refetch (fires are already
|
||||
// loaded, so enable() does not reload): the enable path itself must have
|
||||
// re-culled before the collection went visible.
|
||||
const show = harness.showById();
|
||||
assert.equal(harness.billboards().show, true, 'the collection is visible again');
|
||||
assert.equal(show.get('firms-1'), true, 'the Tokyo fire is revealed at enable time');
|
||||
assert.equal(show.get('firms-0'), false, 'the Austin fire is NOT left shining through the planet');
|
||||
assert.equal(harness.drawnCount(), 2, 'the markers are drawn again');
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
true,
|
||||
'the Tokyo fire is revealed at enable time',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-0'),
|
||||
false,
|
||||
'the Austin fire is NOT left shining through the planet',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
@@ -541,8 +796,7 @@ test('layer: a near-limb fire on a sub-ellipsoid anchor is not culled by its dat
|
||||
rawFire(lat, lon, 90),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
|
||||
const bb = harness.billboards();
|
||||
const sunken = bb.get(1);
|
||||
@@ -551,8 +805,16 @@ test('layer: a near-limb fire on a sub-ellipsoid anchor is not culled by its dat
|
||||
Math.abs(carto.height - (-27 + FIRE_ANCHOR_LIFT_M)) < 0.5,
|
||||
`the sprite still RENDERS at the datum-correct anchor, got ${carto.height}`,
|
||||
);
|
||||
assert.equal(sunken.show, true, 'the near-limb fire stays on screen (lifted cull anchor)');
|
||||
assert.equal(harness.showById().get('firms-0'), true, 'the camera-nadir fire is unaffected');
|
||||
assert.equal(
|
||||
sunken.show,
|
||||
true,
|
||||
'the near-limb fire stays on screen (lifted cull anchor)',
|
||||
);
|
||||
assert.equal(
|
||||
harness.showById().get('firms-0'),
|
||||
true,
|
||||
'the camera-nadir fire is unaffected',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
_clearMeshFloorCellsForTest();
|
||||
@@ -562,25 +824,37 @@ test('layer: a near-limb fire on a sub-ellipsoid anchor is not culled by its dat
|
||||
|
||||
test('layer: far-side candidates never displace near-side ambient cards', async () => {
|
||||
const near = [];
|
||||
for (let i = 0; i < 6; i += 1) near.push(rawFire(AUSTIN.lat + i * 0.4, AUSTIN.lon + i * 0.4, 100 - i));
|
||||
for (let i = 0; i < 6; i += 1)
|
||||
near.push(rawFire(AUSTIN.lat + i * 0.4, AUSTIN.lon + i * 0.4, 100 - i));
|
||||
const far = [];
|
||||
for (let i = 0; i < 20; i += 1) far.push(rawFire(ANTIPODE.lat + i * 0.4, ANTIPODE.lon + i * 0.4, 900 - i));
|
||||
for (let i = 0; i < 20; i += 1)
|
||||
far.push(rawFire(ANTIPODE.lat + i * 0.4, ANTIPODE.lon + i * 0.4, 900 - i));
|
||||
// Far-side fires are the STRONGEST, so they lead the FRP-ranked candidate
|
||||
// walk and would eat all 18 ambient slots without the horizon skip.
|
||||
const harness = createHarness([...near, ...far]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
|
||||
const ids = harness.latestEntries().map((entry) => entry.id);
|
||||
assert.ok(ids.length > 0, 'cards were published');
|
||||
assert.ok(ids.length <= FIRMS_AMBIENT_COHORT_LIMIT, 'the ambient cap still holds');
|
||||
assert.ok(
|
||||
ids.length <= FIRMS_AMBIENT_COHORT_LIMIT,
|
||||
'the ambient cap still holds',
|
||||
);
|
||||
// Card ids are `fire:firms:<lat>:<lon>:<acqMs>:<sat>` (the refetch-stable
|
||||
// detection key), so a card is matched back to its seed by coordinate.
|
||||
const nearCoords = new Set(near.map((fire) => `${fire.lat.toFixed(4)}:${fire.lon.toFixed(4)}`));
|
||||
const nearIds = ids.filter((id) => nearCoords.has(id.split(':').slice(2, 4).join(':')));
|
||||
const nearCoords = new Set(
|
||||
near.map((fire) => `${fire.lat.toFixed(4)}:${fire.lon.toFixed(4)}`),
|
||||
);
|
||||
const nearIds = ids.filter((id) =>
|
||||
nearCoords.has(id.split(':').slice(2, 4).join(':')),
|
||||
);
|
||||
assert.equal(nearIds.length, 6, 'every in-view fire gets a card');
|
||||
assert.equal(new Set(nearIds).size, 6, 'six distinct near-side detections, not one repeated');
|
||||
assert.equal(
|
||||
new Set(nearIds).size,
|
||||
6,
|
||||
'six distinct near-side detections, not one repeated',
|
||||
);
|
||||
assert.equal(ids.length, 6, 'no slot is spent on a fire behind the planet');
|
||||
assert.equal(FIRMS_OVERLAY_SOURCE_ID, 'firms');
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user