diff options
Diffstat (limited to 'src/corelib/tools/qpoint.h')
-rw-r--r-- | src/corelib/tools/qpoint.h | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index 7df4d49005..50b4c864be 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -4,7 +4,9 @@ #ifndef QPOINT_H #define QPOINT_H +#include <QtCore/qcompare.h> #include <QtCore/qnamespace.h> +#include <QtCore/qnumeric.h> #include <QtCore/q20type_traits.h> #include <QtCore/q23utility.h> @@ -51,10 +53,10 @@ public: constexpr static inline int dotProduct(const QPoint &p1, const QPoint &p2) { return p1.xp * p2.xp + p1.yp * p2.yp; } - friend constexpr inline bool operator==(const QPoint &p1, const QPoint &p2) noexcept +private: + friend constexpr bool comparesEqual(const QPoint &p1, const QPoint &p2) noexcept { return p1.xp == p2.xp && p1.yp == p2.yp; } - friend constexpr inline bool operator!=(const QPoint &p1, const QPoint &p2) noexcept - { return p1.xp != p2.xp || p1.yp != p2.yp; } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QPoint) friend constexpr inline QPoint operator+(const QPoint &p1, const QPoint &p2) noexcept { return QPoint(p1.xp + p2.xp, p1.yp + p2.yp); } friend constexpr inline QPoint operator-(const QPoint &p1, const QPoint &p2) noexcept @@ -78,6 +80,7 @@ public: friend constexpr inline QPoint operator/(const QPoint &p, qreal c) { return QPoint(qRound(p.xp / c), qRound(p.yp / c)); } +public: #if defined(Q_OS_DARWIN) || defined(Q_QDOC) [[nodiscard]] Q_CORE_EXPORT CGPoint toCGPoint() const noexcept; #endif @@ -241,19 +244,25 @@ public: return p1.xp * p2.xp + p1.yp * p2.yp; } +private: QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE - friend constexpr inline bool operator==(const QPointF &p1, const QPointF &p2) + friend constexpr bool qFuzzyCompare(const QPointF &p1, const QPointF &p2) noexcept { 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)); } - friend constexpr inline bool operator!=(const QPointF &p1, const QPointF &p2) + QT_WARNING_POP + friend constexpr bool qFuzzyIsNull(const QPointF &point) noexcept { - return !(p1 == p2); + return qFuzzyIsNull(point.xp) && qFuzzyIsNull(point.yp); } - QT_WARNING_POP - + friend constexpr bool comparesEqual(const QPointF &p1, const QPointF &p2) noexcept + { return qFuzzyCompare(p1, p2); } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QPointF) + friend constexpr bool comparesEqual(const QPointF &p1, const QPoint &p2) noexcept + { return comparesEqual(p1, p2.toPointF()); } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QPointF, QPoint) friend constexpr inline QPointF operator+(const QPointF &p1, const QPointF &p2) { return QPointF(p1.xp + p2.xp, p1.yp + p2.yp); } friend constexpr inline QPointF operator-(const QPointF &p1, const QPointF &p2) @@ -272,6 +281,7 @@ public: return QPointF(p.xp / divisor, p.yp / divisor); } +public: constexpr QPoint toPoint() const; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) |