summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/positioning/qgeorectangle.cpp36
-rw-r--r--tests/auto/qgeorectangle/tst_qgeorectangle.cpp8
2 files changed, 13 insertions, 31 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);
diff --git a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
index 59dc38be..06b65e86 100644
--- a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
+++ b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
@@ -1794,14 +1794,14 @@ void tst_QGeoRectangle::translate_data()
<< 20.0
<< 20.0
<< QGeoRectangle(QGeoCoordinate(90.0, -10.0),
- QGeoCoordinate(40.0, 50.0));
+ QGeoCoordinate(30.0, 50.0));
QTest::newRow("non wrapping -> south clip")
<< QGeoRectangle(QGeoCoordinate(-20.0, -30.0),
QGeoCoordinate(-80.0, 30.0))
<< -20.0
<< 20.0
- << QGeoRectangle(QGeoCoordinate(-40.0, -10.0),
+ << QGeoRectangle(QGeoCoordinate(-30.0, -10.0),
QGeoCoordinate(-90.0, 50.0));
QTest::newRow("wrapping -> non wrapping")
@@ -1826,14 +1826,14 @@ void tst_QGeoRectangle::translate_data()
<< 20.0
<< 20.0
<< QGeoRectangle(QGeoCoordinate(90.0, 150.0),
- QGeoCoordinate(40.0, -150.0));
+ QGeoCoordinate(30.0, -150.0));
QTest::newRow("wrapping -> south clip")
<< QGeoRectangle(QGeoCoordinate(-20.0, 130.0),
QGeoCoordinate(-80.0, -170.0))
<< -20.0
<< 20.0
- << QGeoRectangle(QGeoCoordinate(-40.0, 150.0),
+ << QGeoRectangle(QGeoCoordinate(-30.0, 150.0),
QGeoCoordinate(-90.0, -150.0));
}