mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-12-01 07:01:16 +01:00
Code cleanup
This commit is contained in:
parent
3b16f37e66
commit
fa0c09b30c
@ -203,23 +203,18 @@ static qreal area(const QVector<QPointF> &polygon)
|
|||||||
|
|
||||||
static QPointF centroid(const QVector<QPointF> polygon)
|
static QPointF centroid(const QVector<QPointF> polygon)
|
||||||
{
|
{
|
||||||
qreal cx = 0, cy = 0, factor = 0;
|
qreal cx = 0, cy = 0;
|
||||||
qreal A = area(polygon);
|
qreal factor = 1.0 / (6.0 * area(polygon));
|
||||||
|
|
||||||
for (int i = 0; i < polygon.size(); i++) {
|
for (int i = 0; i < polygon.size(); i++) {
|
||||||
int j = (i + 1) % polygon.size();
|
int j = (i + 1) % polygon.size();
|
||||||
factor=(polygon.at(i).x() * polygon.at(j).y() - polygon[j].x()
|
qreal f = (polygon.at(i).x() * polygon.at(j).y() - polygon.at(j).x()
|
||||||
* polygon[i].y());
|
* polygon.at(i).y());
|
||||||
cx+=(polygon[i].x() + polygon[j].x()) * factor;
|
cx += (polygon.at(i).x() + polygon.at(j).x()) * f;
|
||||||
cy+=(polygon[i].y() + polygon[j].y()) * factor;
|
cy += (polygon.at(i).y() + polygon.at(j).y()) * f;
|
||||||
}
|
}
|
||||||
|
|
||||||
A *= 6.0f;
|
return QPointF(cx * factor, cy * factor);
|
||||||
factor = 1/A;
|
|
||||||
cx *= factor;
|
|
||||||
cy *= factor;
|
|
||||||
|
|
||||||
return QPointF(cx, cy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rectNearPolygon(const QPolygonF &polygon, const QRectF &rect)
|
static bool rectNearPolygon(const QPolygonF &polygon, const QRectF &rect)
|
||||||
|
Loading…
Reference in New Issue
Block a user