mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Flights, military, satellites, installations, local ADS-B and ALPR hung gevTrackedId, gevDisplayPosition, gevVisualPosition, gevSelectionOrigin and gevLabelModel on the Cesium entities they draw, and the tracked readout, follow camera, cockpit, share links and awareness read them back. They now live in src/data/entityRecords.js, a Core-owned record per entity: layers write entityRecord(entity), readers use readEntityRecord(entity). Nothing changes on screen. This is the first slice of the renderer plan's state mirror (P1). The module is exported as ./data/entity-records so hosted code can read the same records, and window.__godsEyeView.entityRecords gives the QA scripts the same access from the page.
93 lines
3.1 KiB
JavaScript
93 lines
3.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as Cesium from 'cesium';
|
|
import {
|
|
clampTrackedCameraPosition,
|
|
trackedDisplayPositionForCamera,
|
|
trackedModelScaleForPixelCap,
|
|
} from './trackedCamera.js';
|
|
import { withEntityRecord } from './entityRecords.js';
|
|
|
|
test('tracked camera origin crossing returns to the prior side at the minimum range', () => {
|
|
const camera = {
|
|
position: new Cesium.Cartesian3(0, 500, -300),
|
|
direction: new Cesium.Cartesian3(0, -1, 0),
|
|
};
|
|
const previous = new Cesium.Cartesian3(0, -1000, 600);
|
|
assert.equal(clampTrackedCameraPosition(camera, previous, 150), true);
|
|
assert.ok(Cesium.Cartesian3.dot(camera.position, previous) > 0);
|
|
assert.ok(Math.abs(Cesium.Cartesian3.magnitude(camera.position) - 150) < 1e-9);
|
|
});
|
|
|
|
test('tracked camera clamps a too-close approach along the current sight line', () => {
|
|
const camera = {
|
|
position: new Cesium.Cartesian3(0, -80, 0),
|
|
direction: new Cesium.Cartesian3(0, 1, 0),
|
|
};
|
|
const previous = new Cesium.Cartesian3(0, -200, 0);
|
|
assert.equal(clampTrackedCameraPosition(camera, previous, 150), true);
|
|
assert.ok(Math.abs(camera.position.x) === 0);
|
|
assert.equal(camera.position.y, -150);
|
|
assert.ok(Math.abs(camera.position.z) === 0);
|
|
});
|
|
|
|
test('tracked camera leaves a safe approach unchanged', () => {
|
|
const camera = {
|
|
position: new Cesium.Cartesian3(0, -800, 500),
|
|
direction: Cesium.Cartesian3.normalize(
|
|
new Cesium.Cartesian3(0, 800, -500),
|
|
new Cesium.Cartesian3(),
|
|
),
|
|
};
|
|
const previous = Cesium.Cartesian3.clone(camera.position);
|
|
const before = Cesium.Cartesian3.clone(camera.position);
|
|
assert.equal(clampTrackedCameraPosition(camera, previous, 150), false);
|
|
assert.deepEqual(camera.position, before);
|
|
});
|
|
|
|
test('tracked model keeps calibrated scale when it projects below the pixel cap', () => {
|
|
const scale = trackedModelScaleForPixelCap({
|
|
baseScale: 24,
|
|
nativeRadiusM: 1.43,
|
|
rangeM: 1000,
|
|
viewportHeightPx: 800,
|
|
fovyRad: Math.PI / 3,
|
|
maximumPixelSize: 104,
|
|
});
|
|
assert.equal(scale, 24);
|
|
});
|
|
|
|
test('tracked model shrinks smoothly when close enough to exceed the pixel cap', () => {
|
|
const scale = trackedModelScaleForPixelCap({
|
|
baseScale: 24,
|
|
nativeRadiusM: 1.43,
|
|
rangeM: 150,
|
|
viewportHeightPx: 800,
|
|
fovyRad: Math.PI / 3,
|
|
maximumPixelSize: 104,
|
|
});
|
|
const focalLengthPx = 800 / (2 * Math.tan(Math.PI / 6));
|
|
const projectedDiameterPx = (2 * 1.43 * scale * focalLengthPx) / 150;
|
|
assert.ok(scale < 24);
|
|
assert.ok(Math.abs(projectedDiameterPx - 104) < 1e-9);
|
|
});
|
|
|
|
test('tracked camera prefers the already-rendered display cache', () => {
|
|
let callbackReads = 0;
|
|
const cached = new Cesium.Cartesian3(1, 2, 3);
|
|
const entity = withEntityRecord({ position: {
|
|
getValue: () => {
|
|
callbackReads += 1;
|
|
return new Cesium.Cartesian3(4, 5, 6);
|
|
},
|
|
} }, { displayPosition: () => cached });
|
|
const result = trackedDisplayPositionForCamera(
|
|
entity,
|
|
Cesium.JulianDate.now(),
|
|
new Cesium.Cartesian3(),
|
|
);
|
|
assert.deepEqual(result, cached);
|
|
assert.notEqual(result, cached);
|
|
assert.equal(callbackReads, 0);
|
|
});
|