mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
fix(cctv): count a lone camera in the marker it sits against
A ground cell with one camera always drew its icon, so at some zooms a camera poked out from under a count marker with its own callout. An icon closer than the merge gap to a count marker now joins that marker: the count grows by one and the icon, its callout and its card are not drawn. Two lone cameras with no count beside them stay two icons, and the active camera always keeps its own icon.
This commit is contained in:
1 parent
c536d22ff0
commit
65942008bf
8 files changed
+125
-24
No files matched your search
@@ -91,6 +91,8 @@ function collectNeighbors(marker, grid, members, gap) {
|
||||
const bucket = grid.get(`${marker.col + col},${marker.row + row}`);
|
||||
if (!bucket) continue;
|
||||
for (const other of bucket) {
|
||||
// Lone cameras join a count beside them, never each other.
|
||||
if (marker.cell.count === 1 && other.cell.count === 1) continue;
|
||||
// Distance between the horizontal centre segments of the two pills.
|
||||
const extra = marker.halfSegment + other.halfSegment;
|
||||
const dx = Math.max(0, Math.abs(marker.x - other.x) - extra);
|
||||
@@ -107,6 +109,8 @@ function collectNeighbors(marker, grid, members, gap) {
|
||||
/**
|
||||
* Merge connected groups of overlapping horizontal pills. Each marker occupies
|
||||
* one grid bucket. Even the widest pill can only touch its eight neighbors.
|
||||
* A cell with one camera takes the footprint `sizeFor(1)` gives its icon and
|
||||
* joins a count it touches; two such cells alone stay apart.
|
||||
* Ground cells stay intact for the camera picker and individual-icon pass.
|
||||
*/
|
||||
export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
|
||||
@@ -94,3 +94,44 @@ test('stadiums merge by their own radii and segment lengths across grid boundari
|
||||
// Large pills can reach across a row boundary at their full diameter.
|
||||
check([7350, 7350], [origin, { x: 35, y: 88 }], [14700]);
|
||||
});
|
||||
|
||||
test('a lone camera joins a count it touches, and lone cameras alone stay apart', () => {
|
||||
const sizes = {
|
||||
1: { width: 24, height: 24 },
|
||||
9: { width: 40, height: 40 },
|
||||
};
|
||||
const gap = 4;
|
||||
const check = (counts, positions, expected) => {
|
||||
const cells = counts.map((count, i) => ({
|
||||
...createCameraCell(String(i)),
|
||||
count,
|
||||
}));
|
||||
let i = 0;
|
||||
const groups = mergeCountCells(
|
||||
cells,
|
||||
() => positions[i++],
|
||||
(count) => sizes[count],
|
||||
gap,
|
||||
);
|
||||
assert.deepEqual(
|
||||
groups.map((cell) => cell.count),
|
||||
expected,
|
||||
);
|
||||
// A lone camera that stays apart is still its own cell object.
|
||||
assert.deepEqual(
|
||||
groups.filter((cell) => cell.count === 1),
|
||||
cells.filter((cell) => groups.includes(cell) && cell.count === 1),
|
||||
);
|
||||
};
|
||||
const at = (x, y = 100) => ({ x, y });
|
||||
// Radii 20 and 12: the four-pixel gap is clear at 36 pixels.
|
||||
check([9, 1], [at(100), at(135)], [10]);
|
||||
check([9, 1], [at(100), at(136)], [9, 1]);
|
||||
check([1, 9], [at(135), at(100)], [10]);
|
||||
// Overlapping icons with no count beside them stay two icons.
|
||||
check([1, 1], [at(100), at(110)], [1, 1]);
|
||||
// A count takes every lone camera it touches, on either side.
|
||||
check([1, 9, 1], [at(70), at(100), at(130)], [11]);
|
||||
// A lone camera that only touches another lone camera is left alone.
|
||||
check([1, 1, 9], [at(40), at(70), at(100)], [1, 10]);
|
||||
});
|
||||
@@ -332,6 +332,43 @@ test('a crowded cell shows its count and a singleton keeps its icon', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('a lone camera beside a count joins it, unless it is the active camera', () => {
|
||||
// Three cameras north of a cell boundary, one 111 m away south of it.
|
||||
const { records } = recordsAt([
|
||||
[0.0005, 0.0005],
|
||||
[0.0006, 0.0005],
|
||||
[0.0007, 0.0005],
|
||||
[0.0006, -0.0005],
|
||||
[0.2, 0],
|
||||
]);
|
||||
seedCoverage({ viewer: viewerAt(20_000), records });
|
||||
refreshHorizonCulling();
|
||||
assert.deepEqual(shownIds(records), ['cam-4']);
|
||||
assert.deepEqual(_viewRecordIdsForTest(), ['cam-4']);
|
||||
assert.deepEqual(
|
||||
markers().map((item) => item.cell.count),
|
||||
[4],
|
||||
);
|
||||
assert.deepEqual(
|
||||
cctvLayer.getDetectableObjects().map((o) => o.sourceId),
|
||||
['cam-4'],
|
||||
);
|
||||
// The picker still offers one camera from each ground cell.
|
||||
assert.equal(cctvLayer.getUIState().cameraIndex.length, 3);
|
||||
|
||||
seedCoverage({
|
||||
viewer: viewerAt(20_000),
|
||||
records,
|
||||
activeCameraId: 'cam-3',
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
assert.deepEqual(shownIds(records), ['cam-3', 'cam-4']);
|
||||
assert.deepEqual(
|
||||
markers().map((item) => item.cell.count),
|
||||
[3],
|
||||
);
|
||||
});
|
||||
|
||||
test('a pan keeps the same winners, and an unchanged view keeps its list', () => {
|
||||
const { records } = recordsAt(CLUSTER);
|
||||
seedCoverage({
|
||||
@@ -698,20 +735,22 @@ test('overlapping cells merge at their weighted centre and keep every camera in
|
||||
});
|
||||
refreshHorizonCulling();
|
||||
const shown = markers();
|
||||
assert.deepEqual(shownIds(records), ['cam-7', 'cam-8']);
|
||||
// The lone camera 111 m south sits under the merged marker and joins it;
|
||||
// the active one beside it keeps its own icon.
|
||||
assert.deepEqual(shownIds(records), ['cam-7']);
|
||||
assert.equal(
|
||||
shown.reduce((sum, m) => sum + m.cell.count, 0),
|
||||
7,
|
||||
8,
|
||||
);
|
||||
assert.deepEqual(
|
||||
shown.map((m) => m.cell.count).sort((a, b) => a - b),
|
||||
[2, 5],
|
||||
[2, 6],
|
||||
);
|
||||
const merged = shown.find((m) => m.cell.count === 5);
|
||||
const merged = shown.find((m) => m.cell.count === 6);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(
|
||||
merged.pos,
|
||||
Cesium.Cartesian3.fromDegrees(0.0008, 0, 10),
|
||||
Cesium.Cartesian3.fromDegrees(0.004 / 6, -0.001 / 6, 10),
|
||||
) < 0.01,
|
||||
);
|
||||
const positions = shown.map((m) => [m.cell.key, m.pos, m.height, m.width]);
|
||||
@@ -720,13 +759,10 @@ test('overlapping cells merge at their weighted centre and keep every camera in
|
||||
clickMarker(merged);
|
||||
const { bounds } = flights.at(-1);
|
||||
assert.ok(
|
||||
records
|
||||
.slice(0, 5)
|
||||
.every(
|
||||
(r) =>
|
||||
Cesium.Cartesian3.distance(r.position, bounds.center) <
|
||||
bounds.radius,
|
||||
),
|
||||
[...records.slice(0, 5), records[8]].every(
|
||||
(r) =>
|
||||
Cesium.Cartesian3.distance(r.position, bounds.center) < bounds.radius,
|
||||
),
|
||||
);
|
||||
assert.ok(
|
||||
bounds.radius < 300,
|
||||
|
||||
Reference in new issue
Block a user