mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
fix(cctv): keep a clicked group in frame and let counts take clicks over plain fills
- 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.
This commit is contained in:
1 parent
f6982dc934
commit
aba4c9e533
14 files changed
+674
-41
No files matched your search
@@ -0,0 +1,69 @@
|
||||
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;
|
||||
|
||||
// A count of 40 cameras 40 km north of an eye 800 m up takes in a lone camera
|
||||
// 10 km north that is drawn just below it. The click must not land on the lone
|
||||
// camera alone: at least one of the 40 counted cameras must be in the frame.
|
||||
test('a count click does not fly to a lone camera that joined the count', () => {
|
||||
const viewer = {};
|
||||
const flights = [];
|
||||
const fovy = Math.PI / 3;
|
||||
const aspectRatio = 800 / 600;
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera: {
|
||||
pose: () => ({ fovy, aspectRatio, position: fromDegrees(0, 0, 800) }),
|
||||
flyToBounds: (bounds, options) => flights.push({ bounds, options }),
|
||||
},
|
||||
canvas: { clientHeight: 600, clientWidth: 800 },
|
||||
});
|
||||
try {
|
||||
const crowd = createCameraCell('crowd');
|
||||
const counted = [];
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const lat = (40_000 + i / 4) / M;
|
||||
addCellCamera(crowd, { lat, lon: 0, absoluteHeightM: 8 });
|
||||
counted.push(lat);
|
||||
}
|
||||
const lone = createCameraCell('lone');
|
||||
addCellCamera(lone, { lat: 10_000 / M, lon: 0, absoluteHeightM: 8 });
|
||||
const screens = [
|
||||
{ x: 400, y: 300 },
|
||||
{ x: 400, y: 330 },
|
||||
];
|
||||
const groups = mergeCountCells(
|
||||
[crowd, lone],
|
||||
() => screens.shift(),
|
||||
(count) =>
|
||||
count > 1 ? { width: 40, height: 40 } : { width: 24, height: 24 },
|
||||
2,
|
||||
);
|
||||
assert.equal(groups.length, 1);
|
||||
assert.equal(groups[0].count, 41);
|
||||
createNavigation({ state: { _viewer: viewer }, parts: {} }).zoomToCell(
|
||||
groups[0],
|
||||
);
|
||||
assert.equal(flights.length, 1);
|
||||
const { range } = flights[0].options.offset;
|
||||
const center = toLonLatH(flights[0].bounds.center);
|
||||
const halfY = range * Math.tan(fovy / 2);
|
||||
const inFrame = counted.filter(
|
||||
(lat) => Math.abs((lat - center.lat) * M) <= halfY,
|
||||
);
|
||||
assert.ok(
|
||||
inFrame.length > 0,
|
||||
`none of the 40 counted cameras is in the frame (range ${Math.round(range)} m, centre ${Math.round(center.lat * M)} m north)`,
|
||||
);
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user