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

+1 -1
View File
@@ -479,7 +479,7 @@ test('real civil track path creates no native label and publishes every cached h
tracked: false,
history: [
{
time: now,
timeMs: Cesium.JulianDate.toDate(now).getTime(),
epochMs: Date.now(),
position,
velocity: 250,
+1 -1
View File
@@ -407,7 +407,7 @@ test('real military track path creates no native label and publishes every cache
tracked: false,
history: [
{
time: now,
timeMs: Cesium.JulianDate.toDate(now).getTime(),
epochMs: Date.now(),
position,
velocity: 231.5,
+13 -9
View File
@@ -6,7 +6,6 @@
* Turn-rate estimation + constant-rate-turn arc integration are adapted from
* skylight (https://github.com/cpaczek/skylight, MIT) shared/src/aim.ts.
*/
import * as Cesium from 'cesium';
import * as geo from '../geo/index.js';
const DEG = Math.PI / 180;
@@ -257,17 +256,17 @@ export function estimateTurnRateDps(
return Math.max(-maxDps, Math.min(maxDps, rate));
}
/** Adapter: fix history [{time: JulianDate, track, velocity}] →
/** Adapter: fix history [{timeMs, track, velocity}] →
* estimateTurnRateDps, guarded by TURN_MIN_SPEED_MPS (low-speed fix-track
* jitter must not manufacture a turn rate). */
export function turnRateFromFixHistory(history) {
if (!history || history.length < 2) return 0;
const t0 = history[0].time;
const t0 = history[0].timeMs;
const samples = [];
for (const s of history) {
if (!Number.isFinite(s.track)) continue;
samples.push({
tSec: Cesium.JulianDate.secondsDifference(s.time, t0),
tSec: (s.timeMs - t0) / 1000,
trackDeg: s.track,
speedMps: s.velocity,
});
@@ -447,19 +446,23 @@ const _forwardFixOffset = geo.cartesian3.create();
* kinematics. This prevents a late course change from reprojecting the entire
* stale interval and snapping the rendered contact by kilometres.
*
* @param {{time: Cesium.JulianDate, epochMs?: number, position: Cesium.Cartesian3,
* @param {{timeMs: number, epochMs?: number, position: Cesium.Cartesian3,
* velocity?: number, track?: number}} newest Existing immutable history fix.
* @param {{epochMs: number, velocity: number, track: number, turnRateDps?: number}} next
* New kinematics and the wall/source epoch at which they become authoritative.
* @returns {{time: Cesium.JulianDate, epochMs: number, position: Cesium.Cartesian3,
* @returns {{timeMs: number, epochMs: number, position: Cesium.Cartesian3,
* velocity: number, track: number}|null} Forward synthetic fix, or null.
*/
export function synthesizeForwardKinematicsFix(newest, next = {}) {
if (!newest?.position || !newest?.time || !Number.isFinite(next.epochMs))
if (
!newest?.position ||
newest?.timeMs == null ||
!Number.isFinite(next.epochMs)
)
return null;
const startEpochMs = Number.isFinite(newest.epochMs)
? newest.epochMs
: Cesium.JulianDate.toDate(newest.time).getTime();
: newest.timeMs;
if (!Number.isFinite(startEpochMs) || next.epochMs <= startEpochMs)
return null;
@@ -492,7 +495,8 @@ export function synthesizeForwardKinematicsFix(newest, next = {}) {
geo.cartesian3.create(),
);
return {
time: Cesium.JulianDate.fromDate(new Date(next.epochMs)),
// Whole milliseconds, as a Date holds the fix time.
timeMs: Math.trunc(next.epochMs),
epochMs: next.epochMs,
position,
velocity: Number.isFinite(next.velocity)
+8 -7
View File
@@ -93,10 +93,10 @@ test('estimateTurnRateDps: 2°/s ramp detected; noise floored; clamped', () => {
assert.equal(estimateTurnRateDps(wild), -4); // clamped
});
test('turnRateFromFixHistory adapts JulianDate history', () => {
const t0 = Cesium.JulianDate.now();
test('turnRateFromFixHistory adapts the fix history (ms timestamps)', () => {
const t0 = Date.now();
const h = [0, 30, 60].map((s, i) => ({
time: Cesium.JulianDate.addSeconds(t0, s, new Cesium.JulianDate()),
timeMs: t0 + s * 1000,
track: i * 60,
}));
assert.ok(Math.abs(turnRateFromFixHistory(h) - 2) < 1e-9);
@@ -142,9 +142,9 @@ test('courseSlewCapDps: COURSE_MIN_DPS at low speed easing to the fleet cap at c
});
test('turn-rate guard: hover fix-track jitter manufactures NO turn rate; a real slow turn still does', () => {
const t0 = Cesium.JulianDate.now();
const t0 = Date.now();
const mk = (specs) => specs.map(([s, track, velocity]) => ({
time: Cesium.JulianDate.addSeconds(t0, s, new Cesium.JulianDate()),
timeMs: t0 + s * 1000,
track, velocity,
}));
// Hovering heli: 1 m/s drift, reported track flipping ±45° — used to yield ±°/s
@@ -180,7 +180,7 @@ test('repeated kinematics apply only from a forward synthetic fix', () => {
const epochMs = 1_800_000_000_000;
const originalPosition = Cesium.Cartesian3.fromDegrees(-97.7431, 30.2672, 9000);
const newest = {
time: Cesium.JulianDate.fromDate(new Date(epochMs)),
timeMs: epochMs,
epochMs,
position: Cesium.Cartesian3.clone(originalPosition),
velocity: 100,
@@ -195,6 +195,7 @@ test('repeated kinematics apply only from a forward synthetic fix', () => {
assert.equal(newest.velocity, 100);
assert.equal(newest.track, 90);
assert.ok(Cesium.Cartesian3.equals(newest.position, originalPosition));
assert.equal(synthetic.timeMs, epochMs + 10_000);
assert.equal(synthetic.velocity, 220);
assert.equal(synthetic.track, 15);
assert.ok(Math.abs(Cesium.Cartesian3.distance(newest.position, synthetic.position) - 1000) < 0.5);
@@ -202,7 +203,7 @@ test('repeated kinematics apply only from a forward synthetic fix', () => {
test('liftRepeatedGroundFix raises only grounded history and preserves the stored coordinates', () => {
const newest = {
time: Cesium.JulianDate.now(),
timeMs: Date.now(),
epochMs: 123,
position: Cesium.Cartesian3.fromDegrees(-98.04, 29.71, -30),
velocity: 0,
@@ -338,3 +338,33 @@ test('ISS overlay entry retains the native distance scale and source text', () =
assert.equal(entry.edgeFade, 'keyhole');
assert.equal(entry.horizonCull, true);
});
test('the tracked satellite is propagated at the app clock time', async () => {
const { appClock } = await import('../time/clock.js');
const entity = { gevLabelModel: { title: 'OLD', details: ['? km'] } };
const point = { position: new Cesium.Cartesian3() };
const viewer = {
camera: null,
scene: { frameState: { frameNumber: 1 } },
};
_setTrackedSatelliteRefreshStateForTest({
noradId: 25544,
name: 'ISS (ZARYA)',
satrec: twoline2satrec(L1, L2),
entity,
point,
viewer,
now: undefined,
});
try {
appClock.freeze(Date.UTC(2008, 8, 20, 12, 30));
_runSatellitePreRenderForTest();
assert.equal(entity.gevLabelModel.details[1], '353 km · NORAD 25544');
appClock.freeze(Date.UTC(2008, 8, 20, 13, 0));
viewer.scene.frameState.frameNumber = 2;
_runSatellitePreRenderForTest();
assert.equal(entity.gevLabelModel.details[1], '366 km · NORAD 25544');
} finally {
appClock.reset();
}
});