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.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:39:41 -08:00
1 parent df1143485a
commit f6ed35a887
5 files changed
+33 -20

No files matched your search

+1 -1
View File
@@ -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.
*/
+6 -6
View File
@@ -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),
};
}
+18
View File
@@ -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));
});
+8 -11
View File
@@ -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<Cesium.Cartesian3>|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)),
];
}
-2
View File
@@ -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",