From 071b16f76d5996c81e10e12c3e69809128ee8811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 21 Nov 2024 19:05:08 +0100 Subject: [PATCH] Use the boundingbox center instead of the centroid like Mapsforge does --- src/map/mapsforge/mapdata.cpp | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/map/mapsforge/mapdata.cpp b/src/map/mapsforge/mapdata.cpp index f902b7f3..2b9d01f1 100644 --- a/src/map/mapsforge/mapdata.cpp +++ b/src/map/mapsforge/mapdata.cpp @@ -19,27 +19,6 @@ using namespace Mapsforge; #define KEY_REF "ref" #define KEY_ELE "ele" - -static Coordinates centroid(const QVector &v) -{ - double area = 0; - double cx = 0, cy = 0; - - for (int i = 0; i < v.count() - 1; i++) { - const Coordinates &ci = v.at(i); - const Coordinates &cj = v.at(i+1); - double f = (ci.lon() * cj.lat() - cj.lon() * ci.lat()); - - area += f; - cx += (ci.lon() + cj.lon()) * f; - cy += (ci.lat() + cj.lat()) * f; - } - - double factor = 1.0 / (3.0 * area); - - return Coordinates(cx * factor, cy * factor); -} - static void copyPaths(const RectC &rect, const QList *src, QList *dst) { @@ -711,7 +690,7 @@ bool MapData::readPaths(const VectorTile *tile, int zoom, QList *list) p.point.coordinates = Coordinates(outline.first().lon() + MD(lon), outline.first().lat() + MD(lat)); else if (p.closed) - p.point.coordinates = centroid(outline); + p.point.coordinates = p.poly.boundingRect().center(); list->append(p); }