summaryrefslogtreecommitdiff
path: root/src/positioning
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/positioning
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/positioning')
-rw-r--r--src/positioning/qgeocircle.cpp7
-rw-r--r--src/positioning/qgeocoordinate.cpp8
-rw-r--r--src/positioning/qgeorectangle.cpp30
3 files changed, 8 insertions, 37 deletions
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);
}