summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/positioning/qgeorectangle.cpp41
-rw-r--r--tests/auto/qgeorectangle/tst_qgeorectangle.cpp8
2 files changed, 31 insertions, 18 deletions
diff --git a/src/positioning/qgeorectangle.cpp b/src/positioning/qgeorectangle.cpp
index 337b4c76..a760831c 100644
--- a/src/positioning/qgeorectangle.cpp
+++ b/src/positioning/qgeorectangle.cpp
@@ -938,31 +938,36 @@ QGeoRectangle &QGeoRectangle::operator|=(const QGeoRectangle &rectangle)
bool joinWrapLeft = (nonWrapRight >= wrapLeft);
bool joinWrapRight = (nonWrapLeft <= wrapRight);
- if (joinWrapLeft) {
- if (joinWrapRight) {
- left = -180.0;
- right = 180.0;
- } else {
- left = nonWrapLeft;
- right = wrapRight;
- }
+ if (wrapLeft <= nonWrapLeft) { // The wrapping rectangle contains the non-wrapping one entirely
+ left = wrapLeft;
+ right = wrapRight;
} else {
- if (joinWrapRight) {
- left = wrapLeft;
- right = nonWrapRight;
- } else {
- double wrapRightDistance = nonWrapLeft - wrapRight;
- double wrapLeftDistance = wrapLeft - nonWrapRight;
-
- if (wrapLeftDistance == wrapRightDistance) {
+ if (joinWrapLeft) {
+ if (joinWrapRight) {
left = -180.0;
right = 180.0;
- } else if (wrapLeftDistance < wrapRightDistance) {
+ } else {
left = nonWrapLeft;
right = wrapRight;
- } else {
+ }
+ } else {
+ if (joinWrapRight) {
left = wrapLeft;
right = nonWrapRight;
+ } else {
+ double wrapRightDistance = nonWrapLeft - wrapRight;
+ double wrapLeftDistance = wrapLeft - nonWrapRight;
+
+ if (wrapLeftDistance == wrapRightDistance) {
+ left = -180.0;
+ right = 180.0;
+ } else if (wrapLeftDistance < wrapRightDistance) {
+ left = nonWrapLeft;
+ right = wrapRight;
+ } else {
+ left = wrapLeft;
+ right = nonWrapRight;
+ }
}
}
}
diff --git a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
index 01f0104b..219e8dfd 100644
--- a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
+++ b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
@@ -2080,6 +2080,14 @@ void tst_QGeoRectangle::unite_data()
<< QGeoRectangle(QGeoCoordinate(30.0, -180.0),
QGeoCoordinate(-30.0, 180.0));
+ QTest::newRow("wrapping and one containing other")
+ << QGeoRectangle(QGeoCoordinate(30.0, 40.0),
+ QGeoCoordinate(-30.0, -40.0))
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, 170.0))
+ << QGeoRectangle(QGeoCoordinate(30.0, 40.0),
+ QGeoCoordinate(-30.0, -40.0));
+
QTest::newRow("small gap over zero line")
<< QGeoRectangle(QGeoCoordinate(30.0, -20.0),
QGeoCoordinate(-30.0, -10.0))