mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 02:44:02 +00:00
fix: find cables that cross an area between vertices
Cable searches only tested vertices, so a cable crossing an area with no vertex inside it was missed. Lines now test each segment against the area's bounds, across the antimeridian too, and against a radius area's great-circle distance.
This commit is contained in:
1 parent
5b73b70d19
commit
6f56c84b0b
4 files changed
+201
-5
No files matched your search
@@ -1,7 +1,12 @@
|
||||
/** Submarine cables and their landing points. */
|
||||
|
||||
import { defineTool, ToolError } from '../catalog.js';
|
||||
import { AREA_SCHEMA, areaContains, resolveArea } from '../area.js';
|
||||
import {
|
||||
AREA_SCHEMA,
|
||||
areaContains,
|
||||
lineTouchesArea,
|
||||
resolveArea,
|
||||
} from '../area.js';
|
||||
import { LIMIT_SCHEMA, capRows, countNoun } from '../results.js';
|
||||
|
||||
const ATTRIBUTION = '© TeleGeography — submarinecablemap.com (CC BY-NC-SA 3.0)';
|
||||
@@ -58,9 +63,7 @@ export const findSubmarineCables = defineTool({
|
||||
return false;
|
||||
return (
|
||||
!area ||
|
||||
cableLines(feature).some((line) =>
|
||||
line.some(([lon, lat]) => areaContains(area, { lat, lon })),
|
||||
)
|
||||
cableLines(feature).some((line) => lineTouchesArea(line, area))
|
||||
);
|
||||
})
|
||||
.map((feature) => ({
|
||||
|
||||
@@ -72,6 +72,21 @@ test('cables are found by area and name, with landing points and attribution', a
|
||||
catalog.call('find_submarine_cables', {}),
|
||||
/area, a name or both/,
|
||||
);
|
||||
// Areas a cable crosses between vertices, including at the antimeridian.
|
||||
const atlantic = await catalog.call('find_submarine_cables', {
|
||||
area: { bbox: [-30, 40, -20, 43] },
|
||||
});
|
||||
assert.deepEqual(
|
||||
atlantic.data.rows.map((row) => row.id),
|
||||
['marea'],
|
||||
);
|
||||
const pacific = await catalog.call('find_submarine_cables', {
|
||||
area: { bbox: [179, 34, -179, 35.5] },
|
||||
});
|
||||
assert.deepEqual(
|
||||
pacific.data.rows.map((row) => row.id),
|
||||
['unity'],
|
||||
);
|
||||
});
|
||||
|
||||
test('the local fetch serves bundled data files and nothing outside them', async () => {
|
||||
|
||||
Reference in new issue
Block a user