refactor(layers): W1 timestamps without JulianDate

Flights and military keep their fix history in plain milliseconds
(timeMs, whole ms as the Date the JulianDate came from held) and read
"now" from the app clock: the render-delay time, bracketing,
extrapolation, the warm-up check and the trail seed are number
arithmetic (motion.js, tracking.js, snapshotRenderer.js), as is the turn
rate and the forward synthetic fix in data/motionModel.js, which no
longer imports Cesium. The JulianDate scratch fields in state.js and the
unused JulianDate.now() in queries.js go. Launches (mission frame, panel,
selection), the tracked satellite's SGP4 epoch and the celestial ring's
sun and moon read the app clock; where a Cesium property still takes a
JulianDate it is built from the app clock's now (as JulianDate.now did
from Date.now). Wall-clock throttles and feed receipt stamps stay on
Date.now; property reads at viewer.clock.currentTime (render, frozen at
boot) move with the render code in the *a tasks.

Tests that built JulianDate history fixtures now build ms ones with the
same instants (motionModel.test, flights.test, militaryFlights.test); new
tests show the military delayed position and the tracked satellite follow
the app clock (both fail on the previous code).
This commit is contained in:
German Khokhlov committed 2026-10-16 15:01:46 +04:00
1 parent f1a2df5cfe
commit c33ee31efc
21 files changed
+155 -130

No files matched your search

+9 -30
View File
@@ -1,5 +1,5 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { appClock } from '../../time/clock.js';
import {
lerpAngleDeg,
speedRamp,
@@ -67,25 +67,15 @@ export function createMotion({
const out = result || geo.cartesian3.create();
// Render one poll interval behind real time so we interpolate between
// two KNOWN fixes whenever possible (see RENDER_DELAY_SEC rationale).
const renderTime = Cesium.JulianDate.addSeconds(
Cesium.JulianDate.now(),
-RENDER_DELAY_SEC,
flightState._scratchRenderTime,
);
const renderTimeMs = appClock.now() - RENDER_DELAY_SEC * 1000;
// Bracketing pair: interpolate — no extrapolation error, no snap-back.
for (let i = history.length - 1; i >= 1; i--) {
const a = history[i - 1];
const b = history[i];
if (
Cesium.JulianDate.lessThanOrEquals(a.time, renderTime) &&
Cesium.JulianDate.lessThanOrEquals(renderTime, b.time)
) {
const span = Cesium.JulianDate.secondsDifference(b.time, a.time);
const t =
span > 0
? Cesium.JulianDate.secondsDifference(renderTime, a.time) / span
: 1.0;
if (a.timeMs <= renderTimeMs && renderTimeMs <= b.timeMs) {
const span = (b.timeMs - a.timeMs) / 1000;
const t = span > 0 ? (renderTimeMs - a.timeMs) / 1000 / span : 1.0;
// Course of the DISPLAYED motion. The chord is only trustworthy when the
// segment covers real ground (at hover its direction is GPS jitter; on a
// slow tight turn it STEPS the whole per-segment turn at each boundary),
@@ -115,10 +105,7 @@ export function createMotion({
}
const newest = history[history.length - 1];
const elapsedSec = Cesium.JulianDate.secondsDifference(
renderTime,
newest.time,
);
const elapsedSec = (renderTimeMs - newest.timeMs) / 1000;
if (elapsedSec <= 0) {
// Warm-up: renderTime predates ALL history (freshly seen / just-started-tracking
// aircraft, before RENDER_DELAY_SEC of history has accumulated, so no bracketing
@@ -128,10 +115,7 @@ export function createMotion({
// the bracketing interpolation above with NO freeze and NO backward snap. (Holding
// the oldest fix froze the icon until enough history accrued, then jumped.)
const oldest = history[0];
const lookbackSec = Cesium.JulianDate.secondsDifference(
oldest.time,
renderTime,
); // ≥ 0
const lookbackSec = (oldest.timeMs - renderTimeMs) / 1000; // ≥ 0
return _extrapolateFix(
oldest,
info,
@@ -148,7 +132,7 @@ export function createMotion({
// Date for every aircraft twelve times per second.
fixEpochMs: Number.isFinite(newest.epochMs)
? newest.epochMs
: Cesium.JulianDate.toDate(newest.time).getTime(),
: newest.timeMs,
lastContactEpochMs: info?.lastContactEpochMs,
});
return _extrapolateFix(
@@ -213,12 +197,7 @@ export function createMotion({
if (!flightState._trackedIcao) return false;
const history = flightState._positionHistory.get(flightState._trackedIcao);
if (!history || history.length === 0) return true;
const renderTime = Cesium.JulianDate.addSeconds(
Cesium.JulianDate.now(),
-RENDER_DELAY_SEC,
flightState._scratchWarmupTime,
);
return Cesium.JulianDate.lessThan(renderTime, history[0].time);
return appClock.now() - RENDER_DELAY_SEC * 1000 < history[0].timeMs;
}
/** Resolve the selected aircraft's actual rendered square extent this frame. */