Draw civil flights from an icon set moved on the GPU

Every flight is now a row in the layer's icon set. Its motion segment
follows the same regime `_deadReckon` picks (interpolate between fixes,
warm up backward from the oldest, coast forward from the newest), and
one shared `_motionRegime` makes that choice for both. The shader moves
every untracked contact between polls, so the 12 Hz fleet tick no
longer touches each billboard. It now only re-plans expired rows,
floors grounded contacts, advances focus while needed, and runs the 3D
model regime.

Grounded contacts the floor lifts are pinned to a hold at the floored
position. Their nose glides on the GPU. Contacts within 50 km re-floor
every tick, and farther ones take turns about once a second. Low
contacts are judged for the horizon at no lower than 12 m above the
ellipsoid, as before. Below hover speed a contact's nose holds. A row
whose fleet model is drawn keeps its focus updated, because the model
reads it. Untracking re-plans and re-floors the icon from the tracked
course.

On the same views with about 6,700 OpenSky flights, frame gaps at p95
drop from 28-40 ms to 17 ms, and the fleet tick from 16-37 ms to about
2 ms at most.
This commit is contained in:
Sameh Khamis committed 2026-11-03 19:40:39 -08:00
1 parent 37dd4058c1
commit fa3a3a3bca
33 files changed
+1598 -986

No files matched your search

