mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
The vessel source accepts an optional area and sends it as lat, lon and radius_km. The vessel layer asks for the area the camera shows (centered on the middle of the screen, sized by camera height), or every vessel from high enough up, and asks again when the view moves or zooms by a quarter of that radius. vessels_in_area names its area too. Servers that hold every vessel may ignore the area; callers still keep only what is inside it.
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
VIEW_AREA_MAX_RADIUS_KM,
|
|
VIEW_AREA_MIN_RADIUS_KM,
|
|
viewAreaMovedEnough,
|
|
viewAreaRadiusKm,
|
|
} from './viewArea.js';
|
|
|
|
test('the area asked for follows the camera height, and a wide view asks for every vessel', () => {
|
|
assert.equal(viewAreaRadiusKm(2_000), VIEW_AREA_MIN_RADIUS_KM);
|
|
assert.equal(viewAreaRadiusKm(80_000), 80);
|
|
assert.equal(
|
|
viewAreaRadiusKm(VIEW_AREA_MAX_RADIUS_KM * 1000),
|
|
VIEW_AREA_MAX_RADIUS_KM,
|
|
);
|
|
assert.equal(viewAreaRadiusKm(VIEW_AREA_MAX_RADIUS_KM * 1000 + 1), null);
|
|
assert.equal(viewAreaRadiusKm(Number.NaN), null);
|
|
});
|
|
|
|
test('a view asks again only after moving or zooming a quarter of its radius', () => {
|
|
const here = { lat: 37.8, lon: -122.4, radiusKm: 40 };
|
|
assert.equal(viewAreaMovedEnough(null, here), true);
|
|
assert.equal(viewAreaMovedEnough(here, null), true);
|
|
assert.equal(viewAreaMovedEnough(null, null), false);
|
|
assert.equal(viewAreaMovedEnough(here, { ...here, lat: 37.85 }), false);
|
|
assert.equal(viewAreaMovedEnough(here, { ...here, lat: 37.9 }), true);
|
|
assert.equal(viewAreaMovedEnough(here, { ...here, radiusKm: 45 }), false);
|
|
assert.equal(viewAreaMovedEnough(here, { ...here, radiusKm: 55 }), true);
|
|
});
|