diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-08-06 13:17:15 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-11-30 12:20:58 +0000 |
commit | 4ed9e84d5933a3eeaf55ac2f39fec826f0cadad0 (patch) | |
tree | 80b60ff9e0ec7fda0ac773920eb1f231d11a0531 /src/positioning/qgeorectangle.cpp | |
parent | cd8880cc04b22610e835e6cc02cc16ac22ec9fae (diff) | |
download | qtlocation-4ed9e84d5933a3eeaf55ac2f39fec826f0cadad0.tar.gz |
Change QGeoRectangle::translate to not modify the rectangle
QGeoRectangle::translate currently modifies the rectangle if the
latitudinal offset brings the rectangle out of bounds.
This patch changes the behavior of the translation, clamping the
latitudinal offset, and preventing changes to the rectangle geometry.
Change-Id: Iedb8823bbd6e3c04ee499bb9f9945049a9590aae
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/positioning/qgeorectangle.cpp')
-rw-r--r-- | src/positioning/qgeorectangle.cpp | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/src/positioning/qgeorectangle.cpp b/src/positioning/qgeorectangle.cpp index a8d74414..33d740ca 100644 --- a/src/positioning/qgeorectangle.cpp +++ b/src/positioning/qgeorectangle.cpp @@ -44,6 +44,7 @@ #include "qdoublevector2d_p.h" #include "qgeocoordinate.h" #include "qnumeric.h" +#include "qlocationutils_p.h" #include <QList> QT_BEGIN_NAMESPACE @@ -767,37 +768,18 @@ void QGeoRectangle::translate(double degreesLatitude, double degreesLongitude) double brLat = d->bottomRight.latitude(); double brLon = d->bottomRight.longitude(); - if ((tlLat != 90.0) || (brLat != -90.0)) { - tlLat += degreesLatitude; - brLat += degreesLatitude; - } + if (degreesLatitude >= 0.0) + degreesLatitude = qMin(degreesLatitude, 90.0 - tlLat); + else + degreesLatitude = qMax(degreesLatitude, -90.0 - brLat); if ( (tlLon != -180.0) || (brLon != 180.0) ) { - tlLon += degreesLongitude; - brLon += degreesLongitude; + tlLon = QLocationUtils::wrapLong(tlLon + degreesLongitude); + brLon = QLocationUtils::wrapLong(brLon + degreesLongitude); } - 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; - - if (tlLat > 90.0) - tlLat = 90.0; - - if (tlLat < -90.0) - tlLat = -90.0; - - if (brLat > 90.0) - brLat = 90.0; - - if (brLat < -90.0) - brLat = -90.0; + tlLat += degreesLatitude; + brLat += degreesLatitude; d->topLeft = QGeoCoordinate(tlLat, tlLon); d->bottomRight = QGeoCoordinate(brLat, brLon); |