mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
The followed aircraft's trail runs to where the aircraft is drawn
When an application places live contacts itself, the tracked trail was cut at the layer's own delayed clock, which can run minutes behind the placed aircraft: the trail ended far behind the aircraft, and its head was dropped while that clock warmed up. The trail now reads the aircraft's time off its own reports at the point where it is drawn, for Flights and Military Flights.
This commit is contained in:
1 parent
2f0c01eaa7
commit
914b28822a
10 files changed
+374
-15
No files matched your search
@@ -452,6 +452,8 @@ export function createMotion({
|
||||
const sameTrack =
|
||||
flightState._drReconcileValid && flightState._drReconcileIcao === icao24;
|
||||
const raw = _deadReckon(icao24, flightState._scratchDrRaw);
|
||||
flightState._cachedDRPlaced =
|
||||
Boolean(raw) && flightState._drSpeedPlaced === true;
|
||||
flightState._cachedDRCourse = flightState._drCourseDeg;
|
||||
flightState._cachedDRSpeedMps = flightState._drSpeedMps;
|
||||
flightState._cachedDRHold = flightState._drCourseHold;
|
||||
@@ -597,6 +599,16 @@ export function createMotion({
|
||||
* against the now-stable plane (the model's jitter fix, resurfacing in the labels). Returns null when
|
||||
* there's no valid fix for the tracked aircraft, so callers fall back to the icon position. */
|
||||
|
||||
/** Whether a host-supplied placement placed the tracked aircraft where
|
||||
* `_trackedDisplayCached` holds it this frame, rather than this layer's
|
||||
* own motion at its display delay. */
|
||||
|
||||
function _trackedPlaced() {
|
||||
return (
|
||||
_trackedDisplayCached() !== null && flightState._cachedDRPlaced === true
|
||||
);
|
||||
}
|
||||
|
||||
function _trackedDisplayCached() {
|
||||
return flightState._drReconcileValid &&
|
||||
flightState._drReconcileIcao === flightState._trackedIcao
|
||||
@@ -1217,6 +1229,7 @@ export function createMotion({
|
||||
_trackedFocusSizePx,
|
||||
_trackedDisplayPosition,
|
||||
_trackedDisplayCached,
|
||||
_trackedPlaced,
|
||||
_trackedVisualCached,
|
||||
_trackedModelCenterWorld,
|
||||
_trackedModelEnvelopeM,
|
||||
|
||||
@@ -272,6 +272,12 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._drSpeedPlaced = false;
|
||||
|
||||
/** Sibling of `_cachedDRPosition`: whether a host-supplied placement placed
|
||||
* it (`_drSpeedPlaced` as the tracked aircraft was drawn), so its trail
|
||||
* ends where it is drawn rather than at the layer's display delay. */
|
||||
|
||||
flightState._cachedDRPlaced = false;
|
||||
|
||||
flightState._drCourseHold = false;
|
||||
|
||||
/** Sibling scratch: whether the position `_deadReckon` just returned came from
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
trailBodySegments,
|
||||
trailHeadCurvePoints,
|
||||
trailHeadStartFix,
|
||||
trailTimeAt,
|
||||
} from '../../data/trailContinuity.js';
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
@@ -396,12 +397,46 @@ export function createTracking({
|
||||
);
|
||||
}
|
||||
|
||||
/** Reports at or before the time the aircraft is drawn (now − the display delay). */
|
||||
/** Reports at or before the time the aircraft is drawn (`_trailDisplayMs`). */
|
||||
|
||||
function _trailBodyCountNow() {
|
||||
return trailBodyCount(
|
||||
return trailBodyCount(flightState._trailFixes, _trailDisplayMs());
|
||||
}
|
||||
|
||||
/**
|
||||
* The time on its trail at which a host-supplied placement draws the
|
||||
* aircraft, read off the trail where it is drawn (`trailTimeAt`): such a
|
||||
* placement draws at a delay of its own, not this layer's. NaN when this
|
||||
* layer's own motion draws it, or the trail has no pair to read.
|
||||
* @returns {number} Epoch ms or NaN.
|
||||
*/
|
||||
function _placedTrailMs() {
|
||||
if (!parts.motion._trackedPlaced?.()) return NaN;
|
||||
return trailTimeAt(
|
||||
flightState._trailFixes,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
parts.motion._trackedDisplayCached(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the trail runs up to: the time the aircraft is drawn at, now −
|
||||
* the display delay, or where a placement draws it. Otherwise the trail
|
||||
* ends short of a placed aircraft, or runs on ahead of it.
|
||||
* @returns {number} Epoch ms.
|
||||
*/
|
||||
function _trailDisplayMs() {
|
||||
const placedMs = _placedTrailMs();
|
||||
return Number.isFinite(placedMs)
|
||||
? placedMs
|
||||
: flightState.now() - displayDelayMs(flightState);
|
||||
}
|
||||
|
||||
/** Whether the trail holds no report behind the aircraft yet: this
|
||||
* layer's own motion draws it before its oldest fix. Never for an
|
||||
* aircraft a placement draws: its trail is read where it is drawn. */
|
||||
function _trailWarmingUp() {
|
||||
return (
|
||||
!Number.isFinite(_placedTrailMs()) && parts.motion._isTrackWarmingUp()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -418,7 +453,7 @@ export function createTracking({
|
||||
if (
|
||||
!flightState._trackedIcao ||
|
||||
!flightState._trailFixes.length ||
|
||||
parts.motion._isTrackWarmingUp()
|
||||
_trailWarmingUp()
|
||||
)
|
||||
return [];
|
||||
const head =
|
||||
@@ -441,7 +476,7 @@ export function createTracking({
|
||||
trailHeadCurvePoints(
|
||||
flightState._trailFixes,
|
||||
flightState._trailBodyCount,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
_trailDisplayMs(),
|
||||
),
|
||||
head,
|
||||
parts.motion._trackedModelCenterWorld(),
|
||||
|
||||
@@ -4,7 +4,12 @@ import * as Cesium from 'cesium';
|
||||
import { createFlightState } from './state.js';
|
||||
import { createTracking } from './tracking.js';
|
||||
import { TRAIL_MAX_POINTS } from './policy.js';
|
||||
import { trailHeadJoins, trailPairBreaks } from '../../data/trailContinuity.js';
|
||||
import {
|
||||
insertTrailFix,
|
||||
trailHeadJoins,
|
||||
trailPairBreaks,
|
||||
trailTimeAt,
|
||||
} from '../../data/trailContinuity.js';
|
||||
|
||||
const MINUTE = 60_000;
|
||||
const HOUR = 60 * MINUTE;
|
||||
@@ -92,6 +97,8 @@ function trackedHarness({
|
||||
nowMs,
|
||||
floor,
|
||||
head = null,
|
||||
placed = false,
|
||||
warmingUp = false,
|
||||
} = {}) {
|
||||
const trail = recordingTrail();
|
||||
const svc = services({ trails: trail, floor });
|
||||
@@ -122,7 +129,9 @@ function trackedHarness({
|
||||
services: svc,
|
||||
parts: {
|
||||
motion: {
|
||||
_isTrackWarmingUp: () => false,
|
||||
_isTrackWarmingUp: () => warmingUp,
|
||||
_trackedPlaced: () => placed,
|
||||
_trackedDisplayCached: () => head,
|
||||
_trackedTrailCached: () => head,
|
||||
_trackedDisplayPosition: () => head,
|
||||
_trackedModelCenterWorld: () => null,
|
||||
@@ -410,3 +419,136 @@ test('every waypoint of a 24 h history survives, and the trail stays within TRAI
|
||||
// The oldest go first: the newest live fix is still the last point.
|
||||
assert.equal(fixes[fixes.length - 1].timeMs, liveStart);
|
||||
});
|
||||
|
||||
/** A trail of `count` reports one minute apart flying east from (50, 1). */
|
||||
function eastTrail(t0, count) {
|
||||
const fixes = [];
|
||||
for (let i = 0; i < count; i++)
|
||||
insertTrailFix(
|
||||
fixes,
|
||||
Cesium.Cartesian3.fromDegrees(1 + i * 0.12, 50, 10_000),
|
||||
t0 + i * MINUTE,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
return fixes;
|
||||
}
|
||||
|
||||
test('the time on the trail is read where the aircraft is drawn', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const fixes = eastTrail(t0, 4);
|
||||
const at = (lon) =>
|
||||
trailTimeAt(fixes, Cesium.Cartesian3.fromDegrees(lon, 50, 10_000));
|
||||
// Halfway between the second and third reports.
|
||||
assert.ok(Math.abs(at(1.18) - (t0 + 1.5 * MINUTE)) < 2_000);
|
||||
// On a report.
|
||||
assert.ok(Math.abs(at(1.24) - (t0 + 2 * MINUTE)) < 2_000);
|
||||
// Past the newest report the time runs on; before the oldest it runs back.
|
||||
assert.ok(Math.abs(at(1.42) - (t0 + 3.5 * MINUTE)) < 2_000);
|
||||
assert.ok(Math.abs(at(0.94) - (t0 - 0.5 * MINUTE)) < 2_000);
|
||||
// Nothing to read without a pair of reports, or without a position.
|
||||
assert.ok(Number.isNaN(trailTimeAt(fixes.slice(0, 1), fixes[0].position)));
|
||||
assert.ok(Number.isNaN(trailTimeAt(fixes, null)));
|
||||
});
|
||||
|
||||
test('the time on the trail is never read across a break', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const fixes = eastTrail(t0, 2);
|
||||
// An hour later, far on: a new segment.
|
||||
insertTrailFix(
|
||||
fixes,
|
||||
Cesium.Cartesian3.fromDegrees(20, 50, 10_000),
|
||||
t0 + HOUR,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
insertTrailFix(
|
||||
fixes,
|
||||
Cesium.Cartesian3.fromDegrees(20.12, 50, 10_000),
|
||||
t0 + HOUR + MINUTE,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
assert.equal(fixes[2].breakBefore, true);
|
||||
// Halfway along the gap is not on the trail: it is read on the newest pair.
|
||||
const at = trailTimeAt(fixes, Cesium.Cartesian3.fromDegrees(10, 50, 10_000));
|
||||
assert.ok(at <= t0 + HOUR, `read ${at - t0} ms in, across the break`);
|
||||
});
|
||||
|
||||
test('a placed aircraft drawn ahead of the display delay keeps its trail joined to it', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const liveFixes = [0, 1, 2, 3].map((i) => ({
|
||||
timeMs: t0 + i * MINUTE,
|
||||
lat: 50,
|
||||
lon: 1 + i * 0.12,
|
||||
}));
|
||||
// The layer's own delay puts the aircraft before its first fix (warming
|
||||
// up), but the placement draws it between the third and fourth reports.
|
||||
const near = Cesium.Cartesian3.fromDegrees(1.3, 50, 10_000);
|
||||
const placed = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 3.5 * MINUTE,
|
||||
head: near,
|
||||
placed: true,
|
||||
warmingUp: true,
|
||||
});
|
||||
placed.flightState._displayDelay = { currentMs: 10 * MINUTE };
|
||||
placed.tracking._startTrail('abc123');
|
||||
// The body runs to the last report behind the aircraft, none ahead of it.
|
||||
assert.deepEqual(
|
||||
placed.trail.last().map((segment) => segment.length > 0),
|
||||
[true],
|
||||
);
|
||||
const body = placed.trail.last()[0];
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(
|
||||
body[body.length - 1],
|
||||
Cesium.Cartesian3.fromDegrees(1.24, 50, 10_000),
|
||||
) < 1,
|
||||
);
|
||||
// The head joins it to the aircraft.
|
||||
const drawn = headPositions(placed);
|
||||
assert.ok(drawn.length >= 2);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[0], body[body.length - 1]) < 1);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[drawn.length - 1], near) < 1e-6);
|
||||
|
||||
// The layer's own motion, warming up, draws no head and no body.
|
||||
const own = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 3.5 * MINUTE,
|
||||
head: near,
|
||||
warmingUp: true,
|
||||
});
|
||||
own.flightState._displayDelay = { currentMs: 10 * MINUTE };
|
||||
own.tracking._startTrail('abc123');
|
||||
assert.deepEqual(own.trail.last(), []);
|
||||
assert.deepEqual(headPositions(own), []);
|
||||
});
|
||||
|
||||
test('a placed aircraft drawn behind the display delay has no trail ahead of it', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const liveFixes = [0, 1, 2, 3].map((i) => ({
|
||||
timeMs: t0 + i * MINUTE,
|
||||
lat: 50,
|
||||
lon: 1 + i * 0.12,
|
||||
}));
|
||||
// The layer's delay would draw every report; the placement holds the
|
||||
// aircraft between the first and second.
|
||||
const behind = Cesium.Cartesian3.fromDegrees(1.06, 50, 10_000);
|
||||
const { trail, tracking, flightState } = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 4 * MINUTE,
|
||||
head: behind,
|
||||
placed: true,
|
||||
});
|
||||
flightState._displayDelay = { currentMs: 0 };
|
||||
tracking._startTrail('abc123');
|
||||
// One report behind it: no line yet, and nothing ahead of the aircraft.
|
||||
assert.deepEqual(trail.last(), []);
|
||||
const drawn = headPositions({ tracking });
|
||||
assert.equal(drawn.length, 2);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(
|
||||
drawn[0],
|
||||
Cesium.Cartesian3.fromDegrees(1, 50, 10_000),
|
||||
) < 1,
|
||||
);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[1], behind) < 1e-6);
|
||||
});
|
||||
@@ -349,6 +349,8 @@ export function createMotion({
|
||||
const sameTrack =
|
||||
flightState._drReconcileValid && flightState._drReconcileIcao === icao24;
|
||||
const raw = _deadReckon(icao24, flightState._scratchDrRaw);
|
||||
flightState._cachedDRPlaced =
|
||||
Boolean(raw) && flightState._drSpeedPlaced === true;
|
||||
flightState._cachedDRCourse = flightState._drCourseDeg;
|
||||
flightState._cachedDRSpeedMps = flightState._drSpeedMps;
|
||||
flightState._cachedDRHold = flightState._drCourseHold;
|
||||
@@ -475,6 +477,16 @@ export function createMotion({
|
||||
* later in the frame, so recomputing _trackedDisplayPosition there jitters the label against the
|
||||
* now-stable plane. Null when no valid fix (callers fall back to the icon position). */
|
||||
|
||||
/** Whether a host-supplied placement placed the tracked aircraft where
|
||||
* `_trackedDisplayCached` holds it this frame, rather than this layer's
|
||||
* own motion at its display delay. */
|
||||
|
||||
function _trackedPlaced() {
|
||||
return (
|
||||
_trackedDisplayCached() !== null && flightState._cachedDRPlaced === true
|
||||
);
|
||||
}
|
||||
|
||||
function _trackedDisplayCached() {
|
||||
return flightState._drReconcileValid &&
|
||||
flightState._drReconcileIcao === flightState._trackedIcao
|
||||
@@ -697,6 +709,7 @@ export function createMotion({
|
||||
_trackedFocusSizePx,
|
||||
_trackedDisplayPosition,
|
||||
_trackedDisplayCached,
|
||||
_trackedPlaced,
|
||||
_trackedVisualCached,
|
||||
_trackedModelCenterWorld,
|
||||
_trackedModelEnvelopeM,
|
||||
|
||||
@@ -236,6 +236,12 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._drSpeedPlaced = false;
|
||||
|
||||
/** Sibling of `_cachedDRPosition`: whether a host-supplied placement placed
|
||||
* it (`_drSpeedPlaced` as the tracked aircraft was drawn), so its trail
|
||||
* ends where it is drawn rather than at the layer's display delay. */
|
||||
|
||||
flightState._cachedDRPlaced = false;
|
||||
|
||||
flightState._drCourseHold = false;
|
||||
|
||||
/** Set by `_deadReckon`: following the clock, the time drawn is well
|
||||
|
||||
@@ -49,6 +49,7 @@ import {
|
||||
trailBodySegments,
|
||||
trailHeadCurvePoints,
|
||||
trailHeadStartFix,
|
||||
trailTimeAt,
|
||||
} from '../../data/trailContinuity.js';
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
@@ -614,12 +615,46 @@ export function createTracking({
|
||||
);
|
||||
}
|
||||
|
||||
/** Reports at or before the time the aircraft is drawn (now − the display delay). */
|
||||
/** Reports at or before the time the aircraft is drawn (`_trailDisplayMs`). */
|
||||
|
||||
function _trailBodyCountNow() {
|
||||
return trailBodyCount(
|
||||
return trailBodyCount(flightState._trailFixes, _trailDisplayMs());
|
||||
}
|
||||
|
||||
/**
|
||||
* The time on its trail at which a host-supplied placement draws the
|
||||
* aircraft, read off the trail where it is drawn (`trailTimeAt`): such a
|
||||
* placement draws at a delay of its own, not this layer's. NaN when this
|
||||
* layer's own motion draws it, or the trail has no pair to read.
|
||||
* @returns {number} Epoch ms or NaN.
|
||||
*/
|
||||
function _placedTrailMs() {
|
||||
if (!parts.motion._trackedPlaced?.()) return NaN;
|
||||
return trailTimeAt(
|
||||
flightState._trailFixes,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
parts.motion._trackedDisplayCached(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the trail runs up to: the time the aircraft is drawn at, now −
|
||||
* the display delay, or where a placement draws it. Otherwise the trail
|
||||
* ends short of a placed aircraft, or runs on ahead of it.
|
||||
* @returns {number} Epoch ms.
|
||||
*/
|
||||
function _trailDisplayMs() {
|
||||
const placedMs = _placedTrailMs();
|
||||
return Number.isFinite(placedMs)
|
||||
? placedMs
|
||||
: flightState.now() - displayDelayMs(flightState);
|
||||
}
|
||||
|
||||
/** Whether the trail holds no report behind the aircraft yet: this
|
||||
* layer's own motion draws it before its oldest fix. Never for an
|
||||
* aircraft a placement draws: its trail is read where it is drawn. */
|
||||
function _trailWarmingUp() {
|
||||
return (
|
||||
!Number.isFinite(_placedTrailMs()) && parts.motion._isTrackWarmingUp()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -636,7 +671,7 @@ export function createTracking({
|
||||
if (
|
||||
!flightState._trackedIcao ||
|
||||
!flightState._trailFixes.length ||
|
||||
parts.motion._isTrackWarmingUp()
|
||||
_trailWarmingUp()
|
||||
)
|
||||
return [];
|
||||
const head =
|
||||
@@ -664,7 +699,7 @@ export function createTracking({
|
||||
trailHeadCurvePoints(
|
||||
flightState._trailFixes,
|
||||
flightState._trailBodyCount,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
_trailDisplayMs(),
|
||||
),
|
||||
end,
|
||||
parts.motion._trackedModelCenterWorld(),
|
||||
|
||||
@@ -65,7 +65,15 @@ function recordingTrail() {
|
||||
};
|
||||
}
|
||||
|
||||
function trackedHarness({ liveFixes = [], trace = null, nowMs, floor, head }) {
|
||||
function trackedHarness({
|
||||
liveFixes = [],
|
||||
trace = null,
|
||||
nowMs,
|
||||
floor,
|
||||
head,
|
||||
placed = false,
|
||||
warmingUp = false,
|
||||
}) {
|
||||
const trail = recordingTrail();
|
||||
const svc = services({ trails: trail, floor });
|
||||
const flightState = createFlightState({
|
||||
@@ -104,7 +112,9 @@ function trackedHarness({ liveFixes = [], trace = null, nowMs, floor, head }) {
|
||||
services: svc,
|
||||
parts: {
|
||||
motion: {
|
||||
_isTrackWarmingUp: () => false,
|
||||
_isTrackWarmingUp: () => warmingUp,
|
||||
_trackedPlaced: () => placed,
|
||||
_trackedDisplayCached: () => head ?? null,
|
||||
_trackedTrailCached: () => head ?? null,
|
||||
_trackedDisplayPosition: () => head ?? null,
|
||||
_trackedModelCenterWorld: () => null,
|
||||
@@ -256,3 +266,36 @@ test('a full 24 h military trace fits within TRAIL_MAX_POINTS without thinning',
|
||||
assert.ok(TRAIL_MAX_POINTS >= day + 500);
|
||||
assert.equal(flightState._trailFixes.length, day + 1);
|
||||
});
|
||||
|
||||
test('a placed military aircraft drawn ahead of the display delay keeps its trail joined to it', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const liveFixes = [0, 1, 2, 3].map((i) => ({
|
||||
timeMs: t0 + i * MINUTE,
|
||||
lat: 50,
|
||||
lon: 1 + i * 0.12,
|
||||
}));
|
||||
// Warming up by the layer's own delay; the placement draws it between the
|
||||
// third and fourth reports.
|
||||
const near = Cesium.Cartesian3.fromDegrees(1.3, 50, 9_000);
|
||||
const harness = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 3.5 * MINUTE,
|
||||
head: near,
|
||||
placed: true,
|
||||
warmingUp: true,
|
||||
});
|
||||
harness.flightState._displayDelay = { currentMs: 10 * MINUTE };
|
||||
harness.tracking._startTrail('ae0001');
|
||||
const body = harness.trail.last()[0];
|
||||
assert.equal(harness.trail.last().length, 1);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(
|
||||
body[body.length - 1],
|
||||
Cesium.Cartesian3.fromDegrees(1.24, 50, 9_000),
|
||||
) < 1,
|
||||
);
|
||||
const drawn = harness.headPositions();
|
||||
assert.ok(drawn.length >= 2);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[0], body[body.length - 1]) < 1);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[drawn.length - 1], near) < 1);
|
||||
});
|
||||
Reference in new issue
Block a user