fix(flights): a trail does not join its track history across a landing or take-off that was not seen

This commit is contained in:
Sameh Khamis committed 2026-11-13 12:53:18 -08:00
1 parent 693faae44e
commit 7e45d4d989
7 files changed
+215 -12

No files matched your search

+4
View File
@@ -2,6 +2,10 @@
## [Unreleased] ## [Unreleased]
- A tracked aircraft's trail no longer draws a straight line from its track
history across a landing or take-off that was not seen: a parked or
taxiing aircraft whose history ends in the air (often its previous flight)
starts its trail on the ground (samehkhamis).
- Aircraft from adsb.lol that report no ground track (parked or taxiing - Aircraft from adsb.lol that report no ground track (parked or taxiing
slowly) now face their reported true heading instead of north, so parked slowly) now face their reported true heading instead of north, so parked
models line up with their gates (samehkhamis). models line up with their gates (samehkhamis).
+84 -10
View File
@@ -12,7 +12,10 @@
* longer than 48 minutes (a coverage hole or a separate flight), when the * longer than 48 minutes (a coverage hole or a separate flight), when the
* implied great-circle speed is over 1,500 kt, or when either point has no * implied great-circle speed is over 1,500 kt, or when either point has no
* reported altitude. A parked aircraft is the exception: a pair under three * reported altitude. A parked aircraft is the exception: a pair under three
* hours apart within 0.1 nm stays one path. * hours apart within 0.1 nm stays one path. A history backfill that ends in
* the air does not join an aircraft now on the ground (or the reverse) when
* more than five minutes lie between them: the landing or take-off was not
* seen, and is often a different flight.
* *
* Civil and military flight tracking share these rules. * Civil and military flight tracking share these rules.
*/ */
@@ -40,6 +43,13 @@ export const TRAIL_STATIONARY_HOLD_MAX_GAP_MS = 3 * 60 * 60_000;
/** @constant {number} How close (nautical miles) two points must be to count as parked. */ /** @constant {number} How close (nautical miles) two points must be to count as parked. */
export const TRAIL_STATIONARY_HOLD_MAX_DISTANCE_NM = 0.1; export const TRAIL_STATIONARY_HOLD_MAX_DISTANCE_NM = 0.1;
/**
* @constant {number} An airborne point and a ground point more than this far
* apart in time do not join: the landing or take-off between them was not
* seen. A last waypoint on short final is a few minutes from the runway.
*/
export const TRAIL_UNSEEN_TRANSITION_MAX_GAP_MS = 5 * 60_000;
/** @constant {number} The head never joins a body point farther than this from the aircraft. */ /** @constant {number} The head never joins a body point farther than this from the aircraft. */
export const TRAIL_HEAD_JOIN_MAX_M = 150_000; export const TRAIL_HEAD_JOIN_MAX_M = 150_000;
@@ -139,21 +149,76 @@ export function trailBackfillFixes(waypoints) {
return { fixes, breakAfter: skipped }; return { fixes, breakAfter: skipped };
} }
/**
* Whether the line from an airborne point to a ground point (in either
* order) skips a landing or take-off that was not seen.
* @param {boolean} prevOnGround - Whether the earlier point is on the ground.
* @param {boolean} nextOnGround - Whether the later point is on the ground.
* @param {number} deltaMs - Later point's time minus the earlier one's.
* @returns {boolean}
*/
export function trailGroundTransitionBreaks(
prevOnGround,
nextOnGround,
deltaMs,
) {
return (
prevOnGround !== nextOnGround &&
!(deltaMs <= TRAIL_UNSEEN_TRANSITION_MAX_GAP_MS)
);
}
/** /**
* Put backfill fixes ahead of the live trail. The join follows the same * Put backfill fixes ahead of the live trail. The join follows the same
* rule, so a distant history tail never connects to the first live fix. * rule, so a distant history tail never connects to the first live fix.
* Past `maxPoints` the oldest recorded points go first, then the oldest * A backfill whose last waypoint is in the air while the first live report
* reports. * is on the ground (or the reverse), more than five minutes before it, does
* not join it either. A live report that does not say uses the aircraft's
* state now; with no live fix to start after it, the backfill is checked
* against now and left out, so the head never draws that line. Past `maxPoints` the oldest
* recorded points go first, then the oldest reports.
* @param {{fixes: object[], breakAfter: boolean}} backfill * @param {{fixes: object[], breakAfter: boolean}} backfill
* @param {object[]} live - Live fixes; the first one's break is recomputed. * @param {object[]} live - Live fixes; the first one's break is recomputed.
* @param {number} maxPoints - Point limit across all segments. * @param {number} maxPoints - Point limit across all segments.
* @param {object} [ground] - Ground state across the join.
* @param {boolean} [ground.backfillEndsOnGround] - The last waypoint's.
* @param {boolean} [ground.onGroundNow] - The aircraft's now, for a live
* report that does not carry its own `onGround`.
* @param {number} [ground.nowMs] - Time the aircraft is at now.
* @returns {object[]} The joined trail. * @returns {object[]} The joined trail.
*/ */
export function joinTrailBackfill({ fixes, breakAfter }, live, maxPoints) { export function joinTrailBackfill(
{ fixes, breakAfter },
live,
maxPoints,
ground = null,
) {
if (!fixes.length) return live; if (!fixes.length) return live;
if (live.length) const last = fixes[fixes.length - 1];
live[0].breakBefore = const unseen = (laterMs, laterOnGround) =>
breakAfter || trailFixBreaks(fixes[fixes.length - 1], live[0]); ground !== null &&
typeof ground.backfillEndsOnGround === 'boolean' &&
typeof laterOnGround === 'boolean' &&
trailGroundTransitionBreaks(
ground.backfillEndsOnGround,
laterOnGround,
laterMs - last.timeMs,
);
if (!live.length)
return Number.isFinite(ground?.nowMs) &&
unseen(ground.nowMs, ground.onGroundNow)
? live
: keepTrailLimit(fixes, maxPoints);
const first = live[0];
live[0].breakBefore =
breakAfter ||
trailFixBreaks(last, first) ||
unseen(
first.timeMs,
typeof first.onGround === 'boolean'
? first.onGround
: ground?.onGroundNow,
);
return keepTrailLimit(fixes.concat(live), maxPoints); return keepTrailLimit(fixes.concat(live), maxPoints);
} }
@@ -499,9 +564,10 @@ function reportFrom(fixes, i) {
* @param {{x: number, y: number, z: number}} position - Owned position. * @param {{x: number, y: number, z: number}} position - Owned position.
* @param {number} timeMs - The report's epoch ms. * @param {number} timeMs - The report's epoch ms.
* @param {number} maxPoints - Point limit across all segments. * @param {number} maxPoints - Point limit across all segments.
* @param {{nullAltitude?: boolean, displayMs?: number, settleMs?: number}} [options] * @param {{nullAltitude?: boolean, displayMs?: number, settleMs?: number, onGround?: boolean}} [options]
* `displayMs`: the time the aircraft is drawn at as the report arrives; * `displayMs`: the time the aircraft is drawn at as the report arrives;
* `settleMs`: how long the icon takes to ease onto a correction. * `settleMs`: how long the icon takes to ease onto a correction;
* `onGround`: whether the report was on the ground, when known.
* @returns {object[]} `fixes`. * @returns {object[]} `fixes`.
*/ */
export function insertTrailFix( export function insertTrailFix(
@@ -509,7 +575,12 @@ export function insertTrailFix(
position, position,
timeMs, timeMs,
maxPoints, maxPoints,
{ nullAltitude = false, displayMs = NaN, settleMs = 0 } = {}, {
nullAltitude = false,
displayMs = NaN,
settleMs = 0,
onGround = undefined,
} = {},
) { ) {
const entry = { const entry = {
position: nullAltitude ? null : position, position: nullAltitude ? null : position,
@@ -518,6 +589,9 @@ export function insertTrailFix(
drawn: false, drawn: false,
breakBefore: false, breakBefore: false,
}; };
// Whether the report was on the ground, when known: a history backfill
// joins it only across a landing or take-off it saw.
if (typeof onGround === 'boolean') entry.onGround = onGround;
let i = insertionIndex(fixes, timeMs); let i = insertionIndex(fixes, timeMs);
// The guess drawn after a report the display already passed. // The guess drawn after a report the display already passed.
fixes.splice(i, reportFrom(fixes, i) - i); fixes.splice(i, reportFrom(fixes, i) - i);
+105
View File
@@ -0,0 +1,105 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import {
joinTrailBackfill,
trailGroundTransitionBreaks,
} from './trailContinuity.js';
// A history backfill that ends in the air does not join an aircraft now on
// the ground (or the reverse) across a landing or take-off nobody saw: a
// parked plane's track history is often its last flight.
const MIN = 60_000;
const LIMIT = 2_000;
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-122.21, 37.7, 0),
);
const at = (e, n, u) =>
Cesium.Matrix4.multiplyByPoint(
enu,
new Cesium.Cartesian3(e, n, u),
new Cesium.Cartesian3(),
);
const fix = (position, timeMs) => ({
position,
timeMs,
nullAltitude: false,
drawn: false,
breakBefore: false,
});
/** The last flight's final waypoint: 5.8 km up, 35 minutes before the taxi. */
const lastFlight = () => ({
fixes: [fix(at(0, 900, 5_800), 0)],
breakAfter: false,
});
const taxi = () => [fix(at(0, 0, 2), 35 * MIN), fix(at(40, -20, 2), 36 * MIN)];
test('an unseen landing or take-off breaks the join', () => {
assert.equal(trailGroundTransitionBreaks(false, true, 35 * MIN), true);
assert.equal(trailGroundTransitionBreaks(true, false, 35 * MIN), true);
assert.equal(trailGroundTransitionBreaks(false, true, 4 * MIN), false);
assert.equal(trailGroundTransitionBreaks(false, false, 35 * MIN), false);
assert.equal(trailGroundTransitionBreaks(true, true, 35 * MIN), false);
});
test('an airborne history does not join a taxiing aircraft', () => {
const joined = joinTrailBackfill(lastFlight(), taxi(), LIMIT, {
backfillEndsOnGround: false,
onGroundNow: true,
nowMs: 36 * MIN,
});
assert.equal(joined.length, 3);
assert.equal(joined[1].breakBefore, true);
});
test('without the ground state the join is unchanged', () => {
const joined = joinTrailBackfill(lastFlight(), taxi(), LIMIT);
assert.equal(joined[1].breakBefore, false);
});
test('a landing seen in the history still joins', () => {
const history = {
fixes: [fix(at(0, 900, 300), 31 * MIN)],
breakAfter: false,
};
const joined = joinTrailBackfill(history, taxi(), LIMIT, {
backfillEndsOnGround: false,
onGroundNow: true,
nowMs: 36 * MIN,
});
assert.equal(joined[1].breakBefore, false);
});
test('with no live fix, an unseen transition leaves the history out', () => {
const ground = {
backfillEndsOnGround: false,
onGroundNow: true,
nowMs: 35 * MIN,
};
assert.deepEqual(joinTrailBackfill(lastFlight(), [], LIMIT, ground), []);
assert.equal(
joinTrailBackfill(lastFlight(), [], LIMIT, {
...ground,
onGroundNow: false,
}).length,
1,
);
});
test('the first live report decides, not the aircraft now', () => {
// Held short with no history waypoints, then took off inside the live
// window: the history and the first live report are both on the ground.
const held = {
fixes: [fix(at(0, 0, 2), 0)],
breakAfter: false,
};
const live = taxi().map((f) => ({ ...f, onGround: true }));
const joined = joinTrailBackfill(held, live, LIMIT, {
backfillEndsOnGround: true,
onGroundNow: false,
nowMs: 36 * MIN,
});
assert.equal(joined[1].breakBefore, false);
});
+3
View File
@@ -113,6 +113,9 @@ export function createFlightSnapshotRenderer({
// Drawn at an invented height: a trail seeded from history keeps no // Drawn at an invented height: a trail seeded from history keeps no
// position for it. // position for it.
inventedHeight: meta.renderAltitudeInvented === true, inventedHeight: meta.renderAltitudeInvented === true,
// Whether this report was on the ground: a trail backfill joins it
// only across a landing or take-off it saw.
onGround: meta.onGround === true,
}); });
if (history.length > POSITION_HISTORY_LIMIT) { if (history.length > POSITION_HISTORY_LIMIT) {
history.shift(); history.shift();
+8 -1
View File
@@ -550,7 +550,7 @@ export function createTracking({
clone(fix.position), clone(fix.position),
historyFixEpochMs(fix), historyFixEpochMs(fix),
TRAIL_MAX_POINTS, TRAIL_MAX_POINTS,
{ nullAltitude: fix.inventedHeight === true }, { nullAltitude: fix.inventedHeight === true, onGround: fix.onGround },
); );
} }
if (!flightState._trail && flightState._viewer) { if (!flightState._trail && flightState._viewer) {
@@ -677,10 +677,17 @@ export function createTracking({
}; };
}), }),
); );
// A history that ends in the air does not join an aircraft now on the
// ground (or the reverse) across a landing or take-off nobody saw.
flightState._trailFixes = joinTrailBackfill( flightState._trailFixes = joinTrailBackfill(
backfill, backfill,
flightState._trailFixes, flightState._trailFixes,
TRAIL_MAX_POINTS, TRAIL_MAX_POINTS,
{
backfillEndsOnGround: parsed[parsed.length - 1].onGround,
onGroundNow: flightState.records.data.get(icao24)?.onGround,
nowMs: flightState.now(),
},
); );
_refreshTrailDisplay(); _refreshTrailDisplay();
} }
+3
View File
@@ -87,6 +87,9 @@ export function createMilitarySnapshotRenderer({
// Drawn at an invented height: a trail seeded from history keeps no // Drawn at an invented height: a trail seeded from history keeps no
// position for it. // position for it.
inventedHeight: meta.renderAltitudeInvented === true, inventedHeight: meta.renderAltitudeInvented === true,
// Whether this report was on the ground: a trail backfill joins it
// only across a landing or take-off it saw.
onGround: meta.onGround === true,
}); });
if (history.length > POSITION_HISTORY_LIMIT) { if (history.length > POSITION_HISTORY_LIMIT) {
history.shift(); history.shift();
+8 -1
View File
@@ -752,7 +752,7 @@ export function createTracking({
_trailFloorPosition(clone(fix.position)), _trailFloorPosition(clone(fix.position)),
historyFixEpochMs(fix), historyFixEpochMs(fix),
TRAIL_MAX_POINTS, TRAIL_MAX_POINTS,
{ nullAltitude: fix.inventedHeight === true }, { nullAltitude: fix.inventedHeight === true, onGround: fix.onGround },
); );
} }
if (!flightState._trail && flightState._viewer) { if (!flightState._trail && flightState._viewer) {
@@ -881,10 +881,17 @@ export function createTracking({
}; };
}), }),
); );
// A history that ends in the air does not join an aircraft now on the
// ground (or the reverse) across a landing or take-off nobody saw.
flightState._trailFixes = joinTrailBackfill( flightState._trailFixes = joinTrailBackfill(
backfill, backfill,
flightState._trailFixes, flightState._trailFixes,
TRAIL_MAX_POINTS, TRAIL_MAX_POINTS,
{
backfillEndsOnGround: parsed[parsed.length - 1].onGround,
onGroundNow: flightState.records.data.get(icao24)?.onGround,
nowMs: flightState.now(),
},
); );
_refreshTrailDisplay(); _refreshTrailDisplay();
} }