Aircraft drawn as far behind real time as their feed is late, along one curve their trail follows

Civil and military aircraft were drawn a fixed 30 s (15 s) behind real time
while anonymous feed reports arrive about 90 s old every 30 s, so every
contact dead reckoned about a minute past its newest report and snapped
when the next one landed (several km on a turn), and the tracked trail,
recorded from those drawn positions and patched as reports arrived, kinked.

- The display delay (data/displayDelay.js) is the 90th percentile of the
  newest 256 report lags plus 5 s, between the layer's floor (30 s, 15 s)
  and five minutes, slewed at most 0.2 s/s up and 0.05 s/s down. Icons,
  the renderer's live motion clock, labels, HUD, detection, the tracked
  camera and the trail read the one delay; following the world clock
  draws with none and deliveries leave it alone.
- Between two reports an aircraft flies a biarc (data/fixCurve.js) that
  passes through both and leaves each along its track, sent as contract
  arc segments; the trail is the reports joined along the same curve, so
  the icon sits on it. Nothing drawn between reports is kept.
- A report a coasting contact missed is eased onto from where it would
  have been that frame (at least 3 s, at most 30% over its speed, within
  20 s); over 5 km it jumps. Past its newest report a contact coasts
  straight on: a turn rate averaged over earlier reports outlived the turn.
- Forward synthetic fixes no longer block real reports older than them,
  and a history keeps 24 fixes.
- A feed simulation (testSupport/aircraftFeedSim.mjs) checks both layers
  against a 90 s late feed, a fallback switch, repeated reports, outages
  and the world clock.
This commit is contained in:
Sameh Khamis committed 2026-11-14 00:31:29 -08:00
1 parent c57eb74506
commit 5f98f8bdf3
40 files changed
+2606 -1238

No files matched your search

