summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2015-01-26 10:21:56 +0400
committerSean Harmer <sean.harmer@kdab.com>2015-01-28 12:37:47 +0000
commita14559bc781b9ac7c61386bf563e62f6fde27d56 (patch)
tree40a90962e641bc2437f5ac609278929c8725fd9e
parent6462744b6bc94f5298881f34d8894a644e21c716 (diff)
[QVectorND] Add missing operator/=(const QVectorND &)
Change-Id: Ic1d2912808b95e02ba5d9cb2972c81c6374bbca9 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/gui/math3d/qvector2d.cpp21
-rw-r--r--src/gui/math3d/qvector2d.h14
-rw-r--r--src/gui/math3d/qvector3d.cpp21
-rw-r--r--src/gui/math3d/qvector3d.h15
-rw-r--r--src/gui/math3d/qvector4d.cpp21
-rw-r--r--src/gui/math3d/qvector4d.h16
-rw-r--r--tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp161
7 files changed, 261 insertions, 8 deletions
diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp
index c46dd35766..cf8ff25661 100644
--- a/src/gui/math3d/qvector2d.cpp
+++ b/src/gui/math3d/qvector2d.cpp
@@ -316,6 +316,16 @@ float QVector2D::distanceToLine
*/
/*!
+ \fn QVector2D &QVector2D::operator/=(const QVector2D &vector)
+ \since 5.5
+
+ Divides the components of this vector by the corresponding
+ components in \a vector.
+
+ \sa operator*=()
+*/
+
+/*!
Returns the dot product of \a v1 and \a v2.
*/
float QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
@@ -407,6 +417,17 @@ float QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
*/
/*!
+ \fn const QVector2D operator/(const QVector2D &vector, const QVector2D &divisor)
+ \relates QVector2D
+ \since 5.5
+
+ Returns the QVector2D object formed by dividing components of the given
+ \a vector by a respective components of the given \a divisor.
+
+ \sa QVector2D::operator/=()
+*/
+
+/*!
\fn bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2)
\relates QVector2D
diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h
index 2cacd8ade0..ef69c80afe 100644
--- a/src/gui/math3d/qvector2d.h
+++ b/src/gui/math3d/qvector2d.h
@@ -85,6 +85,7 @@ public:
QVector2D &operator*=(float factor);
QVector2D &operator*=(const QVector2D &vector);
QVector2D &operator/=(float divisor);
+ inline QVector2D &operator/=(const QVector2D &vector);
static float dotProduct(const QVector2D& v1, const QVector2D& v2); //In Qt 6 convert to inline and constexpr
@@ -97,6 +98,7 @@ public:
Q_DECL_CONSTEXPR friend inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2);
Q_DECL_CONSTEXPR friend inline const QVector2D operator-(const QVector2D &vector);
Q_DECL_CONSTEXPR friend inline const QVector2D operator/(const QVector2D &vector, float divisor);
+ Q_DECL_CONSTEXPR friend inline const QVector2D operator/(const QVector2D &vector, const QVector2D &divisor);
Q_DECL_CONSTEXPR friend inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2);
@@ -187,6 +189,13 @@ inline QVector2D &QVector2D::operator/=(float divisor)
return *this;
}
+inline QVector2D &QVector2D::operator/=(const QVector2D &vector)
+{
+ xp /= vector.xp;
+ yp /= vector.yp;
+ return *this;
+}
+
Q_DECL_CONSTEXPR inline bool operator==(const QVector2D &v1, const QVector2D &v2)
{
return v1.xp == v2.xp && v1.yp == v2.yp;
@@ -232,6 +241,11 @@ Q_DECL_CONSTEXPR inline const QVector2D operator/(const QVector2D &vector, float
return QVector2D(vector.xp / divisor, vector.yp / divisor);
}
+Q_DECL_CONSTEXPR inline const QVector2D operator/(const QVector2D &vector, const QVector2D &divisor)
+{
+ return QVector2D(vector.xp / divisor.xp, vector.yp / divisor.yp);
+}
+
Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2)
{
return qFuzzyCompare(v1.xp, v2.xp) && qFuzzyCompare(v1.yp, v2.yp);
diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp
index 014987b90d..e3744d497d 100644
--- a/src/gui/math3d/qvector3d.cpp
+++ b/src/gui/math3d/qvector3d.cpp
@@ -308,6 +308,16 @@ void QVector3D::normalize()
*/
/*!
+ \fn QVector3D &QVector3D::operator/=(const QVector3D &vector)
+ \since 5.5
+
+ Divides the components of this vector by the corresponding
+ components in \a vector.
+
+ \sa operator*=()
+*/
+
+/*!
Returns the dot product of \a v1 and \a v2.
*/
float QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)
@@ -578,6 +588,17 @@ float QVector3D::distanceToLine
*/
/*!
+ \fn const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor)
+ \relates QVector3D
+ \since 5.5
+
+ Returns the QVector3D object formed by dividing components of the given
+ \a vector by a respective components of the given \a divisor.
+
+ \sa QVector3D::operator/=()
+*/
+
+/*!
\fn bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)
\relates QVector3D
diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h
index 4c25451bab..e24b38444a 100644
--- a/src/gui/math3d/qvector3d.h
+++ b/src/gui/math3d/qvector3d.h
@@ -87,6 +87,7 @@ public:
QVector3D &operator*=(float factor);
QVector3D &operator*=(const QVector3D& vector);
QVector3D &operator/=(float divisor);
+ inline QVector3D &operator/=(const QVector3D &vector);
static float dotProduct(const QVector3D& v1, const QVector3D& v2); //In Qt 6 convert to inline and constexpr
static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2); //in Qt 6 convert to inline and constexpr
@@ -112,6 +113,7 @@ public:
Q_DECL_CONSTEXPR friend const QVector3D operator*(const QVector3D &v1, const QVector3D& v2);
Q_DECL_CONSTEXPR friend inline const QVector3D operator-(const QVector3D &vector);
Q_DECL_CONSTEXPR friend inline const QVector3D operator/(const QVector3D &vector, float divisor);
+ Q_DECL_CONSTEXPR friend inline const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor);
Q_DECL_CONSTEXPR friend inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2);
@@ -211,6 +213,14 @@ inline QVector3D &QVector3D::operator/=(float divisor)
return *this;
}
+inline QVector3D &QVector3D::operator/=(const QVector3D &vector)
+{
+ xp /= vector.xp;
+ yp /= vector.yp;
+ zp /= vector.zp;
+ return *this;
+}
+
Q_DECL_CONSTEXPR inline bool operator==(const QVector3D &v1, const QVector3D &v2)
{
return v1.xp == v2.xp && v1.yp == v2.yp && v1.zp == v2.zp;
@@ -256,6 +266,11 @@ Q_DECL_CONSTEXPR inline const QVector3D operator/(const QVector3D &vector, float
return QVector3D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor);
}
+Q_DECL_CONSTEXPR inline const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor)
+{
+ return QVector3D(vector.xp / divisor.xp, vector.yp / divisor.yp, vector.zp / divisor.zp);
+}
+
Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)
{
return qFuzzyCompare(v1.xp, v2.xp) &&
diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp
index 3603f655cb..b6d239e5ea 100644
--- a/src/gui/math3d/qvector4d.cpp
+++ b/src/gui/math3d/qvector4d.cpp
@@ -359,6 +359,16 @@ void QVector4D::normalize()
*/
/*!
+ \fn QVector4D &QVector4D::operator/=(const QVector4D &vector)
+ \since 5.5
+
+ Divides the components of this vector by the corresponding
+ components in \a vector.
+
+ \sa operator*=()
+*/
+
+/*!
Returns the dot product of \a v1 and \a v2.
*/
float QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
@@ -452,6 +462,17 @@ float QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
*/
/*!
+ \fn const QVector4D operator/(const QVector4D &vector, const QVector4D &divisor)
+ \relates QVector4D
+ \since 5.5
+
+ Returns the QVector4D object formed by dividing components of the given
+ \a vector by a respective components of the given \a divisor.
+
+ \sa QVector4D::operator/=()
+*/
+
+/*!
\fn bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2)
\relates QVector4D
diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h
index 291af5c072..1864b58d7c 100644
--- a/src/gui/math3d/qvector4d.h
+++ b/src/gui/math3d/qvector4d.h
@@ -88,6 +88,7 @@ public:
QVector4D &operator*=(float factor);
QVector4D &operator*=(const QVector4D &vector);
QVector4D &operator/=(float divisor);
+ inline QVector4D &operator/=(const QVector4D &vector);
static float dotProduct(const QVector4D& v1, const QVector4D& v2); //In Qt 6 convert to inline and constexpr
@@ -100,6 +101,7 @@ public:
Q_DECL_CONSTEXPR friend inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2);
Q_DECL_CONSTEXPR friend inline const QVector4D operator-(const QVector4D &vector);
Q_DECL_CONSTEXPR friend inline const QVector4D operator/(const QVector4D &vector, float divisor);
+ Q_DECL_CONSTEXPR friend inline const QVector4D operator/(const QVector4D &vector, const QVector4D &divisor);
Q_DECL_CONSTEXPR friend inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2);
@@ -210,6 +212,15 @@ inline QVector4D &QVector4D::operator/=(float divisor)
return *this;
}
+inline QVector4D &QVector4D::operator/=(const QVector4D &vector)
+{
+ xp /= vector.xp;
+ yp /= vector.yp;
+ zp /= vector.zp;
+ wp /= vector.wp;
+ return *this;
+}
+
Q_DECL_CONSTEXPR inline bool operator==(const QVector4D &v1, const QVector4D &v2)
{
return v1.xp == v2.xp && v1.yp == v2.yp && v1.zp == v2.zp && v1.wp == v2.wp;
@@ -255,6 +266,11 @@ Q_DECL_CONSTEXPR inline const QVector4D operator/(const QVector4D &vector, float
return QVector4D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, vector.wp / divisor);
}
+Q_DECL_CONSTEXPR inline const QVector4D operator/(const QVector4D &vector, const QVector4D &divisor)
+{
+ return QVector4D(vector.xp / divisor.xp, vector.yp / divisor.yp, vector.zp / divisor.zp, vector.wp / divisor.wp);
+}
+
Q_DECL_CONSTEXPR inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2)
{
return qFuzzyCompare(v1.xp, v2.xp) &&
diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
index fa5d1b576f..2b3fbff000 100644
--- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
+++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
@@ -114,6 +114,13 @@ private slots:
void divide4_data();
void divide4();
+ void divideFactor2_data();
+ void divideFactor2();
+ void divideFactor3_data();
+ void divideFactor3();
+ void divideFactor4_data();
+ void divideFactor4();
+
void negate2_data();
void negate2();
void negate3_data();
@@ -1629,16 +1636,154 @@ void tst_QVectorND::multiplyFactor4()
QCOMPARE(v3.w(), v1.w() * factor);
}
-// Test vector division by a factor for 2D vectors.
+// Test component-wise vector division for 2D vectors.
void tst_QVectorND::divide2_data()
{
// Use the same test data as the multiply test.
- multiplyFactor2_data();
+ multiply2_data();
}
void tst_QVectorND::divide2()
{
QFETCH(float, x1);
QFETCH(float, y1);
+ QFETCH(float, x2);
+ QFETCH(float, y2);
+ QFETCH(float, x3);
+ QFETCH(float, y3);
+
+ QVector2D v1(x1, y1);
+ QVector2D v2(x2, y2);
+ QVector2D v3(x3, y3);
+
+ if (v2.x() != 0.0f && v2.y() != 0.0f) {
+ QVERIFY((v3 / v2) == v1);
+
+ QVector2D v4(v3);
+ v4 /= v2;
+ QVERIFY(v4 == v1);
+
+ QCOMPARE(v4.x(), v3.x() / v2.x());
+ QCOMPARE(v4.y(), v3.y() / v2.y());
+ }
+ if (v1.x() != 0.0f && v1.y() != 0.0f) {
+ QVERIFY((v3 / v1) == v2);
+
+ QVector2D v4(v3);
+ v4 /= v1;
+ QVERIFY(v4 == v2);
+
+ QCOMPARE(v4.x(), v3.x() / v1.x());
+ QCOMPARE(v4.y(), v3.y() / v1.y());
+ }
+}
+
+// Test component-wise vector division for 3D vectors.
+void tst_QVectorND::divide3_data()
+{
+ // Use the same test data as the multiply test.
+ multiply3_data();
+}
+void tst_QVectorND::divide3()
+{
+ QFETCH(float, x1);
+ QFETCH(float, y1);
+ QFETCH(float, z1);
+ QFETCH(float, x2);
+ QFETCH(float, y2);
+ QFETCH(float, z2);
+ QFETCH(float, x3);
+ QFETCH(float, y3);
+ QFETCH(float, z3);
+
+ QVector3D v1(x1, y1, z1);
+ QVector3D v2(x2, y2, z2);
+ QVector3D v3(x3, y3, z3);
+
+ if (v2.x() != 0.0f && v2.y() != 0.0f && v2.z() != 0.0f) {
+ QVERIFY((v3 / v2) == v1);
+
+ QVector3D v4(v3);
+ v4 /= v2;
+ QVERIFY(v4 == v1);
+
+ QCOMPARE(v4.x(), v3.x() / v2.x());
+ QCOMPARE(v4.y(), v3.y() / v2.y());
+ QCOMPARE(v4.z(), v3.z() / v2.z());
+ }
+ if (v1.x() != 0.0f && v1.y() != 0.0f && v1.z() != 0.0f) {
+ QVERIFY((v3 / v1) == v2);
+
+ QVector3D v4(v3);
+ v4 /= v1;
+ QVERIFY(v4 == v2);
+
+ QCOMPARE(v4.x(), v3.x() / v1.x());
+ QCOMPARE(v4.y(), v3.y() / v1.y());
+ QCOMPARE(v4.z(), v3.z() / v1.z());
+ }
+}
+
+// Test component-wise vector division for 4D vectors.
+void tst_QVectorND::divide4_data()
+{
+ // Use the same test data as the multiply test.
+ multiply4_data();
+}
+void tst_QVectorND::divide4()
+{
+ QFETCH(float, x1);
+ QFETCH(float, y1);
+ QFETCH(float, z1);
+ QFETCH(float, w1);
+ QFETCH(float, x2);
+ QFETCH(float, y2);
+ QFETCH(float, z2);
+ QFETCH(float, w2);
+ QFETCH(float, x3);
+ QFETCH(float, y3);
+ QFETCH(float, z3);
+ QFETCH(float, w3);
+
+ QVector4D v1(x1, y1, z1, w1);
+ QVector4D v2(x2, y2, z2, w2);
+ QVector4D v3(x3, y3, z3, w3);
+
+ if (v2.x() != 0.0f && v2.y() != 0.0f && v2.z() != 0.0f && v2.w() != 0.0f) {
+ QVERIFY((v3 / v2) == v1);
+
+ QVector4D v4(v3);
+ v4 /= v2;
+ QVERIFY(v4 == v1);
+
+ QCOMPARE(v4.x(), v3.x() / v2.x());
+ QCOMPARE(v4.y(), v3.y() / v2.y());
+ QCOMPARE(v4.z(), v3.z() / v2.z());
+ QCOMPARE(v4.w(), v3.w() / v2.w());
+ }
+ if (v1.x() != 0.0f && v1.y() != 0.0f && v1.z() != 0.0f && v1.w() != 0.0f) {
+ QVERIFY((v3 / v1) == v2);
+
+ QVector4D v4(v3);
+ v4 /= v1;
+ QVERIFY(v4 == v2);
+
+ QCOMPARE(v4.x(), v3.x() / v1.x());
+ QCOMPARE(v4.y(), v3.y() / v1.y());
+ QCOMPARE(v4.z(), v3.z() / v1.z());
+ QCOMPARE(v4.w(), v3.w() / v1.w());
+ }
+}
+
+// Test vector division by a factor for 2D vectors.
+void tst_QVectorND::divideFactor2_data()
+{
+ // Use the same test data as the multiplyFactor test.
+ multiplyFactor2_data();
+}
+void tst_QVectorND::divideFactor2()
+{
+ QFETCH(float, x1);
+ QFETCH(float, y1);
QFETCH(float, factor);
QFETCH(float, x2);
QFETCH(float, y2);
@@ -1660,12 +1805,12 @@ void tst_QVectorND::divide2()
}
// Test vector division by a factor for 3D vectors.
-void tst_QVectorND::divide3_data()
+void tst_QVectorND::divideFactor3_data()
{
- // Use the same test data as the multiply test.
+ // Use the same test data as the multiplyFactor test.
multiplyFactor3_data();
}
-void tst_QVectorND::divide3()
+void tst_QVectorND::divideFactor3()
{
QFETCH(float, x1);
QFETCH(float, y1);
@@ -1693,12 +1838,12 @@ void tst_QVectorND::divide3()
}
// Test vector division by a factor for 4D vectors.
-void tst_QVectorND::divide4_data()
+void tst_QVectorND::divideFactor4_data()
{
- // Use the same test data as the multiply test.
+ // Use the same test data as the multiplyFactor test.
multiplyFactor4_data();
}
-void tst_QVectorND::divide4()
+void tst_QVectorND::divideFactor4()
{
QFETCH(float, x1);
QFETCH(float, y1);