Skip to content

Commit

Permalink
Fix world envelope builder when crossing Greenwich meridian
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Mar 7, 2024
1 parent b40204e commit 1fbcc03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public WorldEnvelope build() {
// A small gap between the east and west longitude at 0 degrees implies that the Envelope
// should include the 0 degrees longitude(meridian), and be split at 180 degrees.
if (dist0 < dist180) {
return new WorldEnvelope(minLat, maxLonWest, maxLat, maxLonEast, transitMedianCenter);
// here we need to use the minLonWest as we want to go the furthest west we can and further
// west means smaller (negative) numbers of longitude
return new WorldEnvelope(minLat, minLonWest, maxLat, maxLonEast, transitMedianCenter);
} else {
return new WorldEnvelope(minLat, minLonEast, maxLat, minLonWest, transitMedianCenter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ void testEast() {
assertTrue(EAST.transitMedianCenter().isEmpty());
}

@Test
void crossingGreenwich() {
// Colchester, east of London
WgsCoordinate COLCHESTER = new WgsCoordinate(51.8926, 0.8981);
// Swindon, west of London
WgsCoordinate SWINDON = new WgsCoordinate(51.5711, -1.7880);
// Cutty Sark, very slightly west of Greenwich
WgsCoordinate CUTTY_SARK = new WgsCoordinate(51.4819,-0.0106);
var env = WorldEnvelope
.of()
.expandToIncludeStreetEntities(COLCHESTER.latitude(), COLCHESTER.longitude())
.expandToIncludeStreetEntities(SWINDON.latitude(), SWINDON.longitude())
.expandToIncludeStreetEntities(CUTTY_SARK.latitude(), CUTTY_SARK.longitude())
.build();
assertEquals(CUTTY_SARK.latitude(), env.lowerLeft().latitude());
assertEquals(SWINDON.longitude(), env.lowerLeft().longitude());

assertEquals(COLCHESTER.longitude(), env.upperRight().longitude());
assertEquals(COLCHESTER.latitude(), env.upperRight().latitude());
}

@Test
void transitMedianCenter() {
var expectedCenter = new WgsCoordinate(S10, E50);
Expand Down

0 comments on commit 1fbcc03

Please sign in to comment.