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

+106 -135
View File
@@ -3,163 +3,134 @@ import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import {
insertTrailFix,
recordTrailPoint,
trailBodySegments,
trailPairBreaks,
trailDistanceM,
trailRecordingBlocked,
trailHeadCurvePoints,
} from './trailContinuity.js';
// Reports decide where the line may run: recorded points never join two
// reports too far apart to be one flight, a report the display has already
// passed replaces the guess drawn after it, and old entries let go of the
// positions they stood for.
// A trail is the aircraft's reports and nothing else, each pair that is one
// path joined along the curve the icon is drawn along between them: no
// stretch it was drawn at between reports is kept, so a late report can
// never leave a kink.
const SEC = 1000;
const LIMIT = 2_000;
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-100, 40, 0),
);
const at = (e, n, u = 10) =>
const at = (e, n, u = 3_000) =>
Cesium.Matrix4.multiplyByPoint(
enu,
new Cesium.Cartesian3(e, n, u),
new Cesium.Cartesian3(),
);
/** No two neighbours in one drawn segment are too far apart to be one flight. */
function assertNoBrokenJoin(fixes) {
const reports = fixes.filter((fix) => !fix.drawn && fix.position);
for (const segment of trailBodySegments(fixes, fixes.length)) {
const inSegment = reports.filter((r) =>
segment.some((p) => Cesium.Cartesian3.distance(p, r.position) < 0.01),
);
for (let i = 1; i < inSegment.length; i++)
assert.equal(
trailPairBreaks(
inSegment[i].timeMs - inSegment[i - 1].timeMs,
trailDistanceM(inSegment[i - 1].position, inSegment[i].position),
),
false,
`one segment joins reports at ${inSegment[i - 1].timeMs / SEC} s and ${
inSegment[i].timeMs / SEC
} s`,
);
/** The sharpest turn (degrees) at any vertex of `line`, steps under 1 m skipped. */
function sharpestTurnDeg(line) {
const u = new Cesium.Cartesian3();
const v = new Cesium.Cartesian3();
let worst = 0;
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 cos = Math.min(1, Cesium.Cartesian3.dot(u, v) / (lu * lv));
worst = Math.max(worst, (Math.acos(cos) * 180) / Math.PI);
}
return worst;
}
test('two reports 60 s and 51 km apart are not joined, even by recorded points', () => {
const A = Cesium.Cartesian3.fromDegrees(-100, 40, 9_000);
const B = Cesium.Cartesian3.fromDegrees(-99.4, 40, 9_000);
const fixes = [];
insertTrailFix(fixes, A, 0, LIMIT);
insertTrailFix(fixes, B, 60 * SEC, LIMIT); // ahead of the display
for (let t = 1; t < 60; t++) {
// Nothing is recorded across the pair.
assert.equal(trailRecordingBlocked(fixes, t * SEC), true);
}
assert.equal(trailBodySegments(fixes, fixes.length).length, 2);
// Points recorded before the far report was known are dropped.
const late = [];
insertTrailFix(late, A, 0, LIMIT);
for (let t = 1; t < 60; t++)
recordTrailPoint(
late,
Cesium.Cartesian3.lerp(A, B, t / 60, new Cesium.Cartesian3()),
t * SEC,
LIMIT,
);
insertTrailFix(late, B, 60 * SEC, LIMIT);
assert.equal(late.filter((fix) => fix.drawn).length, 0);
assert.equal(trailBodySegments(late, late.length).length, 2);
assertNoBrokenJoin(late);
});
// A 100 m/s aircraft in a left turn on a 2 km circle centred at (0, R),
// heading east at the origin, reporting every 15 s with its track.
const R = 2_000;
const W = 100 / R;
const circle = (t) => at(R * Math.sin(W * t), R - R * Math.cos(W * t));
const trackAt = (t) => (90 - (W * t * 180) / Math.PI + 360) % 360;
test('a coast, a hold and then a far report: nothing is drawn across', () => {
const A = at(0, 0, 9_000);
test('reports in a turn are joined along a smooth curve through each report', () => {
const fixes = [];
insertTrailFix(fixes, A, 0, LIMIT);
// The icon coasts east for 90 s at 230 m/s, then holds.
for (let t = 1; t <= 200; t++)
recordTrailPoint(
fixes,
at(230 * Math.min(t, 90), 0, 9_000),
t * SEC,
LIMIT,
);
assert.ok(fixes.filter((fix) => fix.drawn).length > 0);
// The next report is 150 km away two minutes later: over 1,500 kt.
const B = at(0, 150_000, 9_000);
insertTrailFix(fixes, B, 120 * SEC, LIMIT);
assertNoBrokenJoin(fixes);
const segments = trailBodySegments(fixes, fixes.length);
const segmentOf = (p) =>
segments.findIndex((s) =>
s.some((q) => Cesium.Cartesian3.distance(p, q) < 0.01),
);
assert.notEqual(segmentOf(A), segmentOf(B));
// No recorded point between the two reports remains.
assert.equal(
fixes.filter((fix) => fix.drawn && fix.timeMs < 120 * SEC).length,
0,
for (let t = 0; t <= 60; t += 15)
insertTrailFix(fixes, circle(t), t * SEC, LIMIT, { track: trackAt(t) });
assert.deepEqual(
fixes.map((f) => f.timeMs),
[0, 15, 30, 45, 60].map((s) => s * SEC),
);
const [line] = trailBodySegments(fixes, fixes.length);
for (const f of fixes)
assert.ok(
line.some((p) => Cesium.Cartesian3.distance(p, f.position) < 0.01),
'every report is on the line',
);
assert.ok(sharpestTurnDeg(line) < 3, `${sharpestTurnDeg(line)}°`);
// On the circle, not across its chords.
for (const p of line)
assert.ok(
Math.abs(Cesium.Cartesian3.distance(p, at(0, R)) - R) < 20,
'a point off the turn',
);
});
for (const off of [200, 400, 600, 1_000]) {
test(`a report the display already passed, ${off} m off a 2 km turn, leaves no spike`, () => {
const R = 2_000;
const w = 100 / R;
const pos = (t, r = R) =>
at(r * Math.sin(w * t), R - r * Math.cos(w * t), 3_000);
const fixes = [];
insertTrailFix(fixes, pos(0), 0, LIMIT);
for (let t = 1; t <= 60; t++)
recordTrailPoint(fixes, pos(t), t * SEC, LIMIT);
const report = pos(50, R - off);
// It arrives with the display at 60 s; the ease takes 900 ms.
insertTrailFix(fixes, report, 50 * SEC, LIMIT, {
displayMs: 60 * SEC,
settleMs: 900,
});
// The guess drawn after the report is gone...
assert.deepEqual(
fixes.filter((fix) => fix.drawn && fix.timeMs > 50 * SEC),
[],
);
// ...nothing is recorded while the icon eases onto the correction...
assert.equal(trailRecordingBlocked(fixes, 60.5 * SEC), true);
assert.equal(trailRecordingBlocked(fixes, 61 * SEC), false);
// ...and the line reads arc, report, corrected path.
for (let t = 61; t <= 70; t++)
recordTrailPoint(fixes, pos(t, R - off), t * SEC, LIMIT);
const line = trailBodySegments(fixes, fixes.length).flat();
const r = line.findIndex(
(p) => Cesium.Cartesian3.distance(p, report) < 0.01,
);
assert.ok(r > 0);
for (const p of line.slice(0, r))
assert.ok(
Math.abs(Cesium.Cartesian3.distance(p, at(0, R, 3_000)) - R) < 31,
'a point before the report is off the arc',
);
for (const p of line.slice(r + 1))
assert.ok(
Math.abs(Cesium.Cartesian3.distance(p, at(0, R, 3_000)) - (R - off)) <
31,
'a point after the report is off the corrected path',
);
});
}
test('entries behind the report before the display let go of the positions they stood for', () => {
test('reports with no track are joined straight, report to report', () => {
const fixes = [];
for (let s = 0; s <= 2 * 3_600; s++) {
const p = at(230 * s, 0, 10_000);
if (s % 15 === 0) insertTrailFix(fixes, p, s * SEC, LIMIT);
else recordTrailPoint(fixes, p, s * SEC, LIMIT);
}
let held = 0;
for (const fix of fixes) held += fix.absorbed?.length ?? 0;
// Only the newest stretch, up to two reports back, keeps what it stood for.
assert.ok(held <= 30, `${held} positions still held`);
for (let t = 0; t <= 60; t += 15)
insertTrailFix(fixes, circle(t), t * SEC, LIMIT);
const [line] = trailBodySegments(fixes, fixes.length);
assert.equal(line.length, fixes.length);
});
test('two reports 60 s and 51 km apart are not joined', () => {
const fixes = [];
insertTrailFix(
fixes,
Cesium.Cartesian3.fromDegrees(-100, 40, 9_000),
0,
LIMIT,
{ track: 90 },
);
insertTrailFix(
fixes,
Cesium.Cartesian3.fromDegrees(-99.4, 40, 9_000),
60 * SEC,
LIMIT,
{ track: 90 },
);
assert.equal(trailBodySegments(fixes, fixes.length).length, 2);
// Nor is the head drawn along a curve across them.
assert.deepEqual(trailHeadCurvePoints(fixes, 1, 30 * SEC), []);
});
test('a report with no altitude keeps no position and breaks the line', () => {
const fixes = [];
insertTrailFix(fixes, circle(0), 0, LIMIT, { track: trackAt(0) });
insertTrailFix(fixes, circle(15), 15 * SEC, LIMIT, { nullAltitude: true });
insertTrailFix(fixes, circle(30), 30 * SEC, LIMIT, { track: trackAt(30) });
assert.equal(fixes[1].position, null);
assert.equal(trailBodySegments(fixes, fixes.length).length, 2);
});
test('a report arriving late goes in time order and the curve stays smooth', () => {
const fixes = [];
for (const t of [0, 30, 15, 45])
insertTrailFix(fixes, circle(t), t * SEC, LIMIT, { track: trackAt(t) });
assert.deepEqual(
fixes.map((f) => f.timeMs / SEC),
[0, 15, 30, 45],
);
const [line] = trailBodySegments(fixes, fixes.length);
assert.ok(sharpestTurnDeg(line) < 3);
});
test('the head runs along the curve to the next report and stops before the display time', () => {
const fixes = [];
insertTrailFix(fixes, circle(0), 0, LIMIT, { track: trackAt(0) });
insertTrailFix(fixes, circle(15), 15 * SEC, LIMIT, { track: trackAt(15) });
const head = trailHeadCurvePoints(fixes, 1, 10 * SEC);
assert.ok(head.length > 5);
const drawnAt = circle(10);
const [body] = trailBodySegments(fixes, 1);
// Body, head points, then the aircraft: one smooth line.
assert.ok(sharpestTurnDeg([...body, ...head, drawnAt]) < 3);
for (const p of head)
assert.ok(Math.abs(Cesium.Cartesian3.distance(p, at(0, R)) - R) < 20);
});