From d517d5428c30d1e9ae4b6413116ea147a8b64f3c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 23 Apr 2018 13:46:55 +0200 Subject: Use qFuzzyCompare instead of qFuzzyIsNull in QPointF == qFuzzyIsNull has a fixed range, where qFuzzyCompare can tell if numbers are different in a more relative range. Without it QPointFs that are heavily scaled will be interpreted as identical, when they are quite different at their own scale. Task-number: QTBUG-60359 Task-number: QTBUG-62161 Change-Id: Ic4ba90e9e994aedff5548d690f053eb309b0a60b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/tools/qpoint.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qpoint.h') diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index 0f3e0c3517..ae46f0d39f 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -345,16 +345,24 @@ Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator*=(qreal c) xp*=c; yp*=c; return *this; } +QT_WARNING_PUSH +QT_WARNING_DISABLE_CLANG("-Wfloat-equal") +QT_WARNING_DISABLE_GCC("-Wfloat-equal") + Q_DECL_CONSTEXPR inline bool operator==(const QPointF &p1, const QPointF &p2) { - return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp); + 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)); } Q_DECL_CONSTEXPR inline bool operator!=(const QPointF &p1, const QPointF &p2) { - return !qFuzzyIsNull(p1.xp - p2.xp) || !qFuzzyIsNull(p1.yp - p2.yp); + return !(p1 == p2); } +QT_WARNING_POP + Q_DECL_CONSTEXPR inline const QPointF operator+(const QPointF &p1, const QPointF &p2) { return QPointF(p1.xp+p2.xp, p1.yp+p2.yp); -- cgit v1.2.3