refactor(vessels,satellites,awareness): take vector maths from src/geo

Moves the Cartesian3/Cartographic/Matrix3/Matrix4/Math calls of the vessel, satellite and Contacts (awareness) layers, plus flights controller/enrichment, to src/geo. The satellites-layer package boundary now owns the src/geo modules. Awareness keeps Cesium.Cartesian3.clone for the resolved subject position, which reaches the installations anchor (anchor.test pins a Cesium instance).
This commit is contained in:
German Khokhlov committed 2026-10-15 00:17:17 +04:00
1 parent 1a69368ae6
commit 2b83606765
15 files changed
+97 -86

No files matched your search

+5 -5
View File
@@ -3,7 +3,7 @@ import {
satelliteClassLabel,
satelliteClassLegend,
} from '../../data/satelliteClass.js';
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { ISS_NORAD, POINT_STYLES } from './policy.js';
export function createControls({ state: layerState, services, parts, source }) {
@@ -195,7 +195,7 @@ export function createControls({ state: layerState, services, parts, source }) {
return {
noradId,
name: sat.name.trim(),
position: Cesium.Cartesian3.fromDegrees(
position: geo.cartesian3.fromDegrees(
pos.longitude,
pos.latitude,
pos.altitude,
@@ -227,15 +227,15 @@ export function createControls({ state: layerState, services, parts, source }) {
layerState._catalog.get(noradId)?.group === 'dense'
)
continue;
const carto = Cesium.Cartographic.fromCartesian(point.position);
const carto = geo.cartographic.fromCartesian(point.position);
if (!carto) continue;
const sat = layerState._catalog.get(noradId);
result.push({
id: noradId,
label: sat ? sat.name.trim() : String(noradId),
position: point.position,
latitude: Cesium.Math.toDegrees(carto.latitude),
longitude: Cesium.Math.toDegrees(carto.longitude),
latitude: geo.math.toDegrees(carto.latitude),
longitude: geo.math.toDegrees(carto.longitude),
altitudeM: carto.height,
});
}
+14 -14
View File
@@ -1,4 +1,4 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import {
gstime,
propagate,
@@ -24,16 +24,16 @@ export function createOrbits({ state: layerState, services, parts, source }) {
function orbitFrameModelMatrix(
gmstAtBake,
nowDate,
result = new Cesium.Matrix4(),
result = geo.matrix4.create(),
) {
const deltaGmst = gstime(nowDate) - gmstAtBake;
const rotation = Cesium.Matrix3.fromRotationZ(
const rotation = geo.matrix3.fromRotationZ(
-deltaGmst,
layerState._scratchRingRotation,
);
return Cesium.Matrix4.fromRotationTranslation(
return geo.matrix4.fromRotationTranslation(
rotation,
Cesium.Cartesian3.ZERO,
geo.cartesian3.ZERO,
result,
);
}
@@ -55,7 +55,7 @@ export function createOrbits({ state: layerState, services, parts, source }) {
if (!posVel.position || typeof posVel.position === 'boolean') return null;
const gmst = gstime(date);
const geo = eciToGeodetic(posVel.position, gmst);
const geodetic = eciToGeodetic(posVel.position, gmst);
const velocity =
posVel.velocity && typeof posVel.velocity !== 'boolean'
? posVel.velocity
@@ -65,9 +65,9 @@ export function createOrbits({ state: layerState, services, parts, source }) {
: null;
return {
longitude: degreesLong(geo.longitude),
latitude: degreesLat(geo.latitude),
altitude: geo.height * 1000, // km → meters
longitude: degreesLong(geodetic.longitude),
latitude: degreesLat(geodetic.latitude),
altitude: geodetic.height * 1000, // km → meters
speedMps: Number.isFinite(speedMps) ? speedMps : null,
};
} catch {
@@ -101,12 +101,12 @@ export function createOrbits({ state: layerState, services, parts, source }) {
try {
const posVel = propagate(satrec, t);
if (!posVel.position || typeof posVel.position === 'boolean') continue;
const geo = eciToGeodetic(posVel.position, fixedGmst);
const geodetic = eciToGeodetic(posVel.position, fixedGmst);
positions.push(
Cesium.Cartesian3.fromDegrees(
degreesLong(geo.longitude),
degreesLat(geo.latitude),
geo.height * 1000,
geo.cartesian3.fromDegrees(
degreesLong(geodetic.longitude),
degreesLat(geodetic.latitude),
geodetic.height * 1000,
),
);
} catch {
+4 -4
View File
@@ -1,4 +1,4 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { satelliteClassLabel } from '../../data/satelliteClass.js';
import { ISS_NORAD } from './policy.js';
@@ -62,11 +62,11 @@ export function createRecords({ state, parts }) {
}
const point = state._points.get(noradId);
if (!point?.position) return null;
const carto = Cesium.Cartographic.fromCartesian(point.position);
const carto = geo.cartographic.fromCartesian(point.position);
if (!carto) return null;
return {
lat: Cesium.Math.toDegrees(carto.latitude),
lon: Cesium.Math.toDegrees(carto.longitude),
lat: geo.math.toDegrees(carto.latitude),
lon: geo.math.toDegrees(carto.longitude),
altitudeM: carto.height,
speedMps: null,
};
+5 -5
View File
@@ -1,4 +1,4 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
export function createState({ services }) {
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
@@ -58,7 +58,7 @@ export function createState({ services }) {
state._activeFocusCount = 0;
state._scratchFocusScreen = new Cesium.Cartesian2();
state._scratchFocusScreen = geo.cartesian2.create();
state._enabled = false;
@@ -141,7 +141,7 @@ export function createState({ services }) {
state._trackedFrameGeo = null;
// { longitude, latitude, altitude } or null
state._trackedFrameCartesian = new Cesium.Cartesian3();
state._trackedFrameCartesian = geo.cartesian3.create();
/** Optional deterministic clock used only by the production-frame test seam. */
@@ -149,9 +149,9 @@ export function createState({ services }) {
// Scratch variables
state._scratchCartesian = new Cesium.Cartesian3();
state._scratchCartesian = geo.cartesian3.create();
state._scratchRingRotation = new Cesium.Matrix3();
state._scratchRingRotation = geo.matrix3.create();
/** Update the explicit model only when the rounded altitude line changes. */
/** Epoch of the last shared-context refresh for the tracked satellite. */