Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2,
if (x2 < x1) {
x2 += 360;
}
return rectangle(x1, lat1, x2, lat2);
float y1 = Math.min(lat1, lat2);
float y2 = Math.max(lat1, lat2);
return rectangle(x1, y1, x2, y2);
}

private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ public void testRectangleLatLong2() {
assertEquals(10, r.x2(), PRECISION);
}

@Test
public void testRectangleLatLongCrossingEquatorNorthToSouth() {
// entry point is north of the equator, exit point is south of it so
// latitude decreases from lat1 to lat2 (see issue 173)
Rectangle r = Geometries.rectangleGeographic(10, 5, 20, -5);
assertEquals(10, r.x1(), PRECISION);
assertEquals(20, r.x2(), PRECISION);
assertEquals(-5, r.y1(), PRECISION);
assertEquals(5, r.y2(), PRECISION);
}

@Test
public void testRectangleLatLongCrossingEquatorSouthToNorth() {
Rectangle r = Geometries.rectangleGeographic(10, -5, 20, 5);
assertEquals(10, r.x1(), PRECISION);
assertEquals(20, r.x2(), PRECISION);
assertEquals(-5, r.y1(), PRECISION);
assertEquals(5, r.y2(), PRECISION);
}

@Test
public void testPointLatLong() {
Point point = Geometries.pointGeographic(181, 25);
Expand Down