refactor(launches,cctv,alpr): take vector maths from src/geo

Launches selection/replay/panel/policy/policyHelpers/state/camera, CCTV geometry/model/projection/navigation/cards/geometryQueue/state and ALPR model/visuals now use src/geo for Math, Cartesian2/3, Cartographic, Matrix3/4, Quaternion and ENU frames. launches/paths.js keeps Cesium (EllipsoidGeodesic). In camera.js, EllipsoidGeodesic, BoundingSphere.fromPoints/union and the BoundingSphere constructor stay on Cesium; the geo Cartographics passed into EllipsoidGeodesic are only read field by field and cloned there (computeProperties). The CCTV plane orientation stays a Cesium Quaternion and plane dimensions a Cesium Cartesian2 (entity ConstantProperty values). launches-layer and alpr-cameras own the src/geo files.
This commit is contained in:
German Khokhlov committed 2026-10-15 00:18:35 +04:00
1 parent ee8b94d987
commit a915bdb3e5
17 files changed
+215 -214

No files matched your search

+3 -3
View File
@@ -8,7 +8,7 @@ import {
CCTV_FRAME_CANVAS_H,
applyFrameResult,
} from '../../data/cctvCards.js';
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { horizonOccluder } from '../../data/iconOrientation.js';
import { selectCctvLod, applyEvictionGrace } from '../../data/cctvLod.js';
import {
@@ -85,8 +85,8 @@ export function createCards({ state: layerState, services, parts, source }) {
}
const scene = layerState._viewer.scene;
const carto = layerState._viewer.camera.positionCartographic;
const viewerLat = carto ? Cesium.Math.toDegrees(carto.latitude) : 0;
const viewerLon = carto ? Cesium.Math.toDegrees(carto.longitude) : 0;
const viewerLat = carto ? geo.math.toDegrees(carto.latitude) : 0;
const viewerLon = carto ? geo.math.toDegrees(carto.longitude) : 0;
// The active camera is excluded from ambient selection ALWAYS (not just
// after its async activation settles). It is published separately in the
// protected lane below, and grace never applies to it.
+13 -16
View File
@@ -1,4 +1,5 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { createFrustumVolumePrimitive } from '../../data/cctvViewshed.js';
import {
PROJECTION_VERT_ASPECT,
@@ -272,7 +273,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
*/
function frustumCartesians(geometry) {
const at = (p) => Cesium.Cartesian3.fromDegrees(p.lon, p.lat, p.alt);
const at = (p) => geo.cartesian3.fromDegrees(p.lon, p.lat, p.alt);
return {
mount: at(geometry.mount),
capCenter: at(geometry.capCenter),
@@ -280,7 +281,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
tr: at(geometry.corners.tr),
br: at(geometry.corners.br),
bl: at(geometry.corners.bl),
label: Cesium.Cartesian3.fromDegrees(
label: geo.cartesian3.fromDegrees(
geometry.topCenter.lon,
geometry.topCenter.lat,
geometry.topCenter.alt + 1.2,
@@ -301,26 +302,22 @@ export function createGeometry({ state: layerState, services, parts, source }) {
function frustumFrameEcef(camera, atPos) {
const h = parts.model.toRad(camera.headingDeg);
const p = parts.model.toRad(camera.pitchDeg);
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(atPos);
const rot = Cesium.Matrix4.getMatrix3(enu, new Cesium.Matrix3());
const enu = geo.transforms.eastNorthUpToFixedFrame(atPos);
const rot = geo.matrix4.getMatrix3(enu, geo.matrix3.create());
// ENU components: view axis + the perpendicular "up" of the pitched cap.
const dirEnu = new Cesium.Cartesian3(
const dirEnu = geo.cartesian3.create(
Math.sin(h) * Math.cos(p),
Math.cos(h) * Math.cos(p),
Math.sin(p),
);
const upEnu = new Cesium.Cartesian3(
const upEnu = geo.cartesian3.create(
-Math.sin(p) * Math.sin(h),
-Math.sin(p) * Math.cos(h),
Math.cos(p),
);
return {
dir: Cesium.Matrix3.multiplyByVector(
rot,
dirEnu,
new Cesium.Cartesian3(),
),
up: Cesium.Matrix3.multiplyByVector(rot, upEnu, new Cesium.Cartesian3()),
dir: geo.matrix3.multiplyByVector(rot, dirEnu, geo.cartesian3.create()),
up: geo.matrix3.multiplyByVector(rot, upEnu, geo.cartesian3.create()),
};
}
@@ -462,10 +459,10 @@ export function createGeometry({ state: layerState, services, parts, source }) {
sampleMeshFloorCells(layerState._viewer?.scene, [point], {
excludeObjects: excludeObjects.filter(Boolean),
viewerLat: viewerCarto
? Cesium.Math.toDegrees(viewerCarto.latitude)
? geo.math.toDegrees(viewerCarto.latitude)
: undefined,
viewerLon: viewerCarto
? Cesium.Math.toDegrees(viewerCarto.longitude)
? geo.math.toDegrees(viewerCarto.longitude)
: undefined,
});
}
@@ -623,7 +620,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
if (Math.abs(rangeScale - 1) > 0.0001) return; // slider overrides the clamp
try {
const mountAlt = parts.ground.groundAltFor(record) + camera.mountHeightM;
const mountPos = Cesium.Cartesian3.fromDegrees(
const mountPos = geo.cartesian3.fromDegrees(
camera.lon,
camera.lat,
mountAlt,
@@ -637,7 +634,7 @@ export function createGeometry({ state: layerState, services, parts, source }) {
}
const hit = scene.pickFromRay(new Cesium.Ray(mountPos, dir), exclude);
if (!hit?.position) return;
const dist = Cesium.Cartesian3.distance(mountPos, hit.position);
const dist = geo.cartesian3.distance(mountPos, hit.position);
record.probeClampRangeM = activationProbeClampRange(camera.rangeM, dist);
} catch {
// probe failure → keep the unclamped range
+3 -3
View File
@@ -1,4 +1,4 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import {
GEO_PROGRESS_NOTIFY_INTERVAL_MS,
GEO_PROGRESS_NOTIFY_BATCH_LIMIT,
@@ -298,10 +298,10 @@ export function createGeometryQueue({
const active = parts.selection.getActiveRecord();
const carto = layerState._viewer?.camera?.positionCartographic;
const refLat = carto
? Cesium.Math.toDegrees(carto.latitude)
? geo.math.toDegrees(carto.latitude)
: (active?.camera.lat ?? 0);
const refLon = carto
? Cesium.Math.toDegrees(carto.longitude)
? geo.math.toDegrees(carto.longitude)
: (active?.camera.lon ?? 0);
const pending = layerState._records
.filter((record) => record !== active)
+23 -20
View File
@@ -1,4 +1,5 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { staticFrameRefreshMs } from '../../data/cctvLod.js';
import { frameFetchDue, cardFetchPolicy } from '../../data/cctvCards.js';
import { DEFAULT_CAMERA_CALIBRATION } from './policy.js';
@@ -13,7 +14,7 @@ export function createModel({ state: layerState, services, parts, source }) {
*/
function toRad(deg) {
return Cesium.Math.toRadians(deg);
return geo.math.toRadians(deg);
}
/**
@@ -283,8 +284,8 @@ export function createModel({ state: layerState, services, parts, source }) {
const lon2 = lon1 + Math.atan2(y, x);
return {
lat: Cesium.Math.toDegrees(lat2),
lon: Cesium.Math.toDegrees(lon2),
lat: geo.math.toDegrees(lat2),
lon: geo.math.toDegrees(lon2),
};
}
@@ -328,8 +329,8 @@ export function createModel({ state: layerState, services, parts, source }) {
function currentViewContext() {
const carto = layerState._viewer?.camera?.positionCartographic;
if (!carto) return 'none';
const lat = Cesium.Math.toDegrees(carto.latitude);
const lon = Cesium.Math.toDegrees(carto.longitude);
const lat = geo.math.toDegrees(carto.latitude);
const lon = geo.math.toDegrees(carto.longitude);
const alt = carto.height || 0;
const zoomBucket =
alt < 1500
@@ -404,24 +405,26 @@ export function createModel({ state: layerState, services, parts, source }) {
function planeOrientationFor(camera, capCenterPos) {
const frame = parts.geometry.frustumFrameEcef(camera, capCenterPos);
const right = Cesium.Cartesian3.cross(
const right = geo.cartesian3.cross(
frame.dir,
frame.up,
new Cesium.Cartesian3(),
geo.cartesian3.create(),
);
const normal = Cesium.Cartesian3.negate(frame.dir, new Cesium.Cartesian3());
const m = new Cesium.Matrix3(
right.x,
frame.up.x,
normal.x,
right.y,
frame.up.y,
normal.y,
right.z,
frame.up.z,
normal.z,
);
return Cesium.Quaternion.fromRotationMatrix(m);
const normal = geo.cartesian3.negate(frame.dir, geo.cartesian3.create());
// Column-major rotation whose columns are right, up and normal.
const m = geo.matrix3.create();
m[0] = right.x;
m[1] = right.y;
m[2] = right.z;
m[3] = frame.up.x;
m[4] = frame.up.y;
m[5] = frame.up.z;
m[6] = normal.x;
m[7] = normal.y;
m[8] = normal.z;
// The quaternion becomes an entity's ConstantProperty value, so it stays a
// Cesium Quaternion there (that property clones and compares its value).
return geo.quaternion.fromRotationMatrix(m, new Cesium.Quaternion());
}
/**
+3 -2
View File
@@ -1,4 +1,5 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import { CCTV_FOCUS_RESULT } from './policy.js';
export function createNavigation({
@@ -15,8 +16,8 @@ export function createNavigation({
function nearestCameraIdToViewer() {
const carto = layerState._viewer?.camera?.positionCartographic;
if (!carto || !layerState._records.length) return null;
const lat = Cesium.Math.toDegrees(carto.latitude);
const lon = Cesium.Math.toDegrees(carto.longitude);
const lat = geo.math.toDegrees(carto.latitude);
const lon = geo.math.toDegrees(carto.longitude);
let best = null;
for (const record of layerState._records) {
+6 -5
View File
@@ -1,5 +1,6 @@
import { attachCctvVideo } from './videoPlayback.js';
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
import {
CCTV_PROJECTION_OVERLAY_SOURCE_ID,
CCTV_PROJECTION_OVERLAY_SOURCE_OPTIONS,
@@ -77,7 +78,7 @@ export function createProjection({
);
}
if (runtime.labelPosition) {
Cesium.Cartesian3.clone(positions.label, runtime.labelPosition);
geo.cartesian3.clone(positions.label, runtime.labelPosition);
}
}
@@ -124,8 +125,8 @@ export function createProjection({
/** Create the native monitor plane plus its cached host-label presentation. */
function createProjectionPlane(record, runtime, geometry, positions) {
runtime.labelPosition ||= new Cesium.Cartesian3();
Cesium.Cartesian3.clone(positions.label, runtime.labelPosition);
runtime.labelPosition ||= geo.cartesian3.create();
geo.cartesian3.clone(positions.label, runtime.labelPosition);
runtime.cameraId = String(record.camera.id);
runtime.overlayEntry = createCctvProjectionOverlayEntry({
cameraId: runtime.cameraId,
@@ -142,7 +143,7 @@ export function createProjection({
positions.capCenter,
),
plane: {
plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_Z, 0.0),
plane: new Cesium.Plane(geo.cartesian3.UNIT_Z, 0.0),
dimensions: new Cesium.Cartesian2(
geometry.halfW * 2,
geometry.halfH * 2,
@@ -186,7 +187,7 @@ export function createProjection({
video: null,
planeEntity: null,
cameraId: String(record.camera.id),
labelPosition: new Cesium.Cartesian3(),
labelPosition: geo.cartesian3.create(),
overlayEntry: null,
planeMaterial: null,
buffers: null,
+2 -2
View File
@@ -1,4 +1,4 @@
import * as Cesium from 'cesium';
import * as geo from '../../geo/index.js';
export function createState({ services }) {
const {
@@ -74,7 +74,7 @@ export function createState({ services }) {
layerState._activeFocusStyleCount = 0;
layerState._scratchFocusScreen = new Cesium.Cartesian2();
layerState._scratchFocusScreen = geo.cartesian2.create();
// Staggered geometry-load queue state (see startGeometryLoadQueue).