diff options
author | Erik Mattsson <erik.mattsson@appello.com> | 2013-11-04 14:52:22 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-06 01:18:02 +0100 |
commit | e63de105fe71a0d825f8c82c75f17f65614aeb03 (patch) | |
tree | 4bcd1bfdb12431d21179d5bfd2495630a1203fe6 /src/imports/location/qdeclarativepolygonmapitem.cpp | |
parent | 3fa4c43b5285d628084c74354e82ea0ee981d3f1 (diff) |
Always use double point precision for geo lookups internally
This patch is to remedy rounding errors on ARM devices where
qreal is defined as a float instead of double.
The main change is to replace QPointF with QDoubleVector2D when using
screenPositionToCoordinate and coordinateToScreenPosition. In many
cases the QDoubleVector2D is converted to QPointF when the increased
precision is not used. This because many of the surounding classes uses
qreal so the precsision would be lost anyway. These classes include
QVectorPath, QPainterPath and QQuickItem.
The most important change is in polyline and polygon map item in the
updateSourcePoints methods. Using floating point precision here resulted
in many precision errors that caused for example route lines to be
chopped of as the method erroneously thought it needed to wrap to the other
side of the datum line.
The external uses of the coordinate lookup functions in declarative geo map
has been left untouched so they still use QPointF for compatibility reasons. Not
sure how the process goes when updating externally visible parts of the API
Change-Id: I01ed67a0563cfb5c4ff2db6395b7a62eaa8e4a19
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/imports/location/qdeclarativepolygonmapitem.cpp')
-rw-r--r-- | src/imports/location/qdeclarativepolygonmapitem.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp index efd8be2c..7b87bc29 100644 --- a/src/imports/location/qdeclarativepolygonmapitem.cpp +++ b/src/imports/location/qdeclarativepolygonmapitem.cpp @@ -55,6 +55,8 @@ #include <QPainterPath> #include <qnumeric.h> +#include "qdoublevector2d_p.h" + /* poly2tri triangulator includes */ #include "../../3rdparty/poly2tri/common/shapes.h" #include "../../3rdparty/poly2tri/sweep/cdt.h" @@ -156,14 +158,14 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map, if (!sourceDirty_) return; - qreal minX = -1.0; + double minX = -1.0; // build the actual path - QPointF origin; - QPointF lastPoint; + QDoubleVector2D origin; + QDoubleVector2D lastPoint; srcPath_ = QPainterPath(); - qreal unwrapBelowX = 0; + double unwrapBelowX = 0; if (preserveGeometry_ ) unwrapBelowX = map.coordinateToScreenPosition(geoLeftBound_, false).x(); @@ -173,7 +175,7 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map, if (!coord.isValid()) continue; - QPointF point = map.coordinateToScreenPosition(coord, false); + QDoubleVector2D point = map.coordinateToScreenPosition(coord, false); // We can get NaN if the map isn't set up correctly, or the projection // is faulty -- probably best thing to do is abort @@ -188,14 +190,14 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map, origin = point; minX = point.x(); srcOrigin_ = coord; - srcPath_.moveTo(point - origin); + srcPath_.moveTo(point.toPointF() - origin.toPointF()); lastPoint = point; } else { if (point.x() <= minX) minX = point.x(); - const QPointF diff = (point - lastPoint); + const QDoubleVector2D diff = (point - lastPoint); if (diff.x() * diff.x() + diff.y() * diff.y() >= 3.0) { - srcPath_.lineTo(point - origin); + srcPath_.lineTo(point.toPointF() - origin.toPointF()); lastPoint = point; } } @@ -207,7 +209,7 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map, srcPath_ = srcPath_.simplified(); sourceBounds_ = srcPath_.boundingRect(); - geoLeftBound_ = map.screenPositionToCoordinate(QPointF(minX, 0), false); + geoLeftBound_ = map.screenPositionToCoordinate(QDoubleVector2D(minX, 0), false); } /*! @@ -223,12 +225,12 @@ void QGeoMapPolygonGeometry::updateScreenPoints(const QGeoMap &map) return; } - QPointF origin = map.coordinateToScreenPosition(srcOrigin_, false); + QDoubleVector2D origin = map.coordinateToScreenPosition(srcOrigin_, false); // Create the viewport rect in the same coordinate system // as the actual points QRectF viewport(0, 0, map.width(), map.height()); - viewport.translate(-1 * origin); + viewport.translate(-1 * origin.toPointF()); QPainterPath vpPath; vpPath.addRect(viewport); @@ -621,7 +623,7 @@ void QDeclarativePolygonMapItem::dragStarted() */ void QDeclarativePolygonMapItem::dragEnded() { - QPointF newPoint = QPointF(x(),y()) + geometry_.firstPointOffset(); + QDoubleVector2D newPoint = QDoubleVector2D(x(),y()) + QDoubleVector2D(geometry_.firstPointOffset()); QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false); if (newCoordinate.isValid()) { double firstLongitude = path_.at(0).longitude(); |