Files
gods-eye-view/src/layers/wildlifeSightings/viewport.test.mjs
T
Sameh Khamis 020a433b51 Merge main through #1591 into the renderer seam
Brings in the wildlife sightings layer (#1591, iNaturalist and Acartia
sightings). Its badges, density glow and privacy cells draw through the
draw port: the badges and the glow are icons sets (iconCollection.js
batches point writes into one upsert per task), and the privacy cells are
ground-clamped shapes and lines sets swapped whole. The eye, the view
rectangle, clicks, projection, ground readiness and frames come from the
camera, query, input, globe and frame ports, so the layer, its card and
its placement no longer import Cesium.

Differences from main: the density glow is drawn as pixel-sized splats
(56 px) instead of metre-sized ones with a near fade; the card's pan eases
with cubicOut, the contract's nearest ease-out; ground heights are
resampled when the globe's load progress settles or its surface changes,
rather than on tileset load events.

Also fixes two things the last merge left: a double-click that starts on
the followed track and ends off it reaches the renderer's own follow again
(a press that cannot end a double-click on the track gives its hold back
at its release), and the Active Fires heat drapes under the weather
imagery, so weather turned on after it stacks above. CURRENT-STATE notes
that the 2D and Columbus scene-mode checks are gone.
2026-11-09 23:06:26 -08:00

127 lines
4.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
wildlifeViewportBoxes,
snapWildlifeBox,
boxIntersects,
retryDelayMs,
} from './viewport.js';
import { ACARTIA_GUARD_BOX } from './policy.js';
import { getWildlifeHeightBand } from './model.js';
// The camera port's view rectangle is in degrees.
const viewer = (rectangle) => rectangle;
test('local boxes snap outward to 0.1 degrees; wider views to whole degrees', () => {
assert.deepEqual(
snapWildlifeBox({
south: 47.61,
west: -122.35,
north: 47.79,
east: -122.21,
}),
{ south: 47.6, west: -122.4, north: 47.8, east: -122.2 },
);
assert.deepEqual(
snapWildlifeBox({ south: 40.1, west: -126.2, north: 46.1, east: -121.1 }),
{ south: 40, west: -127, north: 47, east: -121 },
);
assert.deepEqual(
snapWildlifeBox({ south: 47.6, west: -122.4, north: 47.8, east: -122.2 }),
{ south: 47.6, west: -122.4, north: 47.8, east: -122.2 },
);
assert.equal(
snapWildlifeBox({ south: -20, west: -30, north: 21, east: 10 }),
null,
);
});
test('the final snapped span stays within 40 degrees and snapping is idempotent', () => {
for (const box of [
{ south: 10.2, west: 0, north: 50.1, east: 1 },
{ south: 0, west: 10.2, north: 1, east: 50.1 },
])
assert.equal(snapWildlifeBox(box), null, JSON.stringify(box));
for (const box of [
{ south: 47.4, west: -122.3, north: 47.6, east: -122.1 },
{ south: 10.01, west: -122.3, north: 14.99, east: -117.31 },
{ south: 10.01, west: 0, north: 15, east: 5 },
{ south: 10.01, west: 0, north: 15.01, east: 5 },
{ south: 10, west: 0, north: 50, east: 1 },
]) {
const snapped = snapWildlifeBox(box);
assert.ok(snapped, JSON.stringify(box));
assert.deepEqual(snapWildlifeBox(snapped), snapped);
}
});
test('intersections handle guard coverage, point boxes and antimeridian', () => {
const seattle = { south: 47.5, west: -122.5, north: 47.7, east: -122.2 };
assert.equal(boxIntersects(seattle, ACARTIA_GUARD_BOX), true);
assert.equal(
boxIntersects({ ...seattle, west: 20, east: 21 }, ACARTIA_GUARD_BOX),
false,
);
const dateline = { south: 10, west: 175, north: 20, east: -175 };
assert.equal(
boxIntersects(dateline, { south: 11, west: 178, north: 12, east: 179 }),
true,
);
assert.equal(
boxIntersects(dateline, { south: 11, west: -1, north: 12, east: 1 }),
false,
);
assert.equal(boxIntersects(null, seattle), false);
});
test('viewport rectangles split at 180 degrees and reject overly large or missing views', () => {
assert.deepEqual(
wildlifeViewportBoxes(
viewer({ south: 10, west: 179, north: 12, east: -178 }),
),
[
{ south: 10, west: 179, north: 12, east: 180 },
{ south: 10, west: -180, north: 12, east: -178 },
],
);
assert.deepEqual(
wildlifeViewportBoxes(
viewer({ south: 47, west: -123, north: 48, east: -122 }),
),
[{ south: 47, west: -123, north: 48, east: -122 }],
);
assert.equal(
wildlifeViewportBoxes(
viewer({ south: -21, west: -10, north: 20, east: 10 }),
),
null,
);
assert.equal(
wildlifeViewportBoxes(
viewer({ south: 0, west: 170, north: 10, east: -140 }),
),
null,
);
assert.equal(wildlifeViewportBoxes(null), null);
});
test('height bands retain representations across +/-5% and switch beyond +/-10%', () => {
assert.equal(getWildlifeHeightBand(3_000_001), 'global');
assert.equal(getWildlifeHeightBand(3_000_000), 'regional');
assert.equal(getWildlifeHeightBand(3_150_000, 'regional'), 'regional');
assert.equal(getWildlifeHeightBand(2_850_000, 'global'), 'global');
assert.equal(getWildlifeHeightBand(3_310_000, 'regional'), 'global');
assert.equal(getWildlifeHeightBand(2_690_000, 'global'), 'regional');
assert.equal(getWildlifeHeightBand(1_600_000), 'regional');
assert.equal(getWildlifeHeightBand(1_000_000), 'cells');
assert.equal(getWildlifeHeightBand(30_000), 'cards');
assert.equal(getWildlifeHeightBand(30_000, 'global'), 'cards');
});
test('retry guidance doubles from 30 seconds to a four-minute ceiling', () => {
assert.deepEqual(
[undefined, 30_000, 60_000, 120_000, 240_000].map(retryDelayMs),
[30_000, 60_000, 120_000, 240_000, 240_000],
);
});