Files
gods-eye-view/src/data/trackedCamera.test.mjs
T
Sameh Khamis e3a850bc9c Follow aircraft and satellites through the camera port
Flights and military follow their tracked aircraft with an
entityFollowTarget: framed in ENU from viewFrom, never closer than
150 m, presentation read from the drawn entity's record. Satellites
follow in Cesium's autodetect frame. The layers' own framing
(applyTrackedCameraFrame) goes; the port's follow has the same
close-range rules, and trackedCamera.js no longer imports Cesium.

The port's helper entity draws nothing: its point's outline is
transparent too, and click and voice picks of it count as picks of
the target's drawn entity. The fake camera binder follows when the
fake has Cesium's entity tracking.
2026-11-06 16:10:48 -08:00

70 lines
2.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import { trackedModelScaleForPixelCap } from './trackedCamera.js';
import { clampFollowEye as clampTrackedCameraPosition } from '../render/cesium/follow.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);
});