mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
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:
1 parent
c57eb74506
commit
5f98f8bdf3
40 files changed
+2606
-1238
No files matched your search
@@ -0,0 +1,6 @@
|
||||
import { feedLatencyTests } from '../../testSupport/aircraftFeedLatency.mjs';
|
||||
import { RENDER_DELAY_SEC } from './policy.js';
|
||||
|
||||
// A slow live feed, as measured: reports about 90 s old every poll, now and
|
||||
// then a fresh fallback feed, a report that does not move on, or an outage.
|
||||
feedLatencyTests('military', RENDER_DELAY_SEC);
|
||||
@@ -2,7 +2,6 @@ import { createAircraftIcons } from '../../data/aircraftIconLayer.js';
|
||||
import {
|
||||
COCKPIT_CONTACT_SIZE_PX,
|
||||
COURSE_MAX_DPS,
|
||||
RENDER_DELAY_SEC,
|
||||
STALE_ALPHA,
|
||||
followsClock,
|
||||
} from './policy.js';
|
||||
@@ -14,7 +13,7 @@ export function createIcons({ flightState, services, parts }) {
|
||||
services,
|
||||
parts,
|
||||
layerId: 'military',
|
||||
renderDelaySec: RENDER_DELAY_SEC,
|
||||
displayDelay: flightState._displayDelay,
|
||||
followsClock: () => followsClock(flightState),
|
||||
staleAlpha: STALE_ALPHA,
|
||||
courseMaxDps: COURSE_MAX_DPS,
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { canvasOf, findCamera } from '../../render/rendererOf.js';
|
||||
import { renderedFrames } from '../../data/renderedFrames.js';
|
||||
import {
|
||||
motionCourse,
|
||||
motionPosition,
|
||||
} from '../../render/motion/iconMotion.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { eastNorthUp, framePoint } from '../../geo/frames.js';
|
||||
import {
|
||||
addSeconds,
|
||||
julianLessThan,
|
||||
julianFromEpochMs,
|
||||
julianToEpochMs,
|
||||
secondsDifference,
|
||||
} from '../../geo/julian.js';
|
||||
import {
|
||||
@@ -25,6 +30,8 @@ import {
|
||||
staleHoldsForFix,
|
||||
arcOffsetEnu,
|
||||
courseSlewCapDps,
|
||||
RECOVER_SNAP_M,
|
||||
recoveryMs,
|
||||
limitCourseStep,
|
||||
} from '../../data/motionModel.js';
|
||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||
@@ -102,8 +109,8 @@ export function createMotion({
|
||||
/**
|
||||
* Dead-reckon an aircraft's current position using ENU (East-North-Up) frame math.
|
||||
*
|
||||
* Renders one poll interval behind real time so positions interpolate between
|
||||
* two KNOWN fixes whenever possible (see RENDER_DELAY_SEC rationale). When the
|
||||
* Renders behind real time, as late as the feed is (displayDelayMs), so
|
||||
* positions interpolate between two KNOWN fixes whenever possible. When the
|
||||
* newest fix is older than the delayed render time (stale position), projects
|
||||
* forward using the aircraft's ground speed and track through the freshest
|
||||
* source contact plus a bounded grace window.
|
||||
@@ -113,7 +120,7 @@ export function createMotion({
|
||||
* @returns {{x: number, y: number, z: number}|null} Estimated current ECEF position, or null if no history
|
||||
*/
|
||||
|
||||
function _deadReckon(icao24, result) {
|
||||
function _deadReckon(icao24, result, sampledRenderTime) {
|
||||
const history = flightState._positionHistory.get(icao24);
|
||||
const info = flightState.records.data.get(icao24);
|
||||
if (!history || history.length === 0) {
|
||||
@@ -124,15 +131,26 @@ export function createMotion({
|
||||
}
|
||||
|
||||
const out = result || vec();
|
||||
// Render one poll interval behind real time so we interpolate between
|
||||
// two KNOWN fixes whenever possible (see RENDER_DELAY_SEC rationale).
|
||||
const renderTime = addSeconds(
|
||||
julianFromEpochMs(flightState.now()),
|
||||
-displayDelayMs(flightState) / 1000,
|
||||
flightState._scratchRenderTime,
|
||||
);
|
||||
// Render behind real time, as late as the feed is (displayDelayMs), so we
|
||||
// interpolate between two KNOWN fixes whenever possible.
|
||||
const renderTime =
|
||||
sampledRenderTime ??
|
||||
addSeconds(
|
||||
julianFromEpochMs(flightState.now()),
|
||||
-displayDelayMs(flightState) / 1000,
|
||||
flightState._scratchRenderTime,
|
||||
);
|
||||
|
||||
const regime = _motionRegime(history, info, renderTime);
|
||||
if (regime.kind === 'between' && regime.piece) {
|
||||
// Along the curve between the two reports, as the icon and the trail.
|
||||
const ms = julianToEpochMs(renderTime);
|
||||
const segment = regime.piece.segment;
|
||||
flightState._drCourseDeg = motionCourse(segment, undefined, ms);
|
||||
flightState._drSpeedMps = segment.speedMps;
|
||||
flightState._drCourseHold = segment.speedMps < COURSE_HOLD_SPEED_MPS;
|
||||
return copyInto(motionPosition(segment, null, ms), out);
|
||||
}
|
||||
if (regime.kind === 'between') {
|
||||
const { a, b, span } = regime;
|
||||
const t = span > 0 ? secondsDifference(renderTime, a.time) / span : 1.0;
|
||||
@@ -244,7 +262,7 @@ export function createMotion({
|
||||
}
|
||||
|
||||
/**
|
||||
* True while the tracked aircraft's delayed display time (now − RENDER_DELAY_SEC)
|
||||
* True while the tracked aircraft's delayed display time (now − displayDelayMs)
|
||||
* predates its oldest real fix — _deadReckon is extrapolating backward with no real
|
||||
* history yet behind the displayed icon, so the trail must draw nothing.
|
||||
* @returns {boolean}
|
||||
@@ -332,35 +350,64 @@ export function createMotion({
|
||||
// which plays faster than the wall clock when following it at a rate.
|
||||
const worldMs = followsClock(flightState) ? flightState.now() : nowMs;
|
||||
const info = flightState.records.data.get(icao24);
|
||||
const dtSec = Math.max(
|
||||
0.001,
|
||||
(worldMs - flightState._drPrevWorldMs) / 1000,
|
||||
);
|
||||
let snapped = false;
|
||||
if (sameTrack) {
|
||||
const dtSec = Math.max(
|
||||
0.001,
|
||||
(worldMs - flightState._drPrevWorldMs) / 1000,
|
||||
);
|
||||
const speed = (info && info.speedMps) || 0;
|
||||
// Plausible single-frame motion (m): real velocity × frame Δt, ×4 slack + 25 m base.
|
||||
const plausible = speed * dtSec * 4 + 25;
|
||||
// Plausible single-frame motion (m): its speed × frame Δt, half again
|
||||
// for slack, plus 5 m. More is a jump (a new report put it elsewhere).
|
||||
const plausible = speed * dtSec * 1.5 + 5;
|
||||
if (distance(raw, flightState._drPrevRaw) > plausible) {
|
||||
// Discontinuity — re-anchor so the DISPLAYED position stays continuous, then decay.
|
||||
copyInto(
|
||||
sub(flightState._drPrevDisplay, raw),
|
||||
flightState._drCorrection,
|
||||
);
|
||||
// Discontinuity — re-anchor so the DISPLAYED position stays continuous,
|
||||
// then ease onto the new path no faster than a little over its speed;
|
||||
// farther off than RECOVER_SNAP_M it is a break, and it jumps.
|
||||
// From where the icon would be this frame had it carried on as it
|
||||
// was moving, not from where it was last frame: it never stands
|
||||
// still for a frame.
|
||||
const anchor =
|
||||
flightState._drPrevStepSec > 0
|
||||
? add(
|
||||
flightState._drPrevDisplay,
|
||||
scale(
|
||||
flightState._drPrevStep,
|
||||
dtSec / flightState._drPrevStepSec,
|
||||
),
|
||||
)
|
||||
: flightState._drPrevDisplay;
|
||||
const errorM = distance(anchor, raw);
|
||||
snapped = errorM >= RECOVER_SNAP_M;
|
||||
copyInto(snapped ? vec() : sub(anchor, raw), flightState._drCorrection);
|
||||
flightState._drCorrectionStartMs = nowMs;
|
||||
flightState._drCorrectionMs = Math.max(
|
||||
DR_CORRECTION_MS,
|
||||
recoveryMs(errorM, speed),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
copyInto(vec(), flightState._drCorrection);
|
||||
flightState._drCorrectionStartMs = nowMs - DR_CORRECTION_MS; // fully decayed
|
||||
flightState._drCorrectionMs = DR_CORRECTION_MS;
|
||||
}
|
||||
|
||||
const elapsed = nowMs - flightState._drCorrectionStartMs;
|
||||
const factor =
|
||||
elapsed >= DR_CORRECTION_MS ? 0 : 1 - elapsed / DR_CORRECTION_MS;
|
||||
const easeMs = flightState._drCorrectionMs ?? DR_CORRECTION_MS;
|
||||
const factor = elapsed >= easeMs ? 0 : 1 - elapsed / easeMs;
|
||||
const display = copyInto(
|
||||
add(raw, scale(flightState._drCorrection, factor)),
|
||||
flightState._trackedPosHolder,
|
||||
);
|
||||
|
||||
// How the icon moved this frame, to carry it on through a re-anchor.
|
||||
if (sameTrack && !snapped) {
|
||||
copyInto(
|
||||
sub(display, flightState._drPrevDisplay),
|
||||
flightState._drPrevStep,
|
||||
);
|
||||
flightState._drPrevStepSec = dtSec;
|
||||
} else flightState._drPrevStepSec = 0;
|
||||
copyInto(raw, flightState._drPrevRaw);
|
||||
copyInto(display, flightState._drPrevDisplay);
|
||||
flightState._drPrevMs = nowMs;
|
||||
|
||||
@@ -14,9 +14,9 @@ const rgba = (css, alpha) =>
|
||||
* Renders aircraft as amber chevrons in one GPU icon set (iconSet.js), whose
|
||||
* shader dead-reckons and orients every row. Supports click-to-track: selecting an aircraft
|
||||
* spawns an Entity the camera follows, whose position is driven by a
|
||||
* dead-reckoning CallbackProperty. The whole fleet renders at
|
||||
* now - RENDER_DELAY_SEC so positions interpolate BETWEEN two known fixes
|
||||
* instead of extrapolating ahead and snapping back when the next poll lands.
|
||||
* dead-reckoning CallbackProperty. The whole fleet renders at now − the
|
||||
* display delay so positions run BETWEEN two known fixes instead of
|
||||
* extrapolating ahead and snapping back when the next poll lands.
|
||||
*/
|
||||
|
||||
/** @constant {number} Milliseconds to wait before retrying after a transient error */
|
||||
@@ -123,7 +123,7 @@ export const TRACKED_BILLBOARD_SCALE_BY_DISTANCE = Object.freeze({
|
||||
// ---------------------------------------------------------------------------
|
||||
// Track-history trail state (PRD WS-F F2/F4): a fading polyline behind the
|
||||
// tracked aircraft. The accumulation array is intentionally SEPARATE from
|
||||
// _positionHistory (capped at POSITION_HISTORY_LIMIT=5 for dead reckoning)
|
||||
// _positionHistory (capped at POSITION_HISTORY_LIMIT for drawing)
|
||||
// so the visible trail can grow to TRAIL_MAX_POINTS fixes.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -136,25 +136,33 @@ export const TRAIL_COLOR = '#FFB800';
|
||||
export const TRAIL_MAX_POINTS = 2000;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Render-behind smoothing (mirrors flights.js): the fleet renders at
|
||||
// now - RENDER_DELAY_SEC so positions interpolate BETWEEN two known fixes
|
||||
// instead of extrapolating ahead and snapping back when the next poll lands.
|
||||
// Removing the delay reintroduces the back/forward oscillation and is a
|
||||
// regression.
|
||||
// Render-behind smoothing (mirrors flights): the fleet renders at now − the
|
||||
// display delay so positions run BETWEEN two known fixes instead of
|
||||
// extrapolating ahead and snapping back when the next poll lands. The delay
|
||||
// follows how late the feed really is (data/displayDelay.js), never under
|
||||
// RENDER_DELAY_SEC, and every consumer shares it. Removing the delay
|
||||
// reintroduces the back/forward oscillation and is a regression.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** @constant {number} Display latency in seconds (= one poll interval). */
|
||||
/** @constant {number} The shortest display delay in seconds (one poll interval). */
|
||||
|
||||
export const RENDER_DELAY_SEC = 15;
|
||||
|
||||
/** @constant {number} How often the feed is polled (ms). */
|
||||
|
||||
export const POLL_INTERVAL_MS = 15_000;
|
||||
|
||||
/** Whether the layer shows the world clock's time instead of the live feed:
|
||||
* its source declares a timeline and the clock is away from live. */
|
||||
export const followsClock = (state) => state.timeline?.active() === true;
|
||||
|
||||
/** How far behind the time contacts are drawn: RENDER_DELAY_SEC live, none
|
||||
* following the clock, whose snapshots are loaded ahead of the time. */
|
||||
/** How far behind the time contacts are drawn (ms): the feed's display
|
||||
* delay live, none following the clock, whose snapshots are loaded ahead
|
||||
* of the time. */
|
||||
export const displayDelayMs = (state) =>
|
||||
followsClock(state) ? 0 : RENDER_DELAY_SEC * 1000;
|
||||
followsClock(state)
|
||||
? 0
|
||||
: (state._displayDelay?.currentMs ?? RENDER_DELAY_SEC * 1000);
|
||||
|
||||
/** @constant {number} Polls an aircraft may miss before removal (transient adsb.lol dropouts). */
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import {
|
||||
LANDED_ALT_MAX_FT,
|
||||
LANDED_SPEED_MAX_MPS,
|
||||
POLL_INTERVAL_MS,
|
||||
followsClock,
|
||||
} from './policy.js';
|
||||
import { emergencyBroadcastPhrase } from '../../data/aircraftEmergency.js';
|
||||
@@ -234,7 +235,7 @@ export function createQueries({
|
||||
source: flightState.feed._lastSource,
|
||||
|
||||
/** @type {number} Polling interval in ms between API fetches */
|
||||
updateInterval: 15000,
|
||||
updateInterval: POLL_INTERVAL_MS,
|
||||
|
||||
/** @deprecated Compatibility alias for {@link enable}. */
|
||||
show(viewer) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export const GROUND_FLOOR_WARM_MAX_ALT_M = 4500;
|
||||
|
||||
export const POSITION_HISTORY_LIMIT = 5;
|
||||
/** Maximum feed fixes retained for drawing: enough to reach back over the
|
||||
* longest display delay at one report per poll. */
|
||||
export const POSITION_HISTORY_LIMIT = 24;
|
||||
|
||||
export const LANDED_MISSING_POLL_LIMIT = 1;
|
||||
|
||||
|
||||
@@ -7,6 +7,30 @@ import {
|
||||
} from '../../data/motionModel.js';
|
||||
import { POSITION_HISTORY_LIMIT } from './recordPolicy.js';
|
||||
import { followsClock } from './policy.js';
|
||||
import { newestReport, pushReport } from '../../data/aircraftMotionRegime.js';
|
||||
|
||||
/**
|
||||
* Note how late each report in a live snapshot is, and aim the display delay
|
||||
* again, before any contact is planned with it: a layer drawing nothing yet
|
||||
* takes the new delay at once.
|
||||
*/
|
||||
function noteDelivery(flightState, snapshot) {
|
||||
const delay = flightState._displayDelay;
|
||||
if (!delay) return;
|
||||
const receiptMs = Date.now();
|
||||
for (const observation of snapshot.records) {
|
||||
const reportMs = observation.positionTimeMs;
|
||||
if (!(Number.isFinite(reportMs) && reportMs > 0)) continue;
|
||||
const history = flightState._positionHistory.get(observation.id);
|
||||
const previous = history && newestReport(history);
|
||||
delay.noteReport(
|
||||
receiptMs,
|
||||
reportMs,
|
||||
previous ? Math.trunc(previous.epochMs) : undefined,
|
||||
);
|
||||
}
|
||||
delay.settle(receiptMs, { jump: !flightState._icons.count });
|
||||
}
|
||||
|
||||
/** Apply military record changes to the layer's drawing and existing follow operations. */
|
||||
export function createMilitarySnapshotRenderer({
|
||||
@@ -32,6 +56,9 @@ export function createMilitarySnapshotRenderer({
|
||||
const currentIcaos = new Set();
|
||||
const receiptNowMs = snapshot.observedAtMs;
|
||||
records.beginSnapshot(snapshot.observedAtMs);
|
||||
// Live, the display delay follows how late this delivery's reports are.
|
||||
if (!replace && !followsClock(flightState))
|
||||
noteDelivery(flightState, snapshot);
|
||||
// Field-test fix (RS46): coarse floor cells to warm for the below-ground
|
||||
// clamp — collected during the loop (low airborne contacts only),
|
||||
// batch-resolved once after it. Never a fetch inside the loop.
|
||||
@@ -69,34 +96,37 @@ export function createMilitarySnapshotRenderer({
|
||||
}
|
||||
const history = flightState._positionHistory.get(icao24);
|
||||
const newest = history[history.length - 1];
|
||||
// Whole milliseconds, as the fix times are kept.
|
||||
const report = newestReport(history);
|
||||
// Whole milliseconds, as the fix times are kept. A report newer than
|
||||
// the last report goes in, past any synthetic fix after it.
|
||||
if (
|
||||
!newest ||
|
||||
Math.trunc(fixEpochMs) > Math.trunc(motion._fixEpochMs(newest))
|
||||
!report ||
|
||||
Math.trunc(fixEpochMs) > Math.trunc(motion._fixEpochMs(report))
|
||||
) {
|
||||
// Per-fix kinematics: the fix's own velocity/track ride along so the
|
||||
// extrapolation paths use the values that BELONG to the fix they
|
||||
// extend, not whatever the latest poll reported.
|
||||
history.push({
|
||||
...motion._historyFix(
|
||||
fixEpochMs,
|
||||
position,
|
||||
meta.speedMps,
|
||||
meta.track,
|
||||
),
|
||||
// Drawn at an invented height: a trail seeded from history keeps no
|
||||
// position for it.
|
||||
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) {
|
||||
history.shift();
|
||||
}
|
||||
pushReport(
|
||||
history,
|
||||
{
|
||||
...motion._historyFix(
|
||||
fixEpochMs,
|
||||
position,
|
||||
meta.speedMps,
|
||||
meta.track,
|
||||
),
|
||||
// Drawn at an invented height: a trail seeded from history keeps no
|
||||
// position for it.
|
||||
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,
|
||||
},
|
||||
POSITION_HISTORY_LIMIT,
|
||||
);
|
||||
// Turn rate from the fix-track history — computed once per new fix
|
||||
// (≤5 samples), consumed by the extrapolation paths at tick rate.
|
||||
meta.turnRateDps = turnRateFromFixHistory(history);
|
||||
meta.turnRateDps = turnRateFromFixHistory(history.slice(-5));
|
||||
// Trail accumulation is separate from the 5-fix DR history (PRD F2)
|
||||
// so the visible trail keeps growing while tracked. Round 2
|
||||
// (owner): ground traffic appends too — taxi history stays live
|
||||
@@ -105,6 +135,7 @@ export function createMilitarySnapshotRenderer({
|
||||
if (isTracked)
|
||||
tracking._appendTrailFix(motion._copyPosition(position), fixEpochMs, {
|
||||
nullAltitude: meta.renderAltitudeInvented === true,
|
||||
track: meta.track,
|
||||
});
|
||||
} else {
|
||||
const modelOwnsGroundVisual = rendering._modelOwnsVisual(icao24);
|
||||
@@ -134,7 +165,7 @@ export function createMilitarySnapshotRenderer({
|
||||
if (synthetic) {
|
||||
history.push(synthetic);
|
||||
if (history.length > POSITION_HISTORY_LIMIT) history.shift();
|
||||
meta.turnRateDps = turnRateFromFixHistory(history);
|
||||
meta.turnRateDps = turnRateFromFixHistory(history.slice(-5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,12 @@ test('a holding military contact draws no head and its trail ends at the last re
|
||||
layer: {},
|
||||
});
|
||||
tracking._startTrail('00a003');
|
||||
assert.equal(calls.at(-1).length, 3);
|
||||
// The body runs through every report and ends at the last one.
|
||||
const body = calls.at(-1);
|
||||
for (const report of fixes)
|
||||
assert.ok(
|
||||
body.some((p) => Cesium.Cartesian3.distance(p, report.position) < 0.01),
|
||||
);
|
||||
assert.ok(Cesium.Cartesian3.distance(body.at(-1), last) < 0.01);
|
||||
assert.deepEqual(tracking._trailHeadPositions(), []);
|
||||
});
|
||||
@@ -1,6 +1,8 @@
|
||||
import { MilitaryFlightRecords } from './records.js';
|
||||
import { createMilitaryFeed } from './ingestion.js';
|
||||
import { worldTimeFor } from '../../time/worldClock.js';
|
||||
import { createDisplayDelay } from '../../data/displayDelay.js';
|
||||
import { POLL_INTERVAL_MS, RENDER_DELAY_SEC } from './policy.js';
|
||||
|
||||
export function createFlightState({ source, services }) {
|
||||
const { createGroundSnap } = services.groundSnap;
|
||||
@@ -13,6 +15,12 @@ export function createFlightState({ source, services }) {
|
||||
});
|
||||
/** The time contacts are drawn behind by the render delay, in epoch ms. */
|
||||
flightState.now = worldTimeFor('military');
|
||||
/** How far behind real time live contacts are drawn: follows how late the
|
||||
* feed's reports arrive (see displayDelayMs in policy.js). */
|
||||
flightState._displayDelay = createDisplayDelay({
|
||||
floorMs: RENDER_DELAY_SEC * 1000,
|
||||
pollMs: POLL_INTERVAL_MS,
|
||||
});
|
||||
/** Follows the world clock while the source declares a timeline (set by the
|
||||
* layer); see followsClock and displayDelayMs in policy.js. */
|
||||
flightState.timeline = null;
|
||||
@@ -132,10 +140,9 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._trailHeadOff = null;
|
||||
|
||||
/** @type {{position: {x: number, y: number, z: number}|null, timeMs: number, nullAltitude: boolean, breakBefore: boolean, drawn?: boolean}[]}
|
||||
* Chronological tracked-aircraft trail (oldest first): reports, and
|
||||
* (`drawn`) where the icon was drawn between them; `breakBefore` starts a
|
||||
* new segment. */
|
||||
/** @type {{position: {x: number, y: number, z: number}|null, timeMs: number, nullAltitude: boolean, breakBefore: boolean, track?: number}[]}
|
||||
* Chronological tracked-aircraft trail (oldest first): reports, joined along
|
||||
* the curve the icon is drawn along; `breakBefore` starts a new segment. */
|
||||
|
||||
flightState._trailFixes = [];
|
||||
|
||||
@@ -143,14 +150,6 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._trailBodyCount = 0;
|
||||
|
||||
/** @type {{x: number, y: number, z: number}|null} Where the tracked icon was last recorded into the trail. */
|
||||
|
||||
flightState._trailRecordPosition = null;
|
||||
|
||||
/** @type {number} Display time (epoch ms) of that recording. */
|
||||
|
||||
flightState._trailRecordMs = -Infinity;
|
||||
|
||||
/** @type {string|undefined} The stale cue last written into the tracked label (see `_staleCueTick`). */
|
||||
|
||||
flightState._trackedStaleCueText = undefined;
|
||||
@@ -263,10 +262,17 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._drCorrectionStartMs = 0;
|
||||
|
||||
/** How long (ms) the correction under way takes to ease out. */
|
||||
flightState._drCorrectionMs = 0;
|
||||
|
||||
flightState._drPrevRaw = { x: 0, y: 0, z: 0 };
|
||||
|
||||
flightState._drPrevDisplay = { x: 0, y: 0, z: 0 };
|
||||
|
||||
/** How the tracked icon moved over the last frame, and that frame's length (s; 0 for none). */
|
||||
flightState._drPrevStep = { x: 0, y: 0, z: 0 };
|
||||
flightState._drPrevStepSec = 0;
|
||||
|
||||
flightState._drPrevMs = 0;
|
||||
|
||||
/** World time of that frame: the wall clock live, the cursor following the clock. */
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { julianToEpochMs } from '../../geo/julian.js';
|
||||
import { renderedFrames } from '../../data/renderedFrames.js';
|
||||
import { clone, distance, distanceSquared, vec } from '../../geo/vector.js';
|
||||
import { trailHeadStart } from '../../data/modelVisualAnchor.js';
|
||||
import { clone, distanceSquared, vec } from '../../geo/vector.js';
|
||||
import { trailHeadLine } from '../../data/modelVisualAnchor.js';
|
||||
import {
|
||||
isTrackingSelectionGesture,
|
||||
isTrackingClickGesture,
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
TRAIL_MAX_POINTS,
|
||||
DR_CORRECTION_MS,
|
||||
displayDelayMs,
|
||||
followsClock,
|
||||
STALE_ALPHA,
|
||||
@@ -41,15 +40,11 @@ import {
|
||||
historyFixEpochMs,
|
||||
insertTrailFix,
|
||||
joinTrailBackfill,
|
||||
recordTrailPoint,
|
||||
trailBackfillFixes,
|
||||
trailBodyCount,
|
||||
trailBodyCountOutsideModel,
|
||||
trailBodySegments,
|
||||
trailHeadCurvePoints,
|
||||
trailHeadStartFix,
|
||||
trailRecordingBlocked,
|
||||
TRAIL_RECORD_STEP_M,
|
||||
TRAIL_RECORD_STEP_MS,
|
||||
} from '../../data/trailContinuity.js';
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
@@ -566,7 +561,11 @@ export function createTracking({
|
||||
* drawn after it (see `insertTrailFix`).
|
||||
*/
|
||||
|
||||
function _appendTrailFix(position, epochMs, { nullAltitude = false } = {}) {
|
||||
function _appendTrailFix(
|
||||
position,
|
||||
epochMs,
|
||||
{ nullAltitude = false, track = undefined } = {},
|
||||
) {
|
||||
const history = flightState._positionHistory.get(flightState._trackedIcao);
|
||||
const timeMs = Number.isFinite(epochMs)
|
||||
? epochMs
|
||||
@@ -576,63 +575,31 @@ export function createTracking({
|
||||
_trailFloorPosition(position),
|
||||
timeMs,
|
||||
TRAIL_MAX_POINTS,
|
||||
{
|
||||
nullAltitude,
|
||||
displayMs: flightState.now() - displayDelayMs(flightState),
|
||||
settleMs: DR_CORRECTION_MS,
|
||||
},
|
||||
{ nullAltitude, track },
|
||||
);
|
||||
_refreshTrailDisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-frame trail work, run before each frame draws whether or not the
|
||||
* head is visible: record where the tracked icon is drawn (at most once a
|
||||
* second or every 150 m, floored like the head) and move the body on as
|
||||
* the display time passes reports. The head only reads the result.
|
||||
* head is visible: move the body on as the display time passes reports.
|
||||
* The head only reads the result.
|
||||
*/
|
||||
|
||||
function _trailTick() {
|
||||
if (!flightState._trackedIcao || !flightState._trail) return;
|
||||
const displayMs = flightState.now() - displayDelayMs(flightState);
|
||||
let changed = false;
|
||||
if (
|
||||
flightState._trailFixes.length &&
|
||||
!parts.motion._isTrackWarmingUp() &&
|
||||
!trailRecordingBlocked(flightState._trailFixes, displayMs)
|
||||
) {
|
||||
const drawn = parts.motion._trackedDisplayPosition(
|
||||
flightState._trackedIcao,
|
||||
);
|
||||
const last = flightState._trailRecordPosition;
|
||||
if (
|
||||
drawn &&
|
||||
(!last ||
|
||||
displayMs - flightState._trailRecordMs >= TRAIL_RECORD_STEP_MS ||
|
||||
distance(last, drawn) >= TRAIL_RECORD_STEP_M)
|
||||
) {
|
||||
flightState._trailRecordMs = displayMs;
|
||||
flightState._trailRecordPosition = clone(drawn);
|
||||
changed = recordTrailPoint(
|
||||
flightState._trailFixes,
|
||||
_trailFloorPosition(clone(drawn)),
|
||||
displayMs,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (changed || _trailBodyCountNow() !== flightState._trailBodyCount)
|
||||
if (_trailBodyCountNow() !== flightState._trailBodyCount)
|
||||
_refreshTrailDisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the trail BODY — the accumulated fixes at or before the delayed display
|
||||
* time (now − RENDER_DELAY_SEC). Newer fixes are AHEAD of the icon, so drawing them
|
||||
* would push the trail in FRONT of the plane. The cheap per-frame trail head line
|
||||
* bridges the last body point to the delayed dead-reckoned head, so the body
|
||||
* rebuilds only on a real fix or when the display time passes one, never at motion
|
||||
* cadence. A break lifts the pen: each segment is its own line, nothing between
|
||||
* them.
|
||||
* Renders the trail BODY — the reports at or before the delayed display time,
|
||||
* joined along the curve the aircraft is drawn along. Newer reports are AHEAD of
|
||||
* the icon, so drawing them would push the trail in FRONT of the plane. The
|
||||
* per-frame head runs on along the same curve from the last body report to the
|
||||
* icon, so the body rebuilds only on a real report or when the display time
|
||||
* passes one, never at motion cadence. A break lifts the pen: each segment is
|
||||
* its own line, nothing between them.
|
||||
*/
|
||||
|
||||
function _refreshTrailDisplay() {
|
||||
@@ -644,18 +611,12 @@ export function createTracking({
|
||||
);
|
||||
}
|
||||
|
||||
/** Fixes at or before the time the aircraft is drawn (now − RENDER_DELAY_SEC),
|
||||
* less the newest recorded points inside its 3D model. */
|
||||
/** Reports at or before the time the aircraft is drawn (now − the display delay). */
|
||||
|
||||
function _trailBodyCountNow() {
|
||||
return trailBodyCountOutsideModel(
|
||||
return trailBodyCount(
|
||||
flightState._trailFixes,
|
||||
trailBodyCount(
|
||||
flightState._trailFixes,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
),
|
||||
parts.motion._trackedModelCenterWorld(),
|
||||
parts.motion._trackedModelEnvelopeM(),
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -679,10 +640,9 @@ export function createTracking({
|
||||
parts.motion._trackedTrailCached() ||
|
||||
parts.motion._trackedDisplayPosition(flightState._trackedIcao);
|
||||
if (!head) return [];
|
||||
// The last body point (a report, or where the icon was drawn a moment
|
||||
// ago) → the icon. No head across a break: a body point more than 150 km
|
||||
// away, or too long ago or too far to be one path, stays detached; none
|
||||
// while the aircraft holds at its last point.
|
||||
// The last body report → the icon. No head across a break: a body point
|
||||
// more than 150 km away, or too long ago or too far to be one path, stays
|
||||
// detached; none while the aircraft holds at its last point.
|
||||
const last = trailHeadStartFix(
|
||||
flightState._trailFixes,
|
||||
head,
|
||||
@@ -690,27 +650,24 @@ export function createTracking({
|
||||
flightState._trailBodyCount,
|
||||
);
|
||||
if (!last) return [];
|
||||
const start = last.position;
|
||||
// Floor the head too (round 2): a grounded tracked contact's DR
|
||||
// display height is the pre-datum default — without this the last
|
||||
// segment dives underground while taxiing.
|
||||
// segment dives underground while taxiing. The model envelope is
|
||||
// measured against the FLOORED endpoint, which is the one actually drawn.
|
||||
const end = _trailFloorPosition(clone(head));
|
||||
// On a contact that has not moved this segment runs from inside the
|
||||
// model out to its own anchor — a line through the fuselage. The END
|
||||
// never gives, so a moving trail still terminates on the tail; the
|
||||
// START is what slides, from nothing on a parked contact out to the
|
||||
// whole segment once it has cleared its own envelope. Measured against
|
||||
// the FLOORED endpoint, which is the one actually drawn.
|
||||
// See trailHeadStart.
|
||||
const from = trailHeadStart(
|
||||
start,
|
||||
return trailHeadLine(
|
||||
last.position,
|
||||
// Along the curve the icon is drawn along, to where it is now.
|
||||
trailHeadCurvePoints(
|
||||
flightState._trailFixes,
|
||||
flightState._trailBodyCount,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
),
|
||||
end,
|
||||
parts.motion._trackedModelCenterWorld(),
|
||||
parts.motion._trackedModelEnvelopeM(),
|
||||
flightState._scratchTrailHead,
|
||||
);
|
||||
if (!from) return [];
|
||||
return [from, end];
|
||||
}
|
||||
|
||||
/** Each drawn frame, before it draws: the trail moved on, then the live
|
||||
@@ -730,11 +687,9 @@ export function createTracking({
|
||||
function _startTrail(icao24) {
|
||||
flightState._trailBackfillToken += 1;
|
||||
flightState._trailFixes = [];
|
||||
flightState._trailRecordPosition = null;
|
||||
flightState._trailRecordMs = -Infinity;
|
||||
const history = flightState._positionHistory.get(icao24) || [];
|
||||
// Seed every report. The body only draws those at or before the delayed
|
||||
// display time (now − RENDER_DELAY_SEC); newer ones join it as the display
|
||||
// display time (now − displayDelayMs); newer ones join it as the display
|
||||
// passes them. A synthetic forward fix (it carries `reportEpochMs`) is a
|
||||
// motion aid, never a report. A report drawn at an invented height keeps
|
||||
// no position and breaks the line.
|
||||
@@ -748,7 +703,11 @@ export function createTracking({
|
||||
_trailFloorPosition(clone(fix.position)),
|
||||
historyFixEpochMs(fix),
|
||||
TRAIL_MAX_POINTS,
|
||||
{ nullAltitude: fix.inventedHeight === true, onGround: fix.onGround },
|
||||
{
|
||||
nullAltitude: fix.inventedHeight === true,
|
||||
onGround: fix.onGround,
|
||||
track: fix.track,
|
||||
},
|
||||
);
|
||||
}
|
||||
if (!flightState._trail && flightState._viewer) {
|
||||
@@ -899,8 +858,6 @@ export function createTracking({
|
||||
function _clearTrail() {
|
||||
flightState._trailBackfillToken += 1;
|
||||
flightState._trailFixes = [];
|
||||
flightState._trailRecordPosition = null;
|
||||
flightState._trailRecordMs = -Infinity;
|
||||
if (flightState._trail) flightState._trail.clear();
|
||||
flightState._trailHeadOff?.();
|
||||
flightState._trailHeadOff = null;
|
||||
|
||||
@@ -8,8 +8,9 @@ import { createFlightState } from './state.js';
|
||||
import { createTracking } from './tracking.js';
|
||||
import { RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
|
||||
|
||||
// A tracked military contact's trail between reports is the path its icon
|
||||
// was drawn along, recorded from the real display path frame by frame.
|
||||
// A tracked military contact's trail is its 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.
|
||||
|
||||
const SEC = 1000;
|
||||
const ICAO = '00a004';
|
||||
@@ -154,6 +155,42 @@ function harness({ fixes, info, nowMs, ground = () => null }) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
@@ -200,6 +237,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);
|
||||
|
||||
@@ -227,64 +281,40 @@ function departure() {
|
||||
return { fixes, info };
|
||||
}
|
||||
|
||||
test('military: a report newer than the display time arrives mid-turn, and the trail between the reports stays on the drawn arc', () => {
|
||||
test('military: 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.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');
|
||||
@@ -300,7 +330,6 @@ test('military: a report the display already passed replaces the guess drawn aft
|
||||
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,
|
||||
@@ -323,16 +352,11 @@ test('military: a report the display already passed replaces the guess drawn aft
|
||||
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);
|
||||
@@ -342,7 +366,7 @@ test('military: a report the display already passed replaces the guess drawn aft
|
||||
}
|
||||
});
|
||||
|
||||
test('military: a history report at an invented height is seeded with no position, and nothing is recorded next to it', () => {
|
||||
test('military: 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;
|
||||
@@ -355,9 +379,10 @@ test('military: a history report at an invented height is seeded with no positio
|
||||
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();
|
||||
@@ -421,15 +446,14 @@ test('military: a plane that stops reporting keeps moving dimmed as STALE from i
|
||||
);
|
||||
// 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);
|
||||
@@ -469,7 +493,7 @@ test('military: a plane held at its last report shows SIGNAL LOST in seconds und
|
||||
}
|
||||
});
|
||||
|
||||
test('military: a report arriving 200 s into a coast: the plane eases onto it and the trail drops what was drawn after it', () => {
|
||||
test('military: 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 {
|
||||
@@ -496,27 +520,29 @@ test('military: a report arriving 200 s into a coast: the plane eases onto it an
|
||||
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();
|
||||
}
|
||||
@@ -629,7 +655,7 @@ test('military: a stalled feed dims the tracked plane as STALE', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('military: a report arriving after the plane has stopped: it eases in with no spur, and the trail keeps everything up to the stop', () => {
|
||||
test('military: 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) });
|
||||
@@ -638,14 +664,8 @@ test('military: a report arriving after the plane has stopped: it eases in with
|
||||
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));
|
||||
@@ -654,26 +674,13 @@ test('military: a report arriving after the plane has stopped: it eases in with
|
||||
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');
|
||||
|
||||
Reference in new issue
Block a user