summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Wilson <alex.wilson@nokia.com>2011-12-20 13:56:03 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-21 00:29:44 +0100
commit0fe4f59487ca01531190cd06ac16da098356f291 (patch)
tree87dd9b7e8622223431439a874c1036b57c756ffc
parenta33eb5c3fed91671c44cd36f4688974bc96d7bc9 (diff)
downloadqtlocation-0fe4f59487ca01531190cd06ac16da098356f291.tar.gz
Using barymetric center for poly triangulation
Previous commit used boundingBox center, which will not work on some valid convex shapes. Barymetric center calculation should work on all simple convex polygons. Change-Id: I0915650c18a87ffcf7a2652ef57924894ae25833 Reviewed-by: David Laing <david.laing@nokia.com>
-rw-r--r--src/imports/location/qdeclarativepolygonmapitem.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp
index f3f510fa..5c9be19c 100644
--- a/src/imports/location/qdeclarativepolygonmapitem.cpp
+++ b/src/imports/location/qdeclarativepolygonmapitem.cpp
@@ -300,11 +300,17 @@ void MapPolygonNode::update(const QColor& fillColor, const QPolygonF& shape,
Vertex *vertices = (Vertex *)fill->vertexData();
- vertices[fillVertexCount++].position = QVector2D(shape.boundingRect().center());
+ qreal xSum = 0, ySum = 0, count = 0;
+ // skip the center point for now, we'll fill it in afterwards
+ fillVertexCount++;
for (int i = 0; i < shape.size(); ++i) {
+ xSum += shape.at(i).x();
+ ySum += shape.at(i).y();
+ count += 1.0;
vertices[fillVertexCount++].position = QVector2D(shape.at(i));
}
vertices[fillVertexCount++].position = QVector2D(shape.at(0));
+ vertices[0].position = QVector2D(xSum / count, ySum / count);
Q_ASSERT(fillVertexCount == fill->vertexCount());
markDirty(DirtyGeometry);