+2
View File
@@ -252,6 +252,8 @@ const _b64 = (s) =>
* NEAR the display size lets the browser's SVG AA do the work: crisp AND
* smooth. 64 covers the 40–58 px fleet band with ≤1.6× minification. */
const FLEET_RASTER_PX = 64;
/** Raster size of the default fleet glyph. */
export const FLEET_ICON_PX = FLEET_RASTER_PX;
/** Tracked raster: the tracked billboard is the one SUSTAINED large 2D glyph
* (close-zoom fleet flybys hand off to 3D models). Keep the 192 px texture so
* it stays crisp at its biggest on-screen sizes. */
+34
View File
@@ -243,6 +243,40 @@ export function applyAircraftBillboardTreatment({
return _treatmentResult;
}
/**
* The alpha an aircraft draws with: base × max(combined floor, focus × limb
* haze). Icon sets compose the same thing in their shader; models need it here.
* @param {object} input
* @param {number} input.baseAlpha
* @param {number} input.focusFactor
* @param {number} input.cameraDistanceM
* @param {number} input.cameraHeightM
* @param {Partial<typeof DEFAULT_AIRCRAFT_RECESSION_PARAMS>} [input.params]
* @returns {number}
*/
export function aircraftTreatmentAlpha({
baseAlpha,
focusFactor,
cameraDistanceM,
cameraHeightM,
params,
}) {
const tuning = resolvedParams(params);
const factors = aircraftRecessionFactorsResolved(
cameraDistanceM,
cameraHeightM,
tuning,
_scratchFactors,
);
return (
baseAlpha *
Math.max(
tuning.combinedAlphaFloor,
clamp(focusFactor, 0, 1) * factors.alpha,
)
);
}
/**
* Apply layer-owned hue and composed aircraft alpha to an ambient glTF model without
* disturbing Cesium's existing MIX/colorBlendAmount presentation semantics.
+6 -6
View File
@@ -83,24 +83,24 @@ for (const layer of LAYERS) {
test(`${layer.name}: near AIR state is independent from model admission`, () => {
assert.match(source, /nextCockpitNearContacts\(/,
'Cockpit derives a separate near-contact hysteresis set');
assert.match(source, /isCockpitContact && !isCockpitNear[\s\S]*cockpitContactDotImage\(\)/,
assert.match(source, /isCockpitContact && !isCockpitNear[\s\S]*cockpitContactDotImage\(\)|!flightState\._cockpitNearContacts\.has\(icao24\);\s*if \(cockpitDot\) \{\s*const dot = iconAtlas\.slot\(cockpitContactDotImage\(\)/,
'only out-of-range Cockpit contacts become dots');
// `_iconKind` is identity for every unconverted contact (see
// tr3bRegistry.test.mjs) — it only swaps the glyph for a contact the
// operator explicitly converted into a TR-3B.
assert.match(source, /bb\.image\s*=\s*aircraftIcon\(\s*_iconKind\(\s*icao24,\s*meta\?\.klass,?\s*\)(,\s*aircraftVisuals\.read\(bb\)\?\.iconLarge\s*\?\s*TRACKED_ICON_PX\s*:\s*undefined)?,?\s*\)/,
assert.match(source, /bb\.image\s*=\s*aircraftIcon\(\s*_iconKind\(\s*icao24,\s*meta\?\.klass,?\s*\)(,\s*aircraftVisuals\.read\(bb\)\?\.iconLarge\s*\?\s*TRACKED_ICON_PX\s*:\s*undefined)?,?\s*\)|aircraftIcon\(\s*parts\.rendering\._iconKind\(icao24, info\?\.klass\),?\s*\)/,
'near contacts and model fallbacks retain the class-derived aircraft silhouette');
assert.match(source, /setBillboard\(\s*bb,\s*'rotation',\s*0\s*\);/,
assert.match(source, /setBillboard\(\s*bb,\s*'rotation',\s*0\s*\);|set\.setFlag\(row, ICON_ROTATES, false\);/,
'far dots are reset to a rotation-free presentation');
assert.match(source, /\(\s*!(?:flightState\.)?_cockpitContactMode\s*\|\|\s*isCockpitNear,?\s*\)\s*&&\s*\(\s*doRotations\s*\|\|\s*revealed,?\s*\)/,
assert.match(source, /\(\s*!(?:flightState\.)?_cockpitContactMode\s*\|\|\s*isCockpitNear,?\s*\)\s*&&\s*\(\s*doRotations\s*\|\|\s*revealed,?\s*\)|set\.setFlag\(row, ICON_ROTATES, true\);/,
'near 2D silhouettes continue to receive projected course');
assert.match(source, /if\s*\(\s*billboardState\(bb\)\.show,?\s*\)\s*setBillboard\(\s*bb,\s*'show',\s*false\s*\);\s*\/\/\s*hand\s*off\s*ONLY\s*once\s*the\s*model\s*renders/,
assert.match(source, /if\s*\(\s*billboardState\(bb\)\.show,?\s*\)\s*setBillboard\(\s*bb,\s*'show',\s*false\s*\);\s*\/\/\s*hand\s*off\s*ONLY\s*once\s*the\s*model\s*renders|icons\.setShown\(row, false\);\s*\/\/\s*hand\s*off\s*ONLY\s*once\s*the\s*model\s*renders/,
'the gap-proof billboard-to-model handoff remains intact');
});
test(`${layer.name}: Cockpit exit clears near state before restoring map presentation`, () => {
const setMode = /^([ \t]*)function _setCockpitContactMode\b[\s\S]*?\n\1\}/m.exec(source)?.[0];
assert.match(setMode, /else\s*(?:flightState\.)?_cockpitNearContacts\s*=\s*new\s*Set\(\s*,?\s*\);/);
assert.match(setMode, /for\s*\(\s*const\s*\[icao24,\s*bb\]\s*of\s*(?:flightState\.)?_billboards,?\s*\)\s*(?:parts\.\w+\.)?_applyFleetBillboardPresentation\(\s*icao24,\s*bb,?\s*\);/);
assert.match(setMode, /for\s*\(\s*const\s*\[icao24,\s*bb\]\s*of\s*(?:flightState\.)?_billboards,?\s*\)\s*(?:parts\.\w+\.)?_applyFleetBillboardPresentation\(\s*icao24,\s*bb,?\s*\);|for \(let row = 0; row < \(icons\?\.count \?\? 0\); row\+\+\)\s*parts\.icons\._applyIconPresentation\(icons\.idAt\(row\)\);/);
});
}
+4
View File
@@ -40,5 +40,9 @@ export const _driveFleetModelHandoffForTest =
flightsLayer.testing._driveFleetModelHandoffForTest;
export const _ensureFleetModelForTest =
flightsLayer.testing._ensureFleetModelForTest;
export const _iconForTest = flightsLayer.testing._iconForTest;
export const _setIconForTest = flightsLayer.testing._setIconForTest;
export const _floorGroundedIconsForTest =
flightsLayer.testing._floorGroundedIconsForTest;
export const mapAnalystRecord = flightsLayer.mapAnalystRecord;
export default flightsLayer;
+101 -28
View File
@@ -14,6 +14,8 @@ import flightsLayer, {
_setTrackedFlightRefreshStateForTest,
_floorGroundedDisplayPositionForTest,
_clearDisplayFloorStateForTest,
_iconForTest,
_floorGroundedIconsForTest,
mapAnalystRecord,
} from './flights.js';
import { setMilitaryLayerActive } from './militaryRegistry.js';
@@ -225,18 +227,9 @@ test('nonempty OpenSky payload with zero usable rows cannot prove share target a
test('a newly seen aircraft appears at its delayed position, not ahead of it', async () => {
// The fleet renders RENDER_DELAY_SEC behind real time, so a fresh contact's
// first displayed position is its fix projected back to that delayed time.
// Creating the billboard at the raw fix drew it ahead until the next fleet
// Creating the icon at the raw fix drew it ahead until the next fleet
// tick, which then jumped it back about one delay of travel.
const added = [];
const billboardCollection = {
show: false,
add(options) {
const billboard = { ...options };
added.push(billboard);
return billboard;
},
remove() {},
};
const billboardCollection = { show: false };
const viewer = { camera: { positionCartographic: null }, scene: {} };
_setTrackedFlightRefreshStateForTest({
icao24: 'seed00',
@@ -293,9 +286,9 @@ test('a newly seen aircraft appears at its delayed position, not ahead of it', a
};
try {
await flightsLayer.update(viewer);
const billboard = added.find((entry) => entry.id === icao24);
assert.ok(billboard, 'the new contact gets a billboard');
const shown = Cesium.Cartographic.fromCartesian(billboard.position);
const icon = _iconForTest(icao24);
assert.ok(icon, 'the new contact gets an icon');
const shown = Cesium.Cartographic.fromCartesian(icon.position);
const fix = Cesium.Cartesian3.fromDegrees(fixLon, fixLat, 10_700);
const behindM = Cesium.Cartesian3.distance(
Cesium.Cartesian3.fromRadians(shown.longitude, shown.latitude, 10_700),
@@ -1066,21 +1059,12 @@ const _floorCarto = (pos) =>
test('a newly seen taxiing aircraft starts on the floor under its delayed position', async () => {
// A grounded contact is drawn at its delayed position lifted onto the floor
// under it. Creating the billboard without that lift started it on the
// under it. Creating the icon without that lift started it on the
// floor of its reported fix, then the next fleet tick raised it.
_clearDisplayFloorStateForTest();
_clearMeshFloorCellsForTest();
setMeshFloorPreferred(true);
const added = [];
const billboardCollection = {
show: false,
add(options) {
const billboard = { ...options };
added.push(billboard);
return billboard;
},
remove() {},
};
const billboardCollection = { show: false };
const viewer = { camera: { positionCartographic: null }, scene: {} };
_setTrackedFlightRefreshStateForTest({
icao24: 'seed00',
@@ -1142,9 +1126,9 @@ test('a newly seen taxiing aircraft starts on the floor under its delayed positi
};
try {
await flightsLayer.update(viewer);
const billboard = added.find((entry) => entry.id === icao24);
assert.ok(billboard, 'the new contact gets a billboard');
const shown = _floorCarto(billboard.position);
const icon = _iconForTest(icao24);
assert.ok(icon, 'the new contact gets an icon');
const shown = _floorCarto(icon.position);
assert.ok(
Cesium.Math.toDegrees(shown.longitude) < fixLon,
'drawn behind the fix',
@@ -1160,6 +1144,95 @@ test('a newly seen taxiing aircraft starts on the floor under its delayed positi
}
});
test('far grounded contacts take turns on the floor; near ones refloor every tick', async () => {
// The floor pass is the fleet tick's only per-contact CPU work. Past
// FLOOR_NEAR_M a contact is refloored once per FLOOR_FAR_EVERY_TICKS.
_clearDisplayFloorStateForTest();
_clearMeshFloorCellsForTest();
setMeshFloorPreferred(true);
const viewer = { camera: { positionCartographic: null }, scene: {} };
_setTrackedFlightRefreshStateForTest({
icao24: 'seed00',
entity: null,
billboard: {
show: false,
position: Cesium.Cartesian3.fromDegrees(0, 0, 0),
},
billboardCollection: { show: false },
viewer,
meta: { rawLat: 0, rawLon: 0, onGround: false },
tracked: false,
});
const icao24 = 'taxi02';
const fixLon = -97.66;
const fixLat = 30.2;
for (let k = -40; k <= 40; k += 1) {
reportMeshFloorCell(fixLat, fixLon + k * 0.0001, 131.5);
}
const nowSec = Math.floor(Date.now() / 1000);
const realFetch = globalThis.fetch;
globalThis.fetch = async (url) => {
if (!String(url).startsWith('/api/flights')) {
return { ok: true, status: 200, json: async () => ({ ac: [] }) };
}
return {
ok: true,
status: 200,
headers: { get: () => null },
json: async () => ({
time: nowSec,
states: [
[
icao24,
'TAXI02 ',
'United States',
nowSec - 2,
nowSec - 2,
fixLon,
fixLat,
null,
true,
10,
90,
0,
null,
null,
null,
null,
null,
5,
],
],
}),
};
};
try {
await flightsLayer.update(viewer);
const start = Cesium.JulianDate.now();
const at = (s) =>
Cesium.JulianDate.addSeconds(start, s, new Cesium.JulianDate());
const far = Cesium.Cartesian3.fromDegrees(fixLon, fixLat, 3_000_000);
const near = Cesium.Cartesian3.fromDegrees(fixLon, fixLat, 10_000);
let last = _iconForTest(icao24).position;
const moves = (camera, from, to) => {
let count = 0;
for (let tick = from; tick <= to; tick += 1) {
_floorGroundedIconsForTest(at(tick), camera);
const now = _iconForTest(icao24).position;
if (Cesium.Cartesian3.distance(now, last) > 1) count += 1;
last = now;
}
return count;
};
assert.equal(moves(far, 1, 24), 2, 'far: once per 12 ticks');
assert.equal(moves(near, 25, 30), 6, 'near: every tick');
} finally {
globalThis.fetch = realFetch;
_clearMeshFloorCellsForTest();
_clearDisplayFloorStateForTest();
}
});
test('display floor: a grounded contact that drifted onto a higher cell is lifted', () => {
_clearDisplayFloorStateForTest();
_clearMeshFloorCellsForTest();
+18 -2
View File
@@ -45,7 +45,7 @@ const COURSE0 = 19; // deg
const COURSE_SLOPE = 20; // lerp: deg per unit fraction
const SLEW_OFFSET = 21; // deg still to glide at SLEW_T0
const SLEW_T0 = 22; // s
const SLEW_RATE = 23; // deg/s
const SLEW_RATE = 23; // deg/s; negative holds the course at the glide's start
const DEG = Math.PI / 180;
const STRAIGHT_BELOW_RAD_PER_SEC = 1e-4;
@@ -140,6 +140,8 @@ export function writeArcSegment(out, row, segment) {
/**
* Glide the displayed course from `fromCourseDeg` onto the segment's own course,
* at most `rateDps`, starting at `t0` (the rate limit at a segment boundary).
* A rate of zero or less holds `fromCourseDeg` for the whole segment instead
* (a hover: the nose keeps its heading however the track moves).
* Call after writing the segment.
* @param {Float32Array} out
* @param {number} row
@@ -153,7 +155,7 @@ export function writeCourseGlide(out, row, fromCourseDeg, t0, rateDps) {
const target = targetCourse(out, o, t0);
out[o + SLEW_OFFSET] = norm180(fromCourseDeg - target);
out[o + SLEW_T0] = t0;
out[o + SLEW_RATE] = Math.max(0, rateDps);
out[o + SLEW_RATE] = rateDps > 0 ? rateDps : -1;
}
/**
@@ -195,6 +197,8 @@ export function segmentCourse(seg, row, tau) {
const o = row * SEGMENT_STRIDE;
const course = targetCourse(seg, o, tau);
const offset = seg[o + SLEW_OFFSET];
if (seg[o + SLEW_RATE] < 0)
return norm360(targetCourse(seg, o, seg[o + SLEW_T0]) + offset);
if (offset === 0) return norm360(course);
// limitCourseStep: the displayed course turns at the rate toward the segment's
// own (possibly turning) course until it reaches it, then follows it. The
@@ -207,6 +211,17 @@ export function segmentCourse(seg, row, tau) {
return norm360(turned < gap ? start + offset + toward * turned : course);
}
/**
* The course the row glides toward at `tau` (its segment's own course).
* @param {Float32Array} seg
* @param {number} row
* @param {number} tau
* @returns {number}
*/
export function segmentTargetCourse(seg, row, tau) {
return norm360(targetCourse(seg, row * SEGMENT_STRIDE, tau));
}
/** The segment's own course at `tau`, before any glide. */
function targetCourse(seg, o, tau) {
const kind = seg[o + KIND];
@@ -310,6 +325,7 @@ float iconTargetCourse(vec4 seg3, vec4 seg4, vec4 seg5, float tau) {
float iconSegmentCourse(vec4 seg3, vec4 seg4, vec4 seg5, float tau) {
float course = iconTargetCourse(seg3, seg4, seg5, tau);
float offset = seg5.y;
if (seg5.w < 0.0) return iconTargetCourse(seg3, seg4, seg5, seg5.z) + offset;
if (offset == 0.0) return course;
float toward = -sign(offset);
float start = iconTargetCourse(seg3, seg4, seg5, seg5.z);
+32
View File
@@ -213,3 +213,35 @@ test('the course glide never outruns the rate while its target turns', () => {
'then it follows the turn',
);
});
test('a zero-rate glide holds the course however the segment turns', () => {
const seg = new Float32Array(SEGMENT_STRIDE);
const to = Cesium.Cartesian3.fromDegrees(-97.04, 32.90001, 10_500);
for (const from of [0, 30]) {
writeLerpSegment(seg, 0, {
from: fix,
to,
t0: 0,
t1: 30,
course0Deg: 0,
courseSlopeDeg: 90,
});
writeCourseGlide(seg, 0, from, 0, 0);
for (const tau of [0, 10, 20, 30, 60])
assert.ok(
courseGap(segmentCourse(seg, 0, tau), from) < 1e-4,
`from ${from}° at τ=${tau}`,
);
}
writeArcSegment(seg, 0, {
fix,
t0: 0,
minDt: 0,
maxDt: 300,
speedMps: 1,
trackDeg: 90,
turnRateDps: 3,
});
writeCourseGlide(seg, 0, 90, 0, 0);
assert.ok(courseGap(segmentCourse(seg, 0, 20), 90) < 1e-4, 'arc turn held');
});
+25 -1
View File
@@ -43,8 +43,14 @@ export const ICON_SHOWN = 1;
export const ICON_ROTATES = 2;
/** Fade and shrink toward the globe's limb (aircraft recession). */
export const ICON_RECEDES = 4;
/** Lift the row 12 m along the normal before the horizon test (fixes near the ground). */
/**
* Judge the row at no lower than ICON_CULL_HEIGHT_M above the ellipsoid in the
* horizon test. A fix near or below the ellipsoid (a grounded contact at geoid
* −31 m before its floor warms) otherwise reads as beyond the limb.
*/
export const ICON_CULL_LIFT = 8;
/** The ellipsoid height a CULL_LIFT row is raised to for the horizon test. */
export const ICON_CULL_HEIGHT_M = 12;
/** Move the epoch forward once render times pass this many seconds. */
const REBASE_AFTER_SEC = 1800;
@@ -422,6 +428,24 @@ export function createIconSet({ capacity = 1024, epoch } = {}) {
course(row, tau) {
return segmentCourse(segments, row, tau);
},
/** The point the horizon test judges for a row drawn at `position`. */
cullPoint(row, position, result = new Cesium.Cartesian3()) {
if (!(style[row * STYLE_STRIDE + FLAGS] & ICON_CULL_LIFT))
return Cesium.Cartesian3.clone(position, result);
// Height above the ellipsoid along the geocentric ray, as the shader
// computes it: exact to millimetres this close to the surface.
const radius = Cesium.Cartesian3.magnitude(position);
Cesium.Cartesian3.multiplyComponents(
position,
Cesium.Ellipsoid.WGS84.oneOverRadii,
result,
);
const height = radius * (1 - 1 / Cesium.Cartesian3.magnitude(result));
const lift = Math.max(0, ICON_CULL_HEIGHT_M - height);
Cesium.Cartesian3.normalize(position, result);
Cesium.Cartesian3.multiplyByScalar(result, lift, result);
return Cesium.Cartesian3.add(position, result, result);
},
};
function markRow(row) {
+24
View File
@@ -4,6 +4,8 @@ import * as Cesium from 'cesium';
import {
createIconSet,
DirtyRows,
ICON_CULL_HEIGHT_M,
ICON_CULL_LIFT,
ICON_ROTATES,
ICON_SHOWN,
} from './iconSet.js';
@@ -225,3 +227,25 @@ test('rebasing moves the epoch without moving any row', () => {
assert.equal(set.expires(row), 1100);
assert.deepEqual(set.dirty.segments.runs(set.count), [[0, 0]]);
});
test('a cull-lift row is judged at no lower than the cull height above the ellipsoid', () => {
const set = createIconSet();
const row = set.add('a');
const height = (p) => Cesium.Cartographic.fromCartesian(p).height;
const at = (h) => Cesium.Cartesian3.fromDegrees(-84.43, 33.64, h);
assert.ok(
Math.abs(height(set.cullPoint(row, at(-31))) - -31) < 1e-6,
'unflagged: as drawn',
);
set.setFlag(row, ICON_CULL_LIFT, true);
for (const h of [-31, 0, 5]) {
assert.ok(
Math.abs(height(set.cullPoint(row, at(h))) - ICON_CULL_HEIGHT_M) < 0.01,
`${h} m is judged at ${ICON_CULL_HEIGHT_M} m`,
);
}
assert.ok(
Math.abs(height(set.cullPoint(row, at(131))) - 131) < 1e-6,
'a contact floored higher keeps its own height',
);
});
+9 -4
View File
@@ -16,7 +16,7 @@
*/
import * as Cesium from 'cesium';
import { ICON_SEGMENT_GLSL, SEGMENT_STRIDE } from './iconSegment.js';
import { ICON_CULL_LIFT, STYLE_STRIDE } from './iconSet.js';
import { ICON_CULL_HEIGHT_M, ICON_CULL_LIFT, STYLE_STRIDE } from './iconSet.js';
import { iconAtlas, MAX_ICON_SLOTS } from './iconAtlas.js';
import {
cameraLimbDistanceM,
@@ -25,8 +25,6 @@ import {
/** On-screen device pixels above which a row draws its near (large) image. */
const NEAR_IMAGE_PX = 76;
/** Rows lifted this far before the horizon test when flagged (low fixes). */
const CULL_LIFT_M = 12;
const ATTRIBUTE_LOCATIONS = Object.freeze({
corner: 0,
@@ -80,6 +78,13 @@ bool iconFlag(float flags, float bit) {
return mod(floor(flags / bit), 2.0) == 1.0;
}
// Raise a near-ground point to at least the cull height (iconSet.cullPoint).
vec3 iconCullPoint(vec3 world) {
float radius = length(world);
float height = radius * (1.0 - 1.0 / length(world * czm_ellipsoidInverseRadii));
return world + world / radius * max(0.0, ${ICON_CULL_HEIGHT_M.toFixed(1)} - height);
}
bool occludedByEllipsoid(vec3 world) {
vec3 cv = u_horizon.xyz;
float vh2 = u_horizon.w;
@@ -101,7 +106,7 @@ void main() {
vec3 rte = iconSegmentPosition(seg0, seg1, seg2, seg3, seg4, u_tau);
vec3 world = u_cameraPosition + rte;
vec3 cullPoint = iconFlag(flags, ${ICON_CULL_LIFT.toFixed(1)}) ? world + normalize(world) * ${CULL_LIFT_M.toFixed(1)} : world;
vec3 cullPoint = iconFlag(flags, ${ICON_CULL_LIFT.toFixed(1)}) ? iconCullPoint(world) : world;
if (occludedByEllipsoid(cullPoint)) return;
vec4 positionEC = czm_modelViewRelativeToEye * vec4(rte, 1.0);
+1 -1
View File
@@ -1660,7 +1660,7 @@ test('hasContact declines while a layer is disabled, whatever its maps still hol
[
'flights',
readLayerSource(new URL('./flights.js', import.meta.url)),
/hasContact\(\s*icao24,?\s*\)\s*\{\s*\n\s*if\s*\(\s*!(?:flightState\.)?_billboardCollection\s*\|\|\s*!(?:flightState\.)?_billboardCollection\.show\s*\|\|\s*(?:flightState\.)?_billboards\.size\s*===\s*0,?\s*\)\s*return\s*null;/,
/hasContact\(\s*icao24,?\s*\)\s*\{\s*\n\s*const icons = flightState\._icons;\s*\n\s*if\s*\(\s*!icons\s*\|\|\s*!icons\.show\s*\|\|\s*icons\.count\s*===\s*0,?\s*\)\s*return\s*null;/,
],
[
'militaryFlights',
+10 -4
View File
@@ -10,7 +10,10 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import flightsLayer, { _setTrackedFlightRefreshStateForTest } from './flights.js';
import flightsLayer, {
_iconForTest,
_setTrackedFlightRefreshStateForTest,
} from './flights.js';
import militaryFlightsLayer, { _setTrackedMilitaryRefreshStateForTest } from './militaryFlights.js';
const ICAO = 'abc123';
@@ -39,6 +42,8 @@ const LAYERS = [
name: 'commercial',
layer: flightsLayer,
visualCenterM: Cesium.Cartesian3.ZERO,
// Where the icon is drawn: the seeded position as the GPU encodes it.
spritePosition: () => _iconForTest(ICAO).position,
seed({ billboardShow, models = [] }) {
_setTrackedFlightRefreshStateForTest({
icao24: ICAO,
@@ -61,6 +66,7 @@ const LAYERS = [
name: 'military',
layer: militaryFlightsLayer,
visualCenterM: Cesium.Cartesian3.ZERO,
spritePosition: () => contactBillboard(true).position,
seed({ billboardShow, models = [] }) {
_setTrackedMilitaryRefreshStateForTest({
icao24: ICAO,
@@ -149,8 +155,8 @@ for (const fixture of LAYERS) {
const spritePosition = detectionPosition(fixture.layer);
assert.ok(spritePosition, 'the 2D sprite publishes a detection candidate');
assert.ok(
Cesium.Cartesian3.equalsEpsilon(spritePosition, contactBillboard(true).position, 0, 1e-6),
'the 2D bracket stays welded to the billboard position',
Cesium.Cartesian3.equalsEpsilon(spritePosition, fixture.spritePosition(), 0, 1e-6),
'the 2D bracket stays welded to the drawn sprite position',
);
const modelMatrix = Cesium.Matrix4.fromRotationTranslation(MODEL_ROTATION, MODEL_POSITION);
@@ -195,7 +201,7 @@ for (const fixture of LAYERS) {
const loadingPosition = detectionPosition(fixture.layer);
assert.ok(loadingPosition, 'the billboard remains detectable while its model loads');
assert.ok(
Cesium.Cartesian3.equalsEpsilon(loadingPosition, contactBillboard(true).position, 0, 1e-6),
Cesium.Cartesian3.equalsEpsilon(loadingPosition, fixture.spritePosition(), 0, 1e-6),
'a shown-but-unready zero-scale model cannot steal the detection anchor',
);
});
+9 -17
View File
@@ -3,7 +3,6 @@ import test from 'node:test';
import * as Cesium from 'cesium';
import { routePlausible } from './routePlausible.js';
import { createTracking } from '../layers/flights/tracking.js';
import { addBillboard } from './billboardMirror.js';
const SFO = { lat: 37.6188, lon: -122.3754, code: 'SFO' };
const LAX = { lat: 33.9416, lon: -118.4085, code: 'LAX' };
@@ -116,15 +115,14 @@ test('unjudgeable endpoint geometry and missing coordinates keep the loose contr
assert.equal(plausible(beyond, null, null), true);
});
test('the actual native tracked label hides the wrong leg and keeps a healthy route', (t) => {
const collection = new Cesium.BillboardCollection();
t.after(() => collection.destroy());
test('the actual native tracked label hides the wrong leg and keeps a healthy route', () => {
const flightState = {
records: { data: new Map(), missingPolls: new Map() },
feed: { _backoff: false },
_billboards: new Map(),
_scratchCarto: new Cesium.Cartographic(),
};
// Where each contact's icon is drawn.
const drawn = new Map();
// Only application host services are supplied. Route admission, WGS84
// billboard conversion and tracked-label formatting are the actual owners.
const services = Object.fromEntries(
@@ -141,7 +139,10 @@ test('the actual native tracked label hides the wrong leg and keeps a healthy ro
].map((name) => [name, {}]),
);
services.aircraftPresentation = { isTr3b: () => false };
const parts = { queries: { _contactLabel: (_, info) => info.callsign } };
const parts = {
queries: { _contactLabel: (_, info) => info.callsign },
icons: { _iconPosition: (id) => drawn.get(id) ?? null },
};
const tracking = createTracking({ flightState, services, parts });
for (const [position, expected] of [
[beyond, false],
@@ -155,18 +156,9 @@ test('the actual native tracked label hides the wrong leg and keeps a healthy ro
verticalRate: 0,
route,
});
flightState._billboards.set(
drawn.set(
id,
addBillboard(collection, {
id,
width: 20,
height: 20,
position: Cesium.Cartesian3.fromDegrees(
position.lon,
position.lat,
10000,
),
}),
Cesium.Cartesian3.fromDegrees(position.lon, position.lat, 10000),
);
assert.equal(
tracking._trackedLabelText(id).includes('SFO → LAX'),
+3 -3
View File
@@ -233,7 +233,7 @@ test('both flight layers keep a converted contact 2D and visible (render invaria
// 1. The 3D model handoff is SUPPRESSED for a converted contact — there is
// no TR-3B GLB, so the triangle billboard stays the visual.
assert.match(source, /modelEligible\.has\(icao24\) && !isTr3b\(icao24\)/,
assert.match(source, /modelEligible\.has\(icao24\) && !isTr3b\(icao24\)|for \(const icao24 of modelEligible\) \{\s*if \(isTr3b\(icao24\)\) continue;/,
`${name}: fleet model handoff skips converted contacts`);
// The tracked regime became default-on and camera-distance driven
// (2026-08-19), so the suppression moved from a conjunct on
@@ -245,7 +245,7 @@ test('both flight layers keep a converted contact 2D and visible (render invaria
// 2. The billboard is never hidden by that suppression — it must keep
// satisfying the getNearby/getDetectableObjects visibility guards, so a
// converted contact still works in Contacts and Cockpit.
assert.match(source, /if\s*\(\s*(bb|modelled)\s*&&\s*id\s*!==\s*(?:flightState\.)?_trackedIcao,?\s*\)\s*setBillboard\(\s*\1,\s*'show',\s*true,?\s*\);/,
assert.match(source, /if\s*\(\s*(bb|modelled)\s*&&\s*id\s*!==\s*(?:flightState\.)?_trackedIcao,?\s*\)\s*setBillboard\(\s*\1,\s*'show',\s*true,?\s*\);|if\s*\(\s*row >= 0\s*&&\s*id\s*!==\s*flightState\._trackedIcao\s*\)\s*flightState\._icons\.setShown\(row, true\);/,
`${name}: converting restores the billboard the model handoff had hidden`);
// 3. Every aircraftIcon() CALL SITE routes through the kind resolver, so no
@@ -411,7 +411,7 @@ test('a converted contact never consumes a 3D model CAP SLOT', async () => {
const source = readLayerSource(new URL(`./${name}`, import.meta.url));
// Anchor on the MODEL-eligibility loop (keepDistSq), not the unrelated
// ambient-enrichment candidate loop that also builds a `cand`.
const loop = /const\s*cand\s*=\s*\[\];\s*\n\s*for\s*\(\s*const\s*\[icao,\s*bb\]\s*of\s*(?:flightState\.)?_billboards,?\s*\)[\s\S]*?cand\.push\(\s*/.exec(source)?.[0];
const loop = /const\s*cand\s*=\s*\[\];\s*\n\s*for\s*\((?:\s*const\s*\[icao,\s*bb\]\s*of\s*(?:flightState\.)?_billboards,?\s*|let row = 0; row < icons\.count; row\+\+)\)[\s\S]*?cand\.push\(\s*/.exec(source)?.[0];
assert.ok(loop, `${name}: the model-eligibility candidate loop is present`);
assert.match(loop, /keepDistSq/, `${name}: matched the model-eligibility loop`);
assert.match(loop, /if \(isTr3b\(icao\)\) continue;/,
+22 -1
View File
@@ -34,6 +34,8 @@ import flightsLayer, {
_trackedBillboardColorForTest as flightsTrackedBillboardColor,
_driveFleetModelHandoffForTest as flightsDriveFleetModel,
_ensureFleetModelForTest as flightsEnsureFleetModel,
_iconForTest as flightsIcon,
_setIconForTest as flightsSetIcon,
} from './flights.js';
import militaryFlightsLayer, {
_setTrackedMilitaryRefreshStateForTest,
@@ -186,6 +188,25 @@ function contactBillboard() {
};
}
/** A flights contact's icon row, read and written the way these tests read a
* billboard: where it is drawn and whether the layer shows it. */
function flightIconView(icao24) {
return {
get position() {
return flightsIcon(icao24)?.position;
},
set position(position) {
flightsSetIcon(icao24, { position });
},
get show() {
return flightsIcon(icao24)?.shown === true;
},
set show(shown) {
flightsSetIcon(icao24, { shown });
},
};
}
/** Records what the driver hands to the scene, so a test can assert that a
* failing loader never put a model up. */
function recordingModelCollection() {
@@ -216,7 +237,7 @@ const LAYERS = [
modelCollection,
meta: { callsign: 'TEST123 ', altitude: 10_668, klass: 'airliner', onGround },
});
return billboard;
return flightIconView(icao24);
},
},
{