summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qrect.cpp62
-rw-r--r--src/corelib/tools/qrect.h2
-rw-r--r--tests/auto/qrect/tst_qrect.cpp2
3 files changed, 31 insertions, 35 deletions
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp
index 2082794c2a..b4fe07009a 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -2154,48 +2154,42 @@ bool QRectF::contains(const QRectF &r) const
QRectF QRectF::operator|(const QRectF &r) const
{
- qreal l1 = xp;
- qreal r1 = xp;
- if (w < 0)
- l1 += w;
- else
- r1 += w;
- if (l1 == r1) // null rect
+ if (isNull())
return r;
+ if (r.isNull())
+ return *this;
- qreal l2 = r.xp;
- qreal r2 = r.xp;
- if (r.w < 0)
- l2 += r.w;
+ qreal left = xp;
+ qreal right = xp;
+ if (w < 0)
+ left += w;
else
- r2 += r.w;
- if (l2 == r2) // null rect
- return *this;
+ right += w;
- qreal t1 = yp;
- qreal b1 = yp;
+ if (r.w < 0) {
+ left = qMin(left, r.xp + r.w);
+ right = qMax(right, r.xp);
+ } else {
+ left = qMin(left, r.xp);
+ right = qMax(right, r.xp + r.w);
+ }
+
+ qreal top = yp;
+ qreal bottom = yp;
if (h < 0)
- t1 += h;
+ top += h;
else
- b1 += h;
- if (t1 == b1) // null rect
- return r;
+ bottom += h;
- qreal t2 = r.yp;
- qreal b2 = r.yp;
- if (r.h < 0)
- t2 += r.h;
- else
- b2 += r.h;
- if (t2 == b2) // null rect
- return *this;
+ if (r.h < 0) {
+ top = qMin(top, r.yp + r.h);
+ bottom = qMax(bottom, r.yp);
+ } else {
+ top = qMin(top, r.yp);
+ bottom = qMax(bottom, r.yp + r.h);
+ }
- QRectF tmp;
- tmp.xp = qMin(l1, l2);
- tmp.yp = qMin(t1, t2);
- tmp.w = qMax(r1, r2) - tmp.xp;
- tmp.h = qMax(b1, b2) - tmp.yp;
- return tmp;
+ return QRectF(left, top, right - left, bottom - top);
}
/*!
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index 0740fe5cd6..efdc24da40 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -653,7 +653,7 @@ inline QRectF::QRectF(const QRect &r)
}
inline bool QRectF::isNull() const
-{ return qIsNull(w) && qIsNull(h); }
+{ return w == 0. && h == 0.; }
inline bool QRectF::isEmpty() const
{ return w <= 0. || h <= 0.; }
diff --git a/tests/auto/qrect/tst_qrect.cpp b/tests/auto/qrect/tst_qrect.cpp
index cdb556015d..5a916363f5 100644
--- a/tests/auto/qrect/tst_qrect.cpp
+++ b/tests/auto/qrect/tst_qrect.cpp
@@ -4125,6 +4125,7 @@ void tst_QRect::unitedRect_data()
QTest::newRow("test 13") << QRect() << QRect(10, 10, 10, 10) << QRect(10, 10, 10, 10);
QTest::newRow("test 14") << QRect(10, 10, 10, 10) << QRect() << QRect(10, 10, 10, 10);
QTest::newRow("test 15") << QRect() << QRect() << QRect();
+ QTest::newRow("test 16") << QRect(0, 0, 100, 0) << QRect(0, 0, 0, 100) << QRect(0, 0, 100, 100);
}
void tst_QRect::unitedRect()
@@ -4160,6 +4161,7 @@ void tst_QRect::unitedRectF_data()
QTest::newRow("test 13") << QRectF() << QRectF(10, 10, 10, 10) << QRectF(10, 10, 10, 10);
QTest::newRow("test 14") << QRectF(10, 10, 10, 10) << QRectF() << QRectF(10, 10, 10, 10);
QTest::newRow("test 15") << QRectF() << QRectF() << QRectF();
+ QTest::newRow("test 16") << QRectF(0, 0, 100, 0) << QRectF(0, 0, 0, 100) << QRectF(0, 0, 100, 100);
}
void tst_QRect::unitedRectF()