Skip to content

Fix rectangleGeographic() throwing when a rectangle crosses the equator - #291

Open
pangwangshu wants to merge 1 commit into
davidmoten:masterfrom
pangwangshu:wapang/issue173
Open

Fix rectangleGeographic() throwing when a rectangle crosses the equator#291
pangwangshu wants to merge 1 commit into
davidmoten:masterfrom
pangwangshu:wapang/issue173

Conversation

@pangwangshu

Copy link
Copy Markdown

Summary

Fixes #173.

Geometries.rectangleGeographic() already normalizes longitude for antimeridian wraparound (adding 360 when x2 < x1), but had no equivalent handling for latitude. When a rectangle's entry latitude is greater than its exit latitude — as happens whenever a path crosses the equator from north to south, or in the reporter's case from -0.10721 to 0.07202 (south to north, but passed to rectangleGeographic in an order where lat1 > lat2) — the resulting y1 > y2 violates the y2 >= y1 precondition in RectangleFloat/RectangleDouble and throws IllegalArgumentException.

This normalizes lat1/lat2 to min/max before constructing the rectangle, mirroring the existing longitude handling. The strict, non-normalizing behaviour of the plain rectangle() factory is unchanged — this only affects rectangleGeographic(), whose whole purpose is to accept geographic points in path order and build a valid bounding box from them.

Test plan

  • Added testRectangleLatLongCrossingEquatorNorthToSouth and testRectangleLatLongCrossingEquatorSouthToNorth in GeometriesTest, covering both crossing directions
  • mvn test -Dtest=GeometriesTest — 19 passed, 0 failed
  • Full suite: mvn test — 313 passed, 0 failed, 1 skipped (pre-existing skip, unrelated)
  • Manually reproduced the reported IllegalArgumentException on the unpatched code and confirmed it no longer throws after the fix

rectangleGeographic() already normalized longitude for antimeridian
wraparound (x2 < x1) but not latitude, so lat1 > lat2 hit the y2 >= y1
precondition and threw IllegalArgumentException. Normalize lat1/lat2
to min/max, consistent with the existing longitude handling.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre conditions failing in Rectangle Implementation

1 participant