+117 -111
View File
@@ -8,8 +8,9 @@ import { createFlightState } from './state.js';
import { createTracking } from './tracking.js';
import { RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
// Between reports, a tracked trail is the path the icon was actually drawn
// along: the real display position, recorded as the frames go by. These tests
// A tracked trail is the aircraft's reports joined along the curve the icon
// is drawn along between them, so the icon always sits on its trail and a
// late report can never leave a kink. These tests
// drive the real motion and display path frame by frame.
const SEC = 1000;
@@ -169,6 +170,42 @@ function harness({
};
}
/**
* The report a plane at `from` (speed and track as reported) gives at `toMs`
* after a constant turn at `rateDps` (negative left), with `trackDeg` its track.
*/
function turnedFix(from, toMs, rateDps, trackDeg) {
const seconds = (toMs - from.epochMs) / SEC;
const turned = (rateDps * seconds * Math.PI) / 180;
const r = from.velocity / Math.abs((rateDps * Math.PI) / 180);
const h = (from.track * Math.PI) / 180;
const fwd = [Math.sin(h), Math.cos(h)];
const side = Math.sign(rateDps);
// To the right of the heading for a right turn, the left for a left one.
const right = [Math.cos(h), -Math.sin(h)];
const along = r * Math.sin(Math.abs(turned));
const across = side * r * (1 - Math.cos(turned));
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(from.position);
const p = Cesium.Matrix4.multiplyByPoint(
enu,
new Cesium.Cartesian3(
fwd[0] * along + right[0] * across,
fwd[1] * along + right[1] * across,
0,
),
new Cesium.Cartesian3(),
);
const c = Cesium.Cartographic.fromCartesian(p);
return fix(
toMs,
Cesium.Math.toDegrees(c.latitude),
Cesium.Math.toDegrees(c.longitude),
Cesium.Cartographic.fromCartesian(from.position).height,
from.velocity,
trackDeg,
);
}
/** Distance from p to the nearest point of a polyline. */
function distanceToPath(p, path) {
let best = Infinity;
@@ -215,6 +252,23 @@ function assertNoSpur(line, label) {
}
}
/** No vertex of `line` turns it more than `maxDeg` (steps under 1 m skipped). */
function assertSmooth(line, maxDeg, label) {
const u = new Cesium.Cartesian3();
const v = new Cesium.Cartesian3();
for (let i = 1; i < line.length - 1; i++) {
Cesium.Cartesian3.subtract(line[i], line[i - 1], u);
Cesium.Cartesian3.subtract(line[i + 1], line[i], v);
const lu = Cesium.Cartesian3.magnitude(u);
const lv = Cesium.Cartesian3.magnitude(v);
if (!(lu > 1 && lv > 1)) continue;
const deg =
(Math.acos(Math.min(1, Cesium.Cartesian3.dot(u, v) / (lu * lv))) * 180) /
Math.PI;
assert.ok(deg <= maxDeg, `${label}: ${deg.toFixed(1)}° at vertex ${i}`);
}
}
const indexOfPoint = (line, p) =>
line.findIndex((q) => Cesium.Cartesian3.distance(p, q) < 0.01);
@@ -242,64 +296,40 @@ function departure() {
return { fixes, info };
}
test('a report newer than the display time arrives mid-turn: the trail between the two reports stays on the drawn arc', () => {
test('a report from a turn lands while the icon coasts: the trail runs report to report along their curve, with no kink, and the icon is on it', () => {
const { fixes, info } = departure();
const start = T0 + 90 * SEC + RENDER_DELAY_SEC * SEC;
const h = harness({ fixes, info, nowMs: start });
try {
h.tracking._startTrail(ICAO);
// 40 s of turn with no new report: the icon flies the arc.
// 40 s with no new report: past it, the icon flies straight on.
h.run(start + 40 * SEC);
const arc = h.drawn.slice();
// The next report is where the plane really was 60 s after the last one,
// still ahead of the display time (normal 30 s delay, slow feed). The icon
// now interpolates the straight line between the two reports and is eased
// onto it.
const at60 = h.motion._deadReckon(
ICAO,
new Cesium.Cartesian3(),
Cesium.JulianDate.fromDate(new Date(T0 + 150 * SEC)),
);
const c = Cesium.Cartographic.fromCartesian(at60);
const report = fix(
T0 + 150 * SEC,
Cesium.Math.toDegrees(c.latitude),
Cesium.Math.toDegrees(c.longitude),
c.height,
112,
220,
);
// still ahead of the display time: through a 2°/s left turn, heading 220°.
const report = turnedFix(fixes[3], T0 + 150 * SEC, -2, 220);
fixes.push(report);
info.true_track = 220;
h.tracking._appendTrailFix(
Cesium.Cartesian3.clone(report.position),
report.epochMs,
{ track: 220 },
);
// The display passes the new report.
h.run(start + 75 * SEC);
const line = h.bodyPoints();
const from = indexOfPoint(line, fixes[3].position);
const to = indexOfPoint(line, report.position);
assert.ok(from >= 0 && to > from, 'both reports are on the trail');
const between = line.slice(from, to + 1);
// Every vertex between the reports is where the icon was drawn...
const drawnPath = [fixes[3].position, ...h.drawn, report.position];
for (const vertex of between) {
const off = distanceToPath(vertex, drawnPath);
assert.ok(
off < 50,
`trail vertex ${off.toFixed(0)} m off the drawn path`,
);
}
// ...and the arc the icon flew is still there: no straight chord. (The
// arc strays far from the chord, so a chord would fail this.)
const a = indexOfPoint(line, fixes[3].position);
const b = indexOfPoint(line, report.position);
assert.ok(a >= 0 && b > a, 'both reports are on the trail');
const between = line.slice(a, b + 1);
// A curve, not the chord, and smooth: no vertex turns more than 3°.
const chord = [fixes[3].position, report.position];
assert.ok(Math.max(...arc.map((p) => distanceToPath(p, chord))) > 300);
// The last 10 s of the arc are exempt: the correction pulled the icon back
// over them, and keeping them would fold the line back on itself.
for (const point of arc.slice(0, -100)) {
const off = distanceToPath(point, between);
assert.ok(off < 50, `drawn arc point ${off.toFixed(0)} m from the trail`);
assert.ok(Math.max(...between.map((p) => distanceToPath(p, chord))) > 300);
assertSmooth(between, 3, 'trail');
// Eased onto the curve, the icon is drawn on its trail.
const trail = [...line, ...h.head()];
for (const p of h.drawn.slice(-100)) {
const off = distanceToPath(p, trail);
assert.ok(off < 3, `drawn ${off.toFixed(1)} m off the trail`);
}
assertNoSpur(line, 'trail');
assertNoSpur(h.head(), 'head');
@@ -361,31 +391,30 @@ test('a fresh report after a hold resumes with no backward spur', () => {
}
});
test('with the head hidden the body keeps advancing, and untracking clears the recording', () => {
test('with the head hidden the body moves on as the display passes reports, and untracking clears the trail', () => {
const { fixes, info } = departure();
const start = T0 + 90 * SEC + RENDER_DELAY_SEC * SEC;
// Drawn 30 s after the first report: the body holds the first two.
const start = T0 + 30 * SEC + RENDER_DELAY_SEC * SEC;
const h = harness({ fixes, info, nowMs: start });
try {
h.tracking._startTrail(ICAO);
h.run(start + 5 * SEC);
const before = h.bodyPoints().at(-1);
// Cockpit view: the head is hidden and its callback never runs.
h.run(start + 30 * SEC, { readHead: false });
// The body's end keeps following the icon; straight stretches are thinned.
const end = h.bodyPoints().at(-1);
h.run(start + 1 * SEC);
assert.ok(
Cesium.Cartesian3.distance(end, before) > 1_000,
Cesium.Cartesian3.distance(h.bodyPoints().at(-1), fixes[1].position) <
0.01,
);
// Cockpit view: the head is hidden, the body still moves on.
h.run(start + 61 * SEC, { readHead: false });
assert.ok(
Cesium.Cartesian3.distance(h.bodyPoints().at(-1), fixes[3].position) <
0.01,
'the body stopped advancing',
);
assert.ok(Cesium.Cartesian3.distance(end, h.drawn.at(-1)) < 300);
h.tracking._clearTrail();
assert.equal(h.flightState._trailFixes.length, 0);
// A new track of the same plane starts from reports only.
// A new track of the same plane starts from its reports.
h.tracking._startTrail(ICAO);
assert.equal(
h.flightState._trailFixes.filter((entry) => entry.drawn).length,
0,
);
assert.equal(h.flightState._trailFixes.length, fixes.length);
} finally {
h.restore();
}
@@ -452,7 +481,6 @@ test('a report the display already passed replaces the guess drawn after it, wit
try {
h.tracking._startTrail(ICAO);
h.run(start + 40 * SEC);
const displayMs = T0 + 130 * SEC;
// A report for 10 s before the display time, 400 m inside the drawn arc.
const guess = h.motion._deadReckon(
ICAO,
@@ -475,16 +503,11 @@ test('a report the display already passed replaces the guess drawn after it, wit
report.epochMs,
);
h.run(start + 55 * SEC);
const recorded = h.flightState._trailFixes.filter((entry) => entry.drawn);
// Nothing recorded between the report and the end of the ease.
// Reports only: nothing drawn between them is kept.
assert.deepEqual(
recorded
.filter(
(entry) =>
entry.timeMs > report.epochMs && entry.timeMs < displayMs + 900,
)
.map((entry) => entry.timeMs - T0),
[],
h.flightState._trailFixes.map((entry) => entry.timeMs),
fixes.map((f) => f.epochMs),
'the trail holds the reports and nothing else',
);
const line = h.bodyPoints();
assert.ok(indexOfPoint(line, report.position) >= 0);
@@ -494,7 +517,7 @@ test('a report the display already passed replaces the guess drawn after it, wit
}
});
test('a history report at an invented height is seeded with no position, and nothing is recorded next to it', () => {
test('a history report at an invented height is seeded with no position, and the trail holds only reports', () => {
const { fixes, info } = departure();
fixes[3].inventedHeight = true;
const start = T0 + 90 * SEC + RENDER_DELAY_SEC * SEC;
@@ -507,9 +530,10 @@ test('a history report at an invented height is seeded with no position, and not
assert.equal(seeded.position, null);
assert.equal(seeded.nullAltitude, true);
h.run(start + 10 * SEC);
assert.equal(
h.flightState._trailFixes.filter((entry) => entry.drawn).length,
0,
assert.deepEqual(
h.flightState._trailFixes.map((entry) => entry.timeMs),
fixes.map((f) => f.epochMs),
'the trail holds the reports and nothing else',
);
} finally {
h.restore();
@@ -570,15 +594,14 @@ test('a plane that stops reporting keeps moving dimmed as STALE from its first m
);
// The coast ends 300 s past the report; the plane stops there.
h.run(pastReport(310));
const recorded = h.flightState._trailFixes.filter((e) => e.drawn).length;
h.run(pastReport(330));
assert.ok(
Cesium.Cartesian3.distance(h.drawn.at(-1), h.drawn.at(-50)) < 0.01,
);
assert.equal(
h.flightState._trailFixes.filter((e) => e.drawn).length,
recorded,
'the trail kept recording a stopped plane',
assert.deepEqual(
h.flightState._trailFixes.map((entry) => entry.timeMs),
fixes.map((f) => f.epochMs),
'the trail holds the reports and nothing else',
);
// 330 s of display past the report is 330 s + the display delay of wall time.
const minutes = Math.floor((330 + RENDER_DELAY_SEC) / 60);
@@ -618,7 +641,7 @@ test('a plane held at its last report shows SIGNAL LOST in seconds under a minut
}
});
test('a report arriving 200 s into a coast: the plane eases onto it and the trail drops what was drawn after it', () => {
test('a report arriving 200 s into a coast: the plane eases onto it with no jump, and the trail runs report to report', () => {
const { fixes, info } = outOfCoverage();
const h = harness({ fixes, info, nowMs: pastReport(-5) });
try {
@@ -645,27 +668,29 @@ test('a report arriving 200 s into a coast: the plane eases onto it and the trai
h.tracking._appendTrailFix(
Cesium.Cartesian3.clone(report.position),
report.epochMs,
{ track: 90 },
);
// Reports only: nothing the coast drew is kept.
assert.deepEqual(
h.flightState._trailFixes.filter(
(e) => e.drawn && e.timeMs > report.epochMs,
),
[],
h.flightState._trailFixes.map((e) => e.timeMs),
fixes.map((f) => f.epochMs),
);
const from = h.drawn.length;
h.run(pastReport(203));
h.run(pastReport(240));
const after = h.drawn.slice(from - 1);
// Frames are 100 ms apart: 14 m at 140 m/s. The ease adds at most 30 %.
for (let i = 1; i < after.length; i++)
assert.ok(
Cesium.Cartesian3.distance(after[i], after[i - 1]) < 400,
Cesium.Cartesian3.distance(after[i], after[i - 1]) < 14 * 1.5,
'the plane jumped instead of easing',
);
// Eased onto the path from the report: 13 s on from it at 140 m/s.
// Eased onto the path from the report: 50 s on from it at 140 m/s.
const off = Cesium.Cartesian3.distance(after.at(-1), report.position);
assert.ok(
Math.abs(off - 140 * 13) < 150,
Math.abs(off - 140 * 50) < 150,
`${off.toFixed(0)} m from the report`,
);
assert.ok(indexOfPoint(h.bodyPoints(), report.position) >= 0);
} finally {
h.restore();
}
@@ -778,7 +803,7 @@ test('a stalled feed dims the tracked plane as STALE', () => {
}
});
test('a report arriving after the plane has stopped: it eases in with no spur, and the trail keeps everything up to the stop', () => {
test('a report arriving after the plane has stopped far back: it jumps onto the new path, and the trail runs report to report with no spur', () => {
const { fixes, info } = outOfCoverage();
info.lastContactEpochMs = fixes.at(-1).epochMs;
const h = harness({ fixes, info, nowMs: pastReport(-5) });
@@ -787,14 +812,8 @@ test('a report arriving after the plane has stopped: it eases in with no spur, a
h.run(pastReport(360));
const stop = Cesium.Cartesian3.clone(h.drawn.at(-1));
assert.ok(Cesium.Cartesian3.distance(stop, h.drawn.at(-100)) < 0.01);
const kept = h.flightState._trailFixes
.filter((e) => e.drawn)
.map((e) => Cesium.Cartesian3.clone(e.position));
// The thinned straight coast, recorded up to where the plane stopped.
assert.ok(kept.length >= 2);
assert.ok(Cesium.Cartesian3.distance(kept.at(-1), stop) < 300);
// Heard again, for 20 s before the display time: the plane flew on, a
// little north of its old heading.
// little north of its old heading, 8 km past where it stopped.
const at = T0 + 30 * SEC + 340 * SEC;
const lonDeg =
-108.05 + (140 * 340) / (111_320 * Math.cos((43 * Math.PI) / 180));
@@ -803,26 +822,13 @@ test('a report arriving after the plane has stopped: it eases in with no spur, a
h.tracking._appendTrailFix(
Cesium.Cartesian3.clone(report.position),
report.epochMs,
);
// Nothing was recorded after the stop, so nothing is dropped.
const after = h.flightState._trailFixes
.filter((e) => e.drawn)
.map((e) => e.position);
assert.equal(after.length, kept.length);
kept.forEach((p, i) =>
assert.ok(Cesium.Cartesian3.distance(p, after[i]) < 0.01),
{ track: 90 },
);
const from = h.drawn.length;
h.run(pastReport(365));
const eased = h.drawn.slice(from - 1);
const jump = Cesium.Cartesian3.distance(eased[0], eased.at(-1));
for (let i = 1; i < eased.length; i++)
assert.ok(
Cesium.Cartesian3.distance(eased[i], eased[i - 1]) < jump / 2,
'the plane jumped instead of easing',
);
// On the path from the report: 25 s on from it at 140 m/s.
const off = Cesium.Cartesian3.distance(eased.at(-1), report.position);
const after = h.drawn.slice(from);
// On the path from the report at once: 25 s on from it at 140 m/s.
const off = Cesium.Cartesian3.distance(after.at(-1), report.position);
assert.ok(Math.abs(off - 140 * 25) < 150, `${off.toFixed(0)} m`);
assertNoSpur(h.bodyPoints(), 'trail');
assertNoSpur(h.head(), 'head');