Files
TREK/server/tests/unit/nest/atlas-coastal-fallback.test.ts
T
Ibrahim Roshdy 8023be452a fix(atlas): give a point no polygon contains to the nearest border
A point just off a simplified coastline lies in no admin0 polygon, and the
fallback then took the candidate with the smallest bounding box. Nice and
Menton sit ~80 m outside France's coast and 20+ km from Italy, but Italy's
box is the smaller one, so they resolved to IT. The fallback now ranks the
candidates by distance to their border. A deferred loose box (PS/XK) keeps
its priority. The parity test's reference lookup mirrors the new rule.

Closes #3048
2026-11-11 20:59:53 +00:00

27 lines
1.5 KiB
TypeScript

import { getCountryFromCoords } from '../../../src/utils/country-borders';
import { describe, expect, it } from 'vitest';
// A point that no admin0 polygon contains (just off a simplified coastline, or in a data
// gap) used to go to the candidate with the smallest bounding box. It now goes to the
// candidate whose border is nearest.
describe('getCountryFromCoords, a point no polygon contains', () => {
it('ATLAS-SVC-056: a point just off a simplified coastline goes to the nearest border, not the smallest box', () => {
// Central Nice lies about 80 m outside France's simplified coast and 20+ km from Italy,
// so no polygon contains it. Both boxes cover it and Italy's is the smaller one, so the
// smallest-box fallback put the whole Nice-Menton strip in Italy.
expect(getCountryFromCoords(43.6947, 7.2578)).toBe('FR'); // Hôtel Negresco, Nice
expect(getCountryFromCoords(43.6969, 7.2703)).toBe('FR'); // Place Masséna, Nice
expect(getCountryFromCoords(43.6598, 7.2137)).toBe('FR'); // Nice Côte d'Azur airport
expect(getCountryFromCoords(43.7753, 7.5029)).toBe('FR'); // Menton
});
it('ATLAS-SVC-057: the Riviera neighbours stay where they were', () => {
expect(getCountryFromCoords(43.7392, 7.428)).toBe('MC'); // Casino de Monte-Carlo
expect(getCountryFromCoords(43.7918, 7.6033)).toBe('IT'); // Ventimiglia
expect(getCountryFromCoords(43.817, 7.7751)).toBe('IT'); // Sanremo
expect(getCountryFromCoords(43.5814, 7.1237)).toBe('FR'); // Antibes
});
});