Skip to content

Commit

Permalink
Use the boundingbox center instead of the centroid like Mapsforge does
Browse files Browse the repository at this point in the history
  • Loading branch information
tumic0 committed Nov 21, 2024
1 parent 6d45002 commit 071b16f
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions src/map/mapsforge/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ using namespace Mapsforge;
#define KEY_REF "ref"
#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,
QList<MapData::Path> *dst)
{
Expand Down Expand Up @@ -711,7 +690,7 @@ bool MapData::readPaths(const VectorTile *tile, int zoom, QList<Path> *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);
}
Expand Down

0 comments on commit 071b16f

Please sign in to comment.