mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
fix: keep clamped traffic bounds monotonic across the antimeridian
The previous fix wrapped the span correctly but normalized the returned west/east back into [-180, 180), which re-inverts the box whenever it crosses the antimeridian (west > east again). Downstream consumers (getBoundsCenter, boundsOverlap) assume west <= east and silently misbehave on an inverted box: the fetch center lands on the opposite side of the planet, and the overlap gate never skips a re-fetch. Drop the normalization and leave west/east unnormalized instead, so the box stays monotonic. The only remaining edge case (coordinates outside the conventional range reaching the Overpass query builder) is a visible, separate problem rather than a silently wrong center. Addresses review feedback on #392.
This commit is contained in:
1 parent
c22ad6af32
commit
830c372c12
2 files changed
+18
-25
No files matched your search
@@ -124,14 +124,15 @@ test('span clamp handles bounds crossing the antimeridian', () => {
|
||||
|
||||
const result = clampBoundsAroundCenter(bounds, center, 0.05);
|
||||
|
||||
assert.ok(result.west >= -180 && result.west < 180);
|
||||
assert.ok(result.east >= -180 && result.east < 180);
|
||||
// west/east are deliberately left unnormalized (may exceed 180) so that
|
||||
// west <= east always holds for downstream consumers (getBoundsCenter,
|
||||
// boundsOverlap) that assume a monotonic box. See #392 review.
|
||||
assert.ok(result.west <= result.east, `west/east not monotonic: ${result.west}, ${result.east}`);
|
||||
assert.ok(Math.abs(result.east - result.west - 0.04) < 1e-12);
|
||||
|
||||
// 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);
|
||||
// The plain-mean center a caller like getBoundsCenter computes must land
|
||||
// back on the antimeridian near the requested center, not ~180 degrees
|
||||
// away on the opposite side of the planet.
|
||||
const center2 = (result.west + result.east) / 2;
|
||||
assert.ok(Math.abs(center2 - center.lon) < 1e-9, `center drifted: ${center2}`);
|
||||
});
|
||||
Reference in new issue
Block a user