From 2e7f8dc341ab19db502fc4ff771de00960d3d636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 15 Sep 2023 23:28:16 +0200 Subject: [PATCH] Fixed map resolution computation for maps > world/2 --- src/map/map.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index 2ade9b9e..16b11761 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -62,9 +62,17 @@ RectC Map::llBounds() qreal Map::resolution(const QRectF &rect) { - qreal cy = rect.center().y(); - QPointF cl(rect.left(), cy); - QPointF cr(rect.right(), cy); + /* The haversine formula used in Coordinates::distanceTo() only gives + "half world" distances and shorter so we have to use only the center + "half rectangle" in case e.g. world map bounds are on the input */ + QRectF halfRect(QPointF(rect.left() + (rect.width() / 4.0), + rect.top() + (rect.height() / 4.0)), + QPointF(rect.right() - (rect.width() / 4.0), + rect.bottom() - (rect.height() / 4.0))); + + qreal cy = halfRect.center().y(); + QPointF cl(halfRect.left(), cy); + QPointF cr(halfRect.right(), cy); qreal ds = xy2ll(cl).distanceTo(xy2ll(cr)); qreal ps = QLineF(cl, cr).length();