From f6ed35a887612b298b64f6985a1835d604356c99 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Fri, 6 Nov 2026 20:38:59 -0800 Subject: [PATCH] Compute ALPR bearings and wedge corners without Cesium The ALPR model's great-circle destination and the direction wedge's corners now come from src/geo: the same numbers, the corners plain ECEF rather than Cesium objects, which the overlay projects as before. Both files leave the Cesium allow-list. --- src/layers/alpr/markerState.js | 2 +- src/layers/alpr/model.js | 12 ++++++------ src/layers/alpr/overlay.test.mjs | 18 ++++++++++++++++++ src/layers/alpr/visuals.js | 19 ++++++++----------- src/render/cesiumAllowList.json | 2 -- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/layers/alpr/markerState.js b/src/layers/alpr/markerState.js index 496d348eb..9acf0d973 100644 --- a/src/layers/alpr/markerState.js +++ b/src/layers/alpr/markerState.js @@ -5,7 +5,7 @@ * - `record`: the camera record the marker shows. * - `clamped`: whether the marker sits on the surface rather than at its height. * - `canvasPosition`, `displayPosition`: the canvas anchor and the position the card reads. - * - `wedge`: the direction wedge's positions. + * - `wedge`: the direction wedge's positions, plain ECEF. * - `nativeAppearance`, `pickPosition`: the native look saved while the canvas draws it. * - `shown`, `surfaceCheckedFor`: the last visibility applied and the anchor last checked. */ diff --git a/src/layers/alpr/model.js b/src/layers/alpr/model.js index b9c1f64c2..82dc8e479 100644 --- a/src/layers/alpr/model.js +++ b/src/layers/alpr/model.js @@ -1,4 +1,4 @@ -import * as Cesium from 'cesium'; +import { toDegrees, toRadians } from '../../geo/index.js'; import { EARTH_MEAN_RADIUS_M } from './policy.js'; export * from './records.js'; @@ -12,9 +12,9 @@ export * from './records.js'; */ export function destinationPointDeg(latDeg, lonDeg, bearingDeg, distanceM) { const angularDistance = distanceM / EARTH_MEAN_RADIUS_M; - const bearing = Cesium.Math.toRadians(bearingDeg); - const lat1 = Cesium.Math.toRadians(latDeg); - const lon1 = Cesium.Math.toRadians(lonDeg); + const bearing = toRadians(bearingDeg); + const lat1 = toRadians(latDeg); + const lon1 = toRadians(lonDeg); const lat2 = Math.asin( Math.sin(lat1) * Math.cos(angularDistance) + Math.cos(lat1) * Math.sin(angularDistance) * Math.cos(bearing), @@ -26,8 +26,8 @@ export function destinationPointDeg(latDeg, lonDeg, bearingDeg, distanceM) { Math.cos(angularDistance) - Math.sin(lat1) * Math.sin(lat2), ); return { - latitude: Cesium.Math.toDegrees(lat2), - longitude: Cesium.Math.toDegrees(lon2), + latitude: toDegrees(lat2), + longitude: toDegrees(lon2), }; } diff --git a/src/layers/alpr/overlay.test.mjs b/src/layers/alpr/overlay.test.mjs index a84510aac..a0ba15e2d 100644 --- a/src/layers/alpr/overlay.test.mjs +++ b/src/layers/alpr/overlay.test.mjs @@ -284,3 +284,21 @@ test('a still view replaces floor anchors with the rendered surface, within the h.paint(); assert.equal(samples, taken, 'each anchor is checked once'); }); + +test('a bearing wedge is plain ECEF at the apex and its two far corners', () => { + const record = { latitude: 30.26, longitude: -97.74, directionDeg: 90 }; + const wedge = directionWedgePositions(record, 150, (lat) => + lat > 30.26 ? 160 : null, + ); + assert.equal(wedge.length, 3); + const apex = Cesium.Cartesian3.fromDegrees(-97.74, 30.26, 150); + assert.deepEqual({ ...wedge[0] }, { x: apex.x, y: apex.y, z: apex.z }); + const heights = wedge.map( + (p) => + Cesium.Cartographic.fromCartesian(new Cesium.Cartesian3(p.x, p.y, p.z)) + .height, + ); + // The corner north of the apex takes the sampled height; the other falls back. + assert.ok(heights.some((h) => Math.abs(h - 160) < 1e-6)); + assert.ok(heights.slice(1).some((h) => Math.abs(h - 150) < 1e-6)); +}); diff --git a/src/layers/alpr/visuals.js b/src/layers/alpr/visuals.js index 9f4d9899a..44c08a351 100644 --- a/src/layers/alpr/visuals.js +++ b/src/layers/alpr/visuals.js @@ -1,4 +1,4 @@ -import * as Cesium from 'cesium'; +import { fromDegrees } from '../../geo/index.js'; import { destinationPointDeg } from './model.js'; import { DIRECTION_CONE_M, @@ -8,8 +8,8 @@ import { import { roundHeadingDegrees } from '../../data/headingDegrees.js'; /** - * Badge scale at a camera distance, matching Cesium's NearFarScalar for the - * native badges (linear between near and far, clamped outside). + * Badge scale at a camera distance, matching the native badges' + * scale-by-distance (linear between near and far, clamped outside). * @param {number} distanceM Camera-to-marker distance. * @returns {number} Scale factor. */ @@ -75,7 +75,8 @@ export function alprLabelDetails(record, source) { * @param {function(number, number): (number|null)} [heightAt] Optional height * for the two far corners (degrees lat, lon), so the wedge follows a slope * instead of floating level from the apex; falls back to the apex height. - * @returns {Array|null} Apex, left and right corners. + * @returns {Array<{x: number, y: number, z: number}>|null} Apex, left and + * right corners, ECEF. */ export function directionWedgePositions(record, heightM = 0, heightAt = null) { if (!Number.isFinite(record.directionDeg)) return null; @@ -96,13 +97,9 @@ export function directionWedgePositions(record, heightM = 0, heightAt = null) { return Number.isFinite(height) ? height : heightM; }; return [ - Cesium.Cartesian3.fromDegrees(record.longitude, record.latitude, heightM), - Cesium.Cartesian3.fromDegrees(left.longitude, left.latitude, corner(left)), - Cesium.Cartesian3.fromDegrees( - right.longitude, - right.latitude, - corner(right), - ), + fromDegrees(record.longitude, record.latitude, heightM), + fromDegrees(left.longitude, left.latitude, corner(left)), + fromDegrees(right.longitude, right.latitude, corner(right)), ]; } diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index ae6dfd8ce..9207c830d 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -41,10 +41,8 @@ "src/input/sensorPick.js", "src/layers/airQuality/index.js", "src/layers/alpr/index.js", - "src/layers/alpr/model.js", "src/layers/alpr/overlay.js", "src/layers/alpr/presentation.js", - "src/layers/alpr/visuals.js", "src/layers/cctv/cards.js", "src/layers/cctv/geometry.js", "src/layers/cctv/geometryQueue.js",