summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp14
-rw-r--r--src/corelib/tools/qpoint.cpp18
-rw-r--r--src/corelib/tools/qpoint.h12
3 files changed, 44 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp
index a83fd9a71f..8c6751cbaa 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp
@@ -79,6 +79,13 @@ p *= 2.5; // p becomes (-3, 10)
//! [5]
+//! [16]
+QPoint p( 3, 7);
+QPoint q(-1, 4);
+int lengthSquared = QPoint::dotProduct(p, q); // lengthSquared becomes 25
+//! [16]
+
+
//! [6]
QPoint p(-3, 10);
p /= 2.5; // p becomes (-1, 4)
@@ -147,3 +154,10 @@ p *= 2.5; // p becomes (-2.75, 10.25)
QPointF p(-2.75, 10.25);
p /= 2.5; // p becomes (-1.1, 4.1)
//! [15]
+
+
+//! [17]
+QPointF p( 3.1, 7.1);
+QPointF q(-1.0, 4.1);
+int lengthSquared = QPointF::dotProduct(p, q); // lengthSquared becomes 26.01
+//! [17]
diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp
index b3dd918a35..784d96bf1c 100644
--- a/src/corelib/tools/qpoint.cpp
+++ b/src/corelib/tools/qpoint.cpp
@@ -223,6 +223,15 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn static int QPoint::dotProduct(const QPoint &p1, const QPoint &p2)
+ \since 5.1
+
+ \snippet code/src_corelib_tools_qpoint.cpp 16
+
+ Returns the dot product of \a p1 and \a p2.
+*/
+
+/*!
\fn bool operator==(const QPoint &p1, const QPoint &p2)
\relates QPoint
@@ -712,6 +721,15 @@ QDebug operator<<(QDebug d, const QPointF &p)
*/
/*!
+ \fn static qreal QPointF::dotProduct(const QPointF &p1, const QPointF &p2)
+ \since 5.1
+
+ \snippet code/src_corelib_tools_qpoint.cpp 17
+
+ Returns the dot product of \a p1 and \a p2.
+*/
+
+/*!
\fn bool operator==(const QPointF &p1, const QPointF &p2)
\relates QPointF
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index b6446e8c9f..cb7a5ecd23 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -76,6 +76,8 @@ public:
inline QPoint &operator/=(qreal divisor);
+ Q_DECL_CONSTEXPR static inline int dotProduct(const QPoint &p1, const QPoint &p2);
+
friend Q_DECL_CONSTEXPR inline bool operator==(const QPoint &, const QPoint &);
friend Q_DECL_CONSTEXPR inline bool operator!=(const QPoint &, const QPoint &);
friend Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &, const QPoint &);
@@ -153,6 +155,9 @@ inline QPoint &QPoint::operator*=(double factor)
inline QPoint &QPoint::operator*=(int factor)
{ xp = xp*factor; yp = yp*factor; return *this; }
+Q_DECL_CONSTEXPR inline int QPoint::dotProduct(const QPoint &p1, const QPoint &p2)
+{ return p1.xp * p2.xp + p1.yp * p2.yp; }
+
Q_DECL_CONSTEXPR inline bool operator==(const QPoint &p1, const QPoint &p2)
{ return p1.xp == p2.xp && p1.yp == p2.yp; }
@@ -233,6 +238,8 @@ public:
inline QPointF &operator*=(qreal c);
inline QPointF &operator/=(qreal c);
+ Q_DECL_CONSTEXPR static inline qreal dotProduct(const QPointF &p1, const QPointF &p2);
+
friend Q_DECL_CONSTEXPR inline bool operator==(const QPointF &, const QPointF &);
friend Q_DECL_CONSTEXPR inline bool operator!=(const QPointF &, const QPointF &);
friend Q_DECL_CONSTEXPR inline const QPointF operator+(const QPointF &, const QPointF &);
@@ -330,6 +337,11 @@ inline QPointF &QPointF::operator*=(qreal c)
xp*=c; yp*=c; return *this;
}
+Q_DECL_CONSTEXPR inline qreal QPointF::dotProduct(const QPointF &p1, const QPointF &p2)
+{
+ return p1.xp * p2.xp + 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);