diff --git a/Tests/src/MercatorProjection.cpp b/Tests/src/MercatorProjection.cpp index a5c95dd4d..5a398956f 100644 --- a/Tests/src/MercatorProjection.cpp +++ b/Tests/src/MercatorProjection.cpp @@ -266,3 +266,19 @@ TEST_CASE("GetDimensions()") REQUIRE(projection.GetDimensions().GetDisplayText()==expectedBox.GetDisplayText()); } + +TEST_CASE("GetDimensions() with rotation") +{ + osmscout::MercatorProjection projection; + osmscout::GeoBox expectedBox(osmscout::GeoCoord(51.49061,7.42522), + osmscout::GeoCoord(51.53420,7.50528)); + + projection.Set(defaultCenter, + 0.524, // 30° + osmscout::Magnification(osmscout::Magnification::magClose), + defaultDpi, + defaultWidth, + defaultHeight); + + REQUIRE(projection.GetDimensions().GetDisplayText()==expectedBox.GetDisplayText()); +} diff --git a/libosmscout/src/osmscout/projection/MercatorProjection.cpp b/libosmscout/src/osmscout/projection/MercatorProjection.cpp index b7cfabc5e..698388057 100644 --- a/libosmscout/src/osmscout/projection/MercatorProjection.cpp +++ b/libosmscout/src/osmscout/projection/MercatorProjection.cpp @@ -124,14 +124,6 @@ namespace osmscout { PixelToGeo(0.0,0.0,topLeft); - GeoCoord topRight; - - PixelToGeo((double)width,0.0,topRight); - - GeoCoord bottomLeft; - - PixelToGeo(0.0,(double)height,bottomLeft); - GeoCoord bottomRight; PixelToGeo((double)width,(double)height,bottomRight); @@ -139,6 +131,20 @@ namespace osmscout { // evaluate bounding box, crop bounding box to valid Mercator area boundingBox=GeoBox(topLeft,bottomRight); + + if (angle!=0.0) { + // be aware that top-left, bottom-right bounding box may not include top-right and bottom-left coordinates when projection is rotated + GeoCoord topRight; + + PixelToGeo((double)width,0.0,topRight); + + GeoCoord bottomLeft; + + PixelToGeo(0.0,(double)height,bottomLeft); + + boundingBox.Include(GeoBox(topRight, bottomLeft)); + } + boundingBox.CropTo(GeoBox(GeoCoord(MinLat,MinLon), GeoCoord(MaxLat,MaxLon)));