Skip to content

Commit 9c01b63

Browse files
committed
QVectorND: fix qFuzzyCompare() precondition violation
qFuzzyCompare() requires that neither argument is numerically zero. This cannot be guaranteed for the vector elements. Fix by using the new QtPrivate::fuzzyCompare() function, which does things in the correct way. As a drive-by, put the operators at the beginning of continued lines, as requested by https://wiki.qt.io/Qt_Coding_Style#Line_breaks Item 2. Amends the start of the public history. Pick-to: 6.10 6.8 6.5 Task-number: QTBUG-142020 Change-Id: I55cfb520bda53e12532923005bb1ee6396b124f2 Reviewed-by: Ivan Solovev <[email protected]>
1 parent 7b09f45 commit 9c01b63

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/gui/math3d/qvectornd.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ QT_BEGIN_NAMESPACE
375375
*/
376376
bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept
377377
{
378-
return qFuzzyCompare(v1.v[0], v2.v[0]) && qFuzzyCompare(v1.v[1], v2.v[1]);
378+
return QtPrivate::fuzzyCompare(v1.v[0], v2.v[0])
379+
&& QtPrivate::fuzzyCompare(v1.v[1], v2.v[1]);
379380
}
380381

381382
#ifndef QT_NO_VECTOR3D
@@ -979,9 +980,9 @@ QVector3D QVector3D::unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &pr
979980
*/
980981
bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept
981982
{
982-
return qFuzzyCompare(v1.v[0], v2.v[0]) &&
983-
qFuzzyCompare(v1.v[1], v2.v[1]) &&
984-
qFuzzyCompare(v1.v[2], v2.v[2]);
983+
return QtPrivate::fuzzyCompare(v1.v[0], v2.v[0])
984+
&& QtPrivate::fuzzyCompare(v1.v[1], v2.v[1])
985+
&& QtPrivate::fuzzyCompare(v1.v[2], v2.v[2]);
985986
}
986987

987988
#ifndef QT_NO_VECTOR2D
@@ -1501,10 +1502,10 @@ QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
15011502
*/
15021503
bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept
15031504
{
1504-
return qFuzzyCompare(v1.v[0], v2.v[0]) &&
1505-
qFuzzyCompare(v1.v[1], v2.v[1]) &&
1506-
qFuzzyCompare(v1.v[2], v2.v[2]) &&
1507-
qFuzzyCompare(v1.v[3], v2.v[3]);
1505+
return QtPrivate::fuzzyCompare(v1.v[0], v2.v[0])
1506+
&& QtPrivate::fuzzyCompare(v1.v[1], v2.v[1])
1507+
&& QtPrivate::fuzzyCompare(v1.v[2], v2.v[2])
1508+
&& QtPrivate::fuzzyCompare(v1.v[3], v2.v[3]);
15081509
}
15091510

15101511
#ifndef QT_NO_VECTOR2D

0 commit comments

Comments
 (0)