summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-08-08 16:19:10 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2016-11-30 12:20:59 +0000
commit720d637494f3cc6493a2b5f2a3405d9fb4ed464c (patch)
tree1d04f463a438dd272544b2c2198b0dfa326a5b6a /src
parent4ed9e84d5933a3eeaf55ac2f39fec826f0cadad0 (diff)
downloadqtlocation-720d637494f3cc6493a2b5f2a3405d9fb4ed464c.tar.gz
Use QLocationUtils::wrapLong thoughout the code
This patch remove if-else used to wrap longitude in the codebase, replacing with the existing utility method wrapLong Change-Id: I7a6eefa6f40b3dd0f47fec987c9197e294303873 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/location/qdeclarativecirclemapitem.cpp9
-rw-r--r--src/imports/location/qquickgeomapgesturearea.cpp1
-rw-r--r--src/positioning/qgeocircle.cpp7
-rw-r--r--src/positioning/qgeocoordinate.cpp8
-rw-r--r--src/positioning/qgeorectangle.cpp30
5 files changed, 12 insertions, 43 deletions
diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp
index f6b3c14f..5e33a1c5 100644
--- a/src/imports/location/qdeclarativecirclemapitem.cpp
+++ b/src/imports/location/qdeclarativecirclemapitem.cpp
@@ -46,6 +46,7 @@
#include <QPainter>
#include "qdoublevector2d_p.h"
+#include "qlocationutils_p.h"
/* poly2tri triangulator includes */
#include "../../3rdparty/poly2tri/common/shapes.h"
@@ -294,12 +295,8 @@ static void calculatePeripheralPoints(QList<QGeoCoordinate> &path,
qreal resultLonRad = lonRad + std::atan2(std::sin(azimuthRad) * cosLatRad_x_sinRatio,
cosRatio - sinLatRad * std::sin(resultLatRad));
qreal lat2 = qgeocoordinate_radToDeg(resultLatRad);
- qreal lon2 = qgeocoordinate_radToDeg(resultLonRad);
- if (lon2 < -180.0) {
- lon2 += 360.0;
- } else if (lon2 > 180.0) {
- lon2 -= 360.0;
- }
+ qreal lon2 = QLocationUtils::wrapLong(qgeocoordinate_radToDeg(resultLonRad));
+
path << QGeoCoordinate(lat2, lon2, center.altitude());
// Consider only points in the left half of the circle for the left bound.
if (azimuthRad > M_PI) {
diff --git a/src/imports/location/qquickgeomapgesturearea.cpp b/src/imports/location/qquickgeomapgesturearea.cpp
index ccf360aa..c115ce49 100644
--- a/src/imports/location/qquickgeomapgesturearea.cpp
+++ b/src/imports/location/qquickgeomapgesturearea.cpp
@@ -1017,6 +1017,7 @@ void QQuickGeoMapGestureArea::updatePinch()
// Add to starting zoom level. Sign of (dist-pinchstartdist) takes care of zoom in / out
m_pinch.m_zoom.m_start;
}
+
m_pinch.m_event.setCenter(mapFromScene(m_sceneCenter));
m_pinch.m_event.setAngle(m_twoTouchAngle);
diff --git a/src/positioning/qgeocircle.cpp b/src/positioning/qgeocircle.cpp
index 9552ac37..17263a42 100644
--- a/src/positioning/qgeocircle.cpp
+++ b/src/positioning/qgeocircle.cpp
@@ -384,12 +384,9 @@ void QGeoCircle::translate(double degreesLatitude, double degreesLongitude)
lat += degreesLatitude;
lon += degreesLongitude;
+ lon = QLocationUtils::wrapLong(lon);
- if (lon < -180.0)
- lon += 360.0;
- if (lon > 180.0)
- lon -= 360.0;
-
+ // TODO: remove this and simply clip latitude.
if (lat > 90.0) {
lat = 180.0 - lat;
if (lon < 0.0)
diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp
index 0386e859..8d39a62e 100644
--- a/src/positioning/qgeocoordinate.cpp
+++ b/src/positioning/qgeocoordinate.cpp
@@ -517,14 +517,8 @@ QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimut
double resultLon, resultLat;
QGeoCoordinatePrivate::atDistanceAndAzimuth(*this, distance, azimuth,
&resultLon, &resultLat);
-
- if (resultLon > 180.0)
- resultLon -= 360.0;
- else if (resultLon < -180.0)
- resultLon += 360.0;
-
double resultAlt = d->alt + distanceUp;
- return QGeoCoordinate(resultLat, resultLon, resultAlt);
+ return QGeoCoordinate(resultLat, QLocationUtils::wrapLong(resultLon), resultAlt);
}
/*!
diff --git a/src/positioning/qgeorectangle.cpp b/src/positioning/qgeorectangle.cpp
index 33d740ca..e74beee3 100644
--- a/src/positioning/qgeorectangle.cpp
+++ b/src/positioning/qgeorectangle.cpp
@@ -443,16 +443,8 @@ void QGeoRectangle::setCenter(const QGeoCoordinate &center)
double tlLon = center.longitude() - width / 2.0;
double brLat = center.latitude() - height / 2.0;
double brLon = center.longitude() + width / 2.0;
-
- if (tlLon < -180.0)
- tlLon += 360.0;
- if (tlLon > 180.0)
- tlLon -= 360.0;
-
- if (brLon < -180.0)
- brLon += 360.0;
- if (brLon > 180.0)
- brLon -= 360.0;
+ tlLon = QLocationUtils::wrapLong(tlLon);
+ brLon = QLocationUtils::wrapLong(brLon);
if (tlLat > 90.0) {
brLat = 2 * center.latitude() - 90.0;
@@ -518,18 +510,10 @@ void QGeoRectangle::setWidth(double degreesWidth)
QGeoCoordinate c = center();
double tlLon = c.longitude() - degreesWidth / 2.0;
-
- if (tlLon < -180.0)
- tlLon += 360.0;
- if (tlLon > 180.0)
- tlLon -= 360.0;
+ tlLon = QLocationUtils::wrapLong(tlLon);
double brLon = c.longitude() + degreesWidth / 2.0;
-
- if (brLon < -180.0)
- brLon += 360.0;
- if (brLon > 180.0)
- brLon -= 360.0;
+ brLon = QLocationUtils::wrapLong(brLon);
d->topLeft = QGeoCoordinate(tlLat, tlLon);
d->bottomRight = QGeoCoordinate(brLat, brLon);
@@ -666,11 +650,7 @@ QGeoCoordinate QGeoRectanglePrivate::center() const
if (topLeft.longitude() > bottomRight.longitude())
cLon = cLon - 180.0;
- if (cLon < -180.0)
- cLon += 360.0;
- if (cLon > 180.0)
- cLon -= 360.0;
-
+ cLon = QLocationUtils::wrapLong(cLon);
return QGeoCoordinate(cLat, cLon);
}