diff --git a/src/main/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeBuilder.java b/src/main/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeBuilder.java index abddba9c5fd..3ff0735540b 100644 --- a/src/main/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeBuilder.java +++ b/src/main/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeBuilder.java @@ -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); } diff --git a/src/test/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeTest.java b/src/test/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeTest.java index bff99800fdb..122daa678c3 100644 --- a/src/test/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeTest.java +++ b/src/test/java/org/opentripplanner/service/worldenvelope/model/WorldEnvelopeTest.java @@ -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);