Fix rectangleGeographic() throwing when a rectangle crosses the equator - #291
Open
pangwangshu wants to merge 1 commit into
Open
Fix rectangleGeographic() throwing when a rectangle crosses the equator#291pangwangshu wants to merge 1 commit into
pangwangshu wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #173.
Geometries.rectangleGeographic()already normalizes longitude for antimeridian wraparound (adding 360 whenx2 < 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.10721to0.07202(south to north, but passed torectangleGeographicin an order wherelat1 > lat2) — the resultingy1 > y2violates they2 >= y1precondition inRectangleFloat/RectangleDoubleand throwsIllegalArgumentException.This normalizes
lat1/lat2tomin/maxbefore constructing the rectangle, mirroring the existing longitude handling. The strict, non-normalizing behaviour of the plainrectangle()factory is unchanged — this only affectsrectangleGeographic(), whose whole purpose is to accept geographic points in path order and build a valid bounding box from them.Test plan
testRectangleLatLongCrossingEquatorNorthToSouthandtestRectangleLatLongCrossingEquatorSouthToNorthinGeometriesTest, covering both crossing directionsmvn test -Dtest=GeometriesTest— 19 passed, 0 failedmvn test— 313 passed, 0 failed, 1 skipped (pre-existing skip, unrelated)IllegalArgumentExceptionon the unpatched code and confirmed it no longer throws after the fix