fix: handle antimeridian crossing in clampBoundsAroundCenter

east - west assumed a linear longitude axis, so a viewport crossing
the antimeridian (west=179.98, east=-179.98) produced a negative span
and unnormalized output coordinates outside [-180, 180). Wrap the span
through 360 and normalize the clamped west/east back into range.

Fixes #352.
This commit is contained in:
Ashfaq committed 2026-09-13 10:15:55 +05:30
1 parent 5f60d86bc9
commit c22ad6af32
2 files changed
+61 -3

No files matched your search

+27
View File
@@ -108,3 +108,30 @@ test('span clamp is idempotent on already-clamped bounds (loadRoadsForBounds re-
const twice = clampBoundsAroundCenter(once, midpoint, 0.05);
assert.deepEqual(twice, once);
});
test('span clamp handles bounds crossing the antimeridian', () => {
const bounds = {
south: -0.02,
north: 0.02,
west: 179.98,
east: -179.98,
};
const center = {
lat: 0,
lon: 179.99,
};
const result = clampBoundsAroundCenter(bounds, center, 0.05);
assert.ok(result.west >= -180 && result.west < 180);
assert.ok(result.east >= -180 && result.east < 180);
// Wrapped longitude span should remain about 0.04 degrees.
const span =
result.east >= result.west
? result.east - result.west
: result.east - result.west + 360;
assert.ok(Math.abs(span - 0.04) < 1e-12);
});