1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Use the boundingbox center instead of the centroid like Mapsforge does

This commit is contained in:
Martin Tůma 2024-11-21 19:05:08 +01:00
parent 6d450023b0
commit 071b16f76d

View File

@ -19,27 +19,6 @@ using namespace Mapsforge;
#define KEY_REF "ref" #define KEY_REF "ref"
#define KEY_ELE "ele" #define KEY_ELE "ele"
static Coordinates centroid(const QVector<Coordinates> &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<MapData::Path> *src, static void copyPaths(const RectC &rect, const QList<MapData::Path> *src,
QList<MapData::Path> *dst) QList<MapData::Path> *dst)
{ {
@ -711,7 +690,7 @@ bool MapData::readPaths(const VectorTile *tile, int zoom, QList<Path> *list)
p.point.coordinates = Coordinates(outline.first().lon() + MD(lon), p.point.coordinates = Coordinates(outline.first().lon() + MD(lon),
outline.first().lat() + MD(lat)); outline.first().lat() + MD(lat));
else if (p.closed) else if (p.closed)
p.point.coordinates = centroid(outline); p.point.coordinates = p.poly.boundingRect().center();
list->append(p); list->append(p);
} }