[QVectorND] Add missing operator/=(const QVectorND &)

Change-Id: Ic1d2912808b95e02ba5d9cb2972c81c6374bbca9
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
Konstantin Ritt 2015-01-26 10:21:56 +04:00 committed by Sean Harmer
parent 6462744b6b
commit a14559bc78
7 changed files with 261 additions and 8 deletions

View File

@ -315,6 +315,16 @@ float QVector2D::distanceToLine
\sa operator*=()
*/
/*!
\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.
*/
@ -406,6 +416,17 @@ float QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
\sa QVector2D::operator/=()
*/
/*!
\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

View File

@ -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);

View File

@ -307,6 +307,16 @@ void QVector3D::normalize()
\sa operator*=()
*/
/*!
\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.
*/
@ -577,6 +587,17 @@ float QVector3D::distanceToLine
\sa QVector3D::operator/=()
*/
/*!
\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

View File

@ -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) &&

View File

@ -358,6 +358,16 @@ void QVector4D::normalize()
\sa operator*=()
*/
/*!
\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.
*/
@ -451,6 +461,17 @@ float QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
\sa QVector4D::operator/=()
*/
/*!
\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

View File

@ -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) &&

View File

@ -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,13 +1636,151 @@ 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);
@ -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);