From f9327fecc1dca707a10b52ffe13b0240320b85fe Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 16 Feb 2012 07:42:11 +0100 Subject: QPoint/QPointF: inline manhattanLength(); QLineF: inline isNull() There's no reason for them not to be, and it's a prerequisite for making these functions constexpr. Change-Id: I03c9965147b51014c7af60a4c2d7f25a3f6e21a7 Reviewed-by: David Faure Reviewed-by: Gunnar Sletta --- src/corelib/tools/qline.cpp | 8 ++------ src/corelib/tools/qline.h | 5 +++++ src/corelib/tools/qpoint.cpp | 11 +++-------- src/corelib/tools/qpoint.h | 8 ++++++++ 4 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index 1ca9a59bde..78f1c44263 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -412,16 +412,12 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) */ /*! + \fn bool QLineF::isNull() const + Returns true if the line is not set up with valid start and end point; otherwise returns false. */ -bool QLineF::isNull() const -{ - return (qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y())) ? true : false; -} - - /*! \fn QPointF QLineF::p1() const diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index 3c7977a207..58ef0316ad 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -310,6 +310,11 @@ inline qreal QLineF::y2() const return pt2.y(); } +inline bool QLineF::isNull() const +{ + return qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y()); +} + inline QPointF QLineF::p1() const { return pt1; diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index 55a2261cb9..ecbe9deb9f 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -402,6 +402,8 @@ QDataStream &operator>>(QDataStream &s, QPoint &p) #endif // QT_NO_DATASTREAM /*! + \fn int QPoint::manhattanLength() const + Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" of the vector from the origin to the point. For example: @@ -417,10 +419,6 @@ QDataStream &operator>>(QDataStream &s, QPoint &p) apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan. */ -int QPoint::manhattanLength() const -{ - return qAbs(x())+qAbs(y()); -} #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QPoint &p) { @@ -505,6 +503,7 @@ QDebug operator<<(QDebug d, const QPointF &p) /*! + \fn qreal QPointF::manhattanLength() const \since 4.6 Returns the sum of the absolute values of x() and y(), @@ -513,10 +512,6 @@ QDebug operator<<(QDebug d, const QPointF &p) \sa QPoint::manhattanLength() */ -qreal QPointF::manhattanLength() const -{ - return qAbs(x())+qAbs(y()); -} /*! \fn qreal QPointF::x() const diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index 827de3936c..2e987fcf41 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -130,6 +130,9 @@ inline void QPoint::setX(int xpos) inline void QPoint::setY(int ypos) { yp = ypos; } +inline int QPoint::manhattanLength() const +{ return qAbs(x())+qAbs(y()); } + inline int &QPoint::rx() { return xp; } @@ -267,6 +270,11 @@ inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { } inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { } +inline qreal QPointF::manhattanLength() const +{ + return qAbs(x())+qAbs(y()); +} + inline bool QPointF::isNull() const { return qIsNull(xp) && qIsNull(yp); -- cgit v1.2.3