summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-01-10 16:29:12 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2019-01-14 09:00:08 +0000
commitb544e2fe22333f0a5fbd24a1ee106c5501a6b886 (patch)
tree08ceef1ba7efb5bfe8f8fc0a3dfb28ba95258c3c
parentc6cfb10b4eb8c227983fe7b4649cb0b691962743 (diff)
Fix QGeoRectangle::operator|=
This patch fixes the case when one QGeoRectangle contains the second, and wraps around. Change-Id: I7110c1864082c502845754fab2dc4e783455a446 Fixes: QTBUG-72935 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-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))