mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
- The flight after a count click checks the frame on both axes and at the height of the highest mount, so a group on a slope or in a very wide window stays in view; when it cannot, it flies to the nearest cell with two or more cameras, never to a lone camera that joined the count. - A count takes a click over a background fill no layer owns (earthquake discs, fire perimeters), and still yields to a scene item another layer registered. - A count crossing the HUD edge refreshes the view only when the active icon or a lone camera depends on it, and never mid-motion, so panning no longer runs extra full view passes. - A count restored at the HUD edge keeps the lone cameras its outline covers, and leaves the others as icons.
97 lines
2.7 KiB
JavaScript
97 lines
2.7 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { bindRenderer } from '../../render/rendererOf.js';
|
|
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
|
import {
|
|
addCellCamera,
|
|
createCameraCell,
|
|
mergeCountCells,
|
|
} from '../../data/cctvCellCounts.js';
|
|
import { createNavigation } from './navigation.js';
|
|
|
|
const M = 111_320;
|
|
|
|
function run({ aspectRatio, fovy, eye, pairs, groundM }) {
|
|
const viewer = {};
|
|
const flights = [];
|
|
const unbind = bindRenderer(viewer, {
|
|
camera: {
|
|
pose: () => ({ fovy, aspectRatio, position: eye }),
|
|
flyToBounds: (bounds, options) => flights.push({ bounds, options }),
|
|
},
|
|
canvas: { clientHeight: 600, clientWidth: Math.round(600 * aspectRatio) },
|
|
});
|
|
try {
|
|
const members = [];
|
|
const cells = pairs.map(({ eastM = 0, northM = 0, h }, i) => {
|
|
const cell = createCameraCell(String(i));
|
|
for (const d of [0, 10]) {
|
|
const m = { lon: (eastM + d) / M, lat: northM / M, h };
|
|
addCellCamera(cell, { lat: m.lat, lon: m.lon, absoluteHeightM: h });
|
|
members.push(m);
|
|
}
|
|
cell.groundM = h;
|
|
return cell;
|
|
});
|
|
const screens = [
|
|
{ x: 400, y: 300 },
|
|
{ x: 420, y: 300 },
|
|
];
|
|
const groups = mergeCountCells(
|
|
cells,
|
|
() => screens.shift(),
|
|
() => ({ width: 40, height: 40 }),
|
|
2,
|
|
);
|
|
assert.equal(groups.length, 1);
|
|
groups[0].groundM = groundM;
|
|
createNavigation({ state: { _viewer: viewer }, parts: {} }).zoomToCell(
|
|
groups[0],
|
|
);
|
|
const { range } = flights[0].options.offset;
|
|
const c = toLonLatH(flights[0].bounds.center);
|
|
const eyeH = c.height + range;
|
|
const tanY = Math.tan(fovy / 2);
|
|
const inFrame = members.filter((m) => {
|
|
const depth = eyeH - m.h;
|
|
if (!(depth > 0)) return false;
|
|
return (
|
|
Math.abs((m.lon - c.lon) * M) <= depth * tanY * aspectRatio &&
|
|
Math.abs((m.lat - c.lat) * M) <= depth * tanY
|
|
);
|
|
});
|
|
return { range, inFrame: inFrame.length, centerH: c.height };
|
|
} finally {
|
|
unbind();
|
|
}
|
|
}
|
|
|
|
test('a count click on pairs 300 m above the ground under the group centre keeps a member in the frame', () => {
|
|
const aspectRatio = 4 / 3;
|
|
const fovy = 2 * Math.atan(Math.tan(Math.PI / 6) / aspectRatio);
|
|
const r = run({
|
|
aspectRatio,
|
|
fovy,
|
|
eye: fromDegrees(0, 0, 900),
|
|
pairs: [
|
|
{ eastM: 3000, h: 800 },
|
|
{ eastM: 5000, h: 800 },
|
|
],
|
|
groundM: 500,
|
|
});
|
|
|
|
const flat = run({
|
|
aspectRatio,
|
|
fovy,
|
|
eye: fromDegrees(0, 0, 900),
|
|
pairs: [
|
|
{ eastM: 3000, h: 500 },
|
|
{ eastM: 5000, h: 500 },
|
|
],
|
|
groundM: 500,
|
|
});
|
|
|
|
assert.equal(flat.inFrame, 4);
|
|
assert.ok(r.inFrame > 0, `no member in frame: ${JSON.stringify(r)}`);
|
|
});
|