Fix regression in QPointF::operator==

Handle hard zero independently in each coordinate, otherwise hard zero
is never equal to anything but itself.

Task-number: QTBUG-69368
Change-Id: I8b1131472bb92efc706a04e0b067e2211a5ccb0c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2018-07-09 15:30:49 +02:00
parent 8c680ab469
commit ad8df72156
2 changed files with 5 additions and 3 deletions

View File

@ -351,9 +351,8 @@ QT_WARNING_DISABLE_GCC("-Wfloat-equal")
Q_DECL_CONSTEXPR inline bool operator==(const QPointF &p1, const QPointF &p2)
{
return ((!p1.xp && !p1.yp) || (!p2.xp && !p2.yp))
? (qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp))
: (qFuzzyCompare(p1.xp, p2.xp) && qFuzzyCompare(p1.yp, p2.yp));
return ((!p1.xp || !p2.xp) ? qFuzzyIsNull(p1.xp - p2.xp) : qFuzzyCompare(p1.xp, p2.xp))
&& ((!p1.yp || !p2.yp) ? qFuzzyIsNull(p1.yp - p2.yp) : qFuzzyCompare(p1.yp, p2.yp));
}
Q_DECL_CONSTEXPR inline bool operator!=(const QPointF &p1, const QPointF &p2)

View File

@ -450,6 +450,9 @@ void tst_QPointF::compare()
p3 -= QPointF(0.1, 0.1);
QVERIFY(p3 == QPointF());
// Test we can compare one dimension with hard zero
QVERIFY(QPointF(1.9543e-14, -32.0) == QPointF(0.0, -32.0));
}
QTEST_MAIN(tst_QPointF)