From 62facb72bbc4967fbf06cecf926cf49d7afdf098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sun, 21 May 2023 14:54:31 +0200 Subject: [PATCH 1/2] add test for bounding box of rotated projection --- Tests/src/MercatorProjection.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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()); +} From 2da9716f3433ac72a794de44ca925bc7ec94cdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sun, 21 May 2023 14:55:32 +0200 Subject: [PATCH 2/2] fix bounding box of rotated projection --- .../projection/MercatorProjection.cpp | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) 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)));