An estimated aircraft position stands in on the trail only until the next received one (#1817)

* An estimated aircraft position stands in on the trail only until the next received one

* Changelog fragment for #1817
This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-18 14:05:39 -08:00
1 parent 522f5b415d
commit d6972f8b78
8 files changed
+126 -8

No files matched your search

+33 -3
View File
@@ -410,6 +410,25 @@ function keepTrailLimit(fixes, maxPoints) {
return fixes;
}
/**
* Take the estimated reports out of the trail, judging again the break before
* each report that followed one.
*/
function dropEstimatedFixes(fixes) {
let dropped = false;
let kept = 0;
for (const fix of fixes) {
if (fix.estimated) {
dropped = true;
continue;
}
if (dropped) fix.breakBefore = trailFixBreaks(fixes[kept - 1], fix);
dropped = false;
fixes[kept++] = fix;
}
fixes.length = kept;
}
/** Index a fix at `timeMs` goes in at: after every entry at or before it. */
function insertionIndex(fixes, timeMs) {
let i = fixes.length;
@@ -425,9 +444,13 @@ function insertionIndex(fixes, timeMs) {
* @param {{x: number, y: number, z: number}} position - Owned position.
* @param {number} timeMs - The report's epoch ms.
* @param {number} maxPoints - Point limit across all segments.
* @param {{nullAltitude?: boolean, onGround?: boolean, track?: number}} [options]
* @param {{nullAltitude?: boolean, onGround?: boolean, track?: number, estimated?: boolean}} [options]
* `onGround`: whether the report was on the ground, when known;
* `track`: its reported track, which the curve leaves it along.
* `track`: its reported track, which the curve leaves it along;
* `estimated`: the feed estimated the position rather than received it. An
* estimated report stands in only until the next received one, which takes
* every estimated report out of the trail: the line runs between received
* positions, never through a feed's guesses and the jump back.
* @returns {object[]} `fixes`.
*/
export function insertTrailFix(
@@ -435,14 +458,21 @@ export function insertTrailFix(
position,
timeMs,
maxPoints,
{ nullAltitude = false, onGround = undefined, track = undefined } = {},
{
nullAltitude = false,
onGround = undefined,
track = undefined,
estimated = false,
} = {},
) {
if (!estimated) dropEstimatedFixes(fixes);
const entry = {
position: nullAltitude ? null : position,
timeMs,
nullAltitude,
breakBefore: false,
};
if (estimated) entry.estimated = true;
if (Number.isFinite(track)) entry.track = track;
// Whether the report was on the ground, when known: a history backfill
// joins it only across a landing or take-off it saw.
+29
View File
@@ -109,6 +109,35 @@ test('a report with no altitude keeps no position and breaks the line', () => {
assert.equal(trailBodySegments(fixes, fixes.length).length, 2);
});
test('an estimated report stands in only until the next received one', () => {
// Out of receiver range a feed carries the aircraft on its last course; the
// next received report is 900 m off that line. The guesses go, so the line
// runs received report to received report.
const fixes = [];
insertTrailFix(fixes, at(0, 0), 0, LIMIT);
insertTrailFix(fixes, at(1_500, 0), 15 * SEC, LIMIT, { estimated: true });
insertTrailFix(fixes, at(3_000, 0), 30 * SEC, LIMIT, { estimated: true });
assert.equal(fixes.length, 3);
assert.equal(fixes[2].estimated, true);
insertTrailFix(fixes, at(4_500, -900), 45 * SEC, LIMIT);
assert.deepEqual(
fixes.map((fix) => [fix.timeMs, fix.estimated === true]),
[
[0, false],
[45 * SEC, false],
],
);
// 45 s and 4.6 km apart: still one path, joined.
assert.equal(fixes[1].breakBefore, false);
// A received report a sweep late, older than the guesses, takes them out too.
insertTrailFix(fixes, at(6_000, -900), 60 * SEC, LIMIT, { estimated: true });
insertTrailFix(fixes, at(5_000, -900), 50 * SEC, LIMIT);
assert.deepEqual(
fixes.map((fix) => fix.timeMs),
[0, 45 * SEC, 50 * SEC],
);
});
test('a report arriving late goes in time order and the curve stays smooth', () => {
const fixes = [];
for (const t of [0, 30, 15, 45])