summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/math3d.pri15
-rw-r--r--src/gui/math3d/qgenericmatrix.cpp52
-rw-r--r--src/gui/math3d/qgenericmatrix.h62
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp194
-rw-r--r--src/gui/math3d/qmatrix4x4.h322
-rw-r--r--src/gui/math3d/qquaternion.cpp255
-rw-r--r--src/gui/math3d/qquaternion.h259
-rw-r--r--src/gui/math3d/qvector2d.cpp560
-rw-r--r--src/gui/math3d/qvector2d.h292
-rw-r--r--src/gui/math3d/qvector3d.cpp761
-rw-r--r--src/gui/math3d/qvector3d.h319
-rw-r--r--src/gui/math3d/qvector4d.cpp641
-rw-r--r--src/gui/math3d/qvector4d.h320
-rw-r--r--src/gui/math3d/qvectornd.cpp1642
-rw-r--r--src/gui/math3d/qvectornd.h1086
15 files changed, 3239 insertions, 3541 deletions
diff --git a/src/gui/math3d/math3d.pri b/src/gui/math3d/math3d.pri
deleted file mode 100644
index e4dd53a68e..0000000000
--- a/src/gui/math3d/math3d.pri
+++ /dev/null
@@ -1,15 +0,0 @@
-HEADERS += \
- math3d/qgenericmatrix.h \
- math3d/qmatrix4x4.h \
- math3d/qquaternion.h \
- math3d/qvector2d.h \
- math3d/qvector3d.h \
- math3d/qvector4d.h
-
-SOURCES += \
- math3d/qgenericmatrix.cpp \
- math3d/qmatrix4x4.cpp \
- math3d/qquaternion.cpp \
- math3d/qvector2d.cpp \
- math3d/qvector3d.cpp \
- math3d/qvector4d.cpp
diff --git a/src/gui/math3d/qgenericmatrix.cpp b/src/gui/math3d/qgenericmatrix.cpp
index b144d132d0..7ffb53a88b 100644
--- a/src/gui/math3d/qgenericmatrix.cpp
+++ b/src/gui/math3d/qgenericmatrix.cpp
@@ -1,46 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qgenericmatrix.h"
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN(QMatrix2x2)
+QT_IMPL_METATYPE_EXTERN(QMatrix2x3)
+QT_IMPL_METATYPE_EXTERN(QMatrix2x4)
+QT_IMPL_METATYPE_EXTERN(QMatrix3x2)
+QT_IMPL_METATYPE_EXTERN(QMatrix3x3)
+QT_IMPL_METATYPE_EXTERN(QMatrix3x4)
+QT_IMPL_METATYPE_EXTERN(QMatrix4x2)
+QT_IMPL_METATYPE_EXTERN(QMatrix4x3)
+
/*!
\class QGenericMatrix
\brief The QGenericMatrix class is a template class that represents a NxM transformation matrix with N columns and M rows.
@@ -177,8 +150,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn template<int NN, int M1, int M2, typename TT> QGenericMatrix<M1, M2, TT> operator*(const QGenericMatrix<NN, M2, TT>& m1, const QGenericMatrix<M1, NN, TT>& m2)
- \relates QGenericMatrix
+ \fn template <int N, int M, typename T> template<int NN, int M1, int M2, typename TT> QGenericMatrix<M1, M2, TT> QGenericMatrix<N, M, T>::operator*(const QGenericMatrix<NN, M2, TT>& m1, const QGenericMatrix<M1, NN, TT>& m2)
Returns the product of the NNxM2 matrix \a m1 and the M1xNN matrix \a m2
to produce a M1xM2 matrix result.
diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h
index 1381014a04..1e20df5a6b 100644
--- a/src/gui/math3d/qgenericmatrix.h
+++ b/src/gui/math3d/qgenericmatrix.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGENERICMATRIX_H
#define QGENERICMATRIX_H
@@ -64,7 +28,7 @@ public:
void fill(T value);
- Q_REQUIRED_RESULT QGenericMatrix<M, N, T> transposed() const;
+ [[nodiscard]] QGenericMatrix<M, N, T> transposed() const;
QGenericMatrix<N, M, T>& operator+=(const QGenericMatrix<N, M, T>& other);
QGenericMatrix<N, M, T>& operator-=(const QGenericMatrix<N, M, T>& other);
@@ -79,7 +43,6 @@ public:
const T *data() const { return *m; }
const T *constData() const { return *m; }
-#if !defined(Q_NO_TEMPLATE_FRIENDS)
template<int NN, int MM, typename TT>
friend QGenericMatrix<NN, MM, TT> operator+(const QGenericMatrix<NN, MM, TT>& m1, const QGenericMatrix<NN, MM, TT>& m2);
template<int NN, int MM, typename TT>
@@ -96,13 +59,10 @@ public:
friend QGenericMatrix<NN, MM, TT> operator/(const QGenericMatrix<NN, MM, TT>& matrix, TT divisor);
private:
-#endif
T m[N][M]; // Column-major order to match OpenGL.
-#if !defined(Q_NO_TEMPLATE_FRIENDS)
template <int NN, int MM, typename TT>
friend class QGenericMatrix;
-#endif
};
template <int N, int M, typename T>
class QTypeInfo<QGenericMatrix<N, M, T> >
@@ -385,13 +345,13 @@ QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix)
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QMatrix2x2)
-Q_DECLARE_METATYPE(QMatrix2x3)
-Q_DECLARE_METATYPE(QMatrix2x4)
-Q_DECLARE_METATYPE(QMatrix3x2)
-Q_DECLARE_METATYPE(QMatrix3x3)
-Q_DECLARE_METATYPE(QMatrix3x4)
-Q_DECLARE_METATYPE(QMatrix4x2)
-Q_DECLARE_METATYPE(QMatrix4x3)
+QT_DECL_METATYPE_EXTERN(QMatrix2x2, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix2x3, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix2x4, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix3x2, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix3x3, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix3x4, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix4x2, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN(QMatrix4x3, Q_GUI_EXPORT)
#endif
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index 5c1cdcc9fc..d04a502519 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmatrix4x4.h"
#include <QtCore/qmath.h>
@@ -136,7 +100,7 @@ QMatrix4x4::QMatrix4x4(const float *values)
*/
/*!
- \fn QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const
+ \fn template <int N, int M> QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const
Constructs a NxM generic matrix from the left-most N columns and
top-most M rows of this 4x4 matrix. If N or M is greater than 4,
@@ -389,7 +353,7 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
*invertible = true;
return orthonormalInverse();
} else if (flagBits < Perspective) {
- QMatrix4x4 inv(1); // The "1" says to not load the identity.
+ QMatrix4x4 inv(Qt::Uninitialized);
double mm[4][4];
copyToDoubles(m, mm);
@@ -425,7 +389,7 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
return inv;
}
- QMatrix4x4 inv(1); // The "1" says to not load the identity.
+ QMatrix4x4 inv(Qt::Uninitialized);
double mm[4][4];
copyToDoubles(m, mm);
@@ -527,7 +491,7 @@ QMatrix3x3 QMatrix4x4::normalMatrix() const
*/
QMatrix4x4 QMatrix4x4::transposed() const
{
- QMatrix4x4 result(1); // The "1" says to not load the identity.
+ QMatrix4x4 result(Qt::Uninitialized);
for (int row = 0; row < 4; ++row) {
for (int col = 0; col < 4; ++col) {
result.m[col][row] = m[row][col];
@@ -627,24 +591,33 @@ QMatrix4x4& QMatrix4x4::operator/=(float divisor)
#ifndef QT_NO_VECTOR3D
+#if QT_DEPRECATED_SINCE(6, 1)
+
/*!
\fn QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
\relates QMatrix4x4
+ \deprecated [6.1] Convert the QVector3D to a QVector4D with 1.0 as the w coordinate, then multiply.
+
Returns the result of transforming \a vector according to \a matrix,
- with the matrix applied post-vector.
+ with the matrix applied post-vector. The vector is transformed as a point.
*/
/*!
\fn QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
\relates QMatrix4x4
+ \deprecated [6.1] Use QMatrix4x4::map() instead.
+
Returns the result of transforming \a vector according to \a matrix,
- with the matrix applied pre-vector.
+ with the matrix applied pre-vector. The vector is transformed as a
+ projective point.
*/
#endif
+#endif
+
#ifndef QT_NO_VECTOR4D
/*!
@@ -681,10 +654,14 @@ QMatrix4x4& QMatrix4x4::operator/=(float divisor)
with the matrix applied post-point.
*/
+#if QT_DEPRECATED_SINCE(6, 1)
+
/*!
\fn QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
\relates QMatrix4x4
+ \deprecated [6.1] Use QMatrix4x4::map() instead.
+
Returns the result of transforming \a point according to \a matrix,
with the matrix applied pre-point.
*/
@@ -693,10 +670,14 @@ QMatrix4x4& QMatrix4x4::operator/=(float divisor)
\fn QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
\relates QMatrix4x4
+ \deprecated [6.1] Use QMatrix4x4::map() instead.
+
Returns the result of transforming \a point according to \a matrix,
with the matrix applied pre-point.
*/
+#endif
+
/*!
\fn QMatrix4x4 operator-(const QMatrix4x4& matrix)
\overload
@@ -726,7 +707,7 @@ QMatrix4x4& QMatrix4x4::operator/=(float divisor)
*/
QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor)
{
- QMatrix4x4 m(1); // The "1" says to not load the identity.
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = matrix.m[0][0] / divisor;
m.m[0][1] = matrix.m[0][1] / divisor;
m.m[0][2] = matrix.m[0][2] / divisor;
@@ -754,6 +735,26 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor)
Returns \c true if \a m1 and \a m2 are equal, allowing for a small
fuzziness factor for floating-point comparisons; false otherwise.
*/
+bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2)
+{
+ return qFuzzyCompare(m1.m[0][0], m2.m[0][0]) &&
+ qFuzzyCompare(m1.m[0][1], m2.m[0][1]) &&
+ qFuzzyCompare(m1.m[0][2], m2.m[0][2]) &&
+ qFuzzyCompare(m1.m[0][3], m2.m[0][3]) &&
+ qFuzzyCompare(m1.m[1][0], m2.m[1][0]) &&
+ qFuzzyCompare(m1.m[1][1], m2.m[1][1]) &&
+ qFuzzyCompare(m1.m[1][2], m2.m[1][2]) &&
+ qFuzzyCompare(m1.m[1][3], m2.m[1][3]) &&
+ qFuzzyCompare(m1.m[2][0], m2.m[2][0]) &&
+ qFuzzyCompare(m1.m[2][1], m2.m[2][1]) &&
+ qFuzzyCompare(m1.m[2][2], m2.m[2][2]) &&
+ qFuzzyCompare(m1.m[2][3], m2.m[2][3]) &&
+ qFuzzyCompare(m1.m[3][0], m2.m[3][0]) &&
+ qFuzzyCompare(m1.m[3][1], m2.m[3][1]) &&
+ qFuzzyCompare(m1.m[3][2], m2.m[3][2]) &&
+ qFuzzyCompare(m1.m[3][3], m2.m[3][3]);
+}
+
#ifndef QT_NO_VECTOR3D
@@ -1139,7 +1140,7 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z)
z = float(double(z) / len);
}
float ic = 1.0f - c;
- QMatrix4x4 rot(1); // The "1" says to not load the identity.
+ QMatrix4x4 rot(Qt::Uninitialized);
rot.m[0][0] = x * x * ic + c;
rot.m[1][0] = x * y * ic - z * s;
rot.m[2][0] = x * z * ic + y * s;
@@ -1163,12 +1164,15 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z)
/*!
\internal
*/
-void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
+void QMatrix4x4::projectedRotate(float angle, float x, float y, float z, float distanceToPlane)
{
// Used by QGraphicsRotation::applyTo() to perform a rotation
// and projection back to 2D in a single step.
+ if (qIsNull(distanceToPlane))
+ return rotate(angle, x, y, z);
if (angle == 0.0f)
return;
+
float c, s;
if (angle == 90.0f || angle == -270.0f) {
s = 1.0f;
@@ -1184,6 +1188,8 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
c = std::cos(a);
s = std::sin(a);
}
+
+ const qreal d = 1.0 / distanceToPlane;
if (x == 0.0f) {
if (y == 0.0f) {
if (z != 0.0f) {
@@ -1207,10 +1213,11 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
// Rotate around the Y axis.
if (y < 0)
s = -s;
- m[0][0] = m[0][0] * c + m[3][0] * s * inv_dist_to_plane;
- m[0][1] = m[0][1] * c + m[3][1] * s * inv_dist_to_plane;
- m[0][2] = m[0][2] * c + m[3][2] * s * inv_dist_to_plane;
- m[0][3] = m[0][3] * c + m[3][3] * s * inv_dist_to_plane;
+ s *= d;
+ m[0][0] = m[0][0] * c + m[3][0] * s;
+ m[0][1] = m[0][1] * c + m[3][1] * s;
+ m[0][2] = m[0][2] * c + m[3][2] * s;
+ m[0][3] = m[0][3] * c + m[3][3] * s;
flagBits = General;
return;
}
@@ -1218,10 +1225,11 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
// Rotate around the X axis.
if (x < 0)
s = -s;
- m[1][0] = m[1][0] * c - m[3][0] * s * inv_dist_to_plane;
- m[1][1] = m[1][1] * c - m[3][1] * s * inv_dist_to_plane;
- m[1][2] = m[1][2] * c - m[3][2] * s * inv_dist_to_plane;
- m[1][3] = m[1][3] * c - m[3][3] * s * inv_dist_to_plane;
+ s *= d;
+ m[1][0] = m[1][0] * c - m[3][0] * s;
+ m[1][1] = m[1][1] * c - m[3][1] * s;
+ m[1][2] = m[1][2] * c - m[3][2] * s;
+ m[1][3] = m[1][3] * c - m[3][3] * s;
flagBits = General;
return;
}
@@ -1234,8 +1242,8 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
y = float(double(y) / len);
z = float(double(z) / len);
}
- float ic = 1.0f - c;
- QMatrix4x4 rot(1); // The "1" says to not load the identity.
+ const float ic = 1.0f - c;
+ QMatrix4x4 rot(Qt::Uninitialized);
rot.m[0][0] = x * x * ic + c;
rot.m[1][0] = x * y * ic - z * s;
rot.m[2][0] = 0.0f;
@@ -1248,14 +1256,24 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
rot.m[1][2] = 0.0f;
rot.m[2][2] = 1.0f;
rot.m[3][2] = 0.0f;
- rot.m[0][3] = (x * z * ic - y * s) * -inv_dist_to_plane;
- rot.m[1][3] = (y * z * ic + x * s) * -inv_dist_to_plane;
+ rot.m[0][3] = (x * z * ic - y * s) * -d;
+ rot.m[1][3] = (y * z * ic + x * s) * -d;
rot.m[2][3] = 0.0f;
rot.m[3][3] = 1.0f;
rot.flagBits = General;
*this *= rot;
}
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+/*!
+ \internal
+*/
+void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
+{
+ projectedRotate(angle, x, y, z, 1024.0);
+}
+#endif
+
/*!
\fn int QMatrix4x4::flags() const
\internal
@@ -1371,10 +1389,10 @@ void QMatrix4x4::ortho(float left, float right, float bottom, float top, float n
return;
// Construct the projection.
- float width = right - left;
- float invheight = top - bottom;
- float clip = farPlane - nearPlane;
- QMatrix4x4 m(1);
+ const float width = right - left;
+ const float invheight = top - bottom;
+ const float clip = farPlane - nearPlane;
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = 2.0f / width;
m.m[1][0] = 0.0f;
m.m[2][0] = 0.0f;
@@ -1412,10 +1430,10 @@ void QMatrix4x4::frustum(float left, float right, float bottom, float top, float
return;
// Construct the projection.
- QMatrix4x4 m(1);
- float width = right - left;
- float invheight = top - bottom;
- float clip = farPlane - nearPlane;
+ QMatrix4x4 m(Qt::Uninitialized);
+ const float width = right - left;
+ const float invheight = top - bottom;
+ const float clip = farPlane - nearPlane;
m.m[0][0] = 2.0f * nearPlane / width;
m.m[1][0] = 0.0f;
m.m[2][0] = (left + right) / width;
@@ -1455,9 +1473,9 @@ void QMatrix4x4::perspective(float verticalAngle, float aspectRatio, float nearP
return;
// Construct the projection.
- QMatrix4x4 m(1);
- float radians = qDegreesToRadians(verticalAngle / 2.0f);
- float sine = std::sin(radians);
+ QMatrix4x4 m(Qt::Uninitialized);
+ const float radians = qDegreesToRadians(verticalAngle / 2.0f);
+ const float sine = std::sin(radians);
if (sine == 0.0f)
return;
float cotan = std::cos(radians) / sine;
@@ -1505,7 +1523,7 @@ void QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVe
QVector3D side = QVector3D::crossProduct(forward, up).normalized();
QVector3D upVector = QVector3D::crossProduct(side, forward);
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = side.x();
m.m[1][0] = side.y();
m.m[2][0] = side.z();
@@ -1554,7 +1572,7 @@ void QMatrix4x4::viewport(float left, float bottom, float width, float height, f
const float w2 = width / 2.0f;
const float h2 = height / 2.0f;
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = w2;
m.m[1][0] = 0.0f;
m.m[2][0] = 0.0f;
@@ -1580,7 +1598,7 @@ void QMatrix4x4::viewport(float left, float bottom, float width, float height, f
\deprecated
Flips between right-handed and left-handed coordinate systems
- by multiplying the y and z co-ordinates by -1. This is normally
+ by multiplying the y and z coordinates by -1. This is normally
used to create a left-handed orthographic view without scaling
the viewport as ortho() does.
@@ -1625,7 +1643,7 @@ void QMatrix4x4::copyDataTo(float *values) const
The returned QTransform is formed by simply dropping the
third row and third column of the QMatrix4x4. This is suitable
- for implementing orthographic projections where the z co-ordinate
+ for implementing orthographic projections where the z coordinate
should be dropped rather than projected.
*/
QTransform QMatrix4x4::toTransform() const
@@ -1640,14 +1658,14 @@ QTransform QMatrix4x4::toTransform() const
corresponds to this matrix.
If \a distanceToPlane is non-zero, it indicates a projection
- factor to use to adjust for the z co-ordinate. The value of
+ factor to use to adjust for the z coordinate. The value of
1024 corresponds to the projection factor used
by QTransform::rotate() for the x and y axes.
If \a distanceToPlane is zero, then the returned QTransform
is formed by simply dropping the third row and third column
of the QMatrix4x4. This is suitable for implementing
- orthographic projections where the z co-ordinate should
+ orthographic projections where the z coordinate should
be dropped rather than projected.
*/
QTransform QMatrix4x4::toTransform(float distanceToPlane) const
@@ -1681,6 +1699,7 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
\fn QPoint QMatrix4x4::map(const QPoint& point) const
Maps \a point by multiplying this matrix by \a point.
+ The matrix is applied pre-point.
\sa mapRect()
*/
@@ -1688,7 +1707,8 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
/*!
\fn QPointF QMatrix4x4::map(const QPointF& point) const
- Maps \a point by multiplying this matrix by \a point.
+ Maps \a point by post-multiplying this matrix by \a point.
+ The matrix is applied pre-point.
\sa mapRect()
*/
@@ -1698,7 +1718,12 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
/*!
\fn QVector3D QMatrix4x4::map(const QVector3D& point) const
- Maps \a point by multiplying this matrix by \a point.
+ Maps \a point by multiplying this matrix by \a point extended to a 4D
+ vector by assuming 1.0 for the w coordinate. The matrix is applied
+ pre-point.
+
+ \note This function is not the same as mapVector(). For points, always use
+ map(). mapVector() is suitable for vectors (directions) only.
\sa mapRect(), mapVector()
*/
@@ -1708,7 +1733,7 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
Maps \a vector by multiplying the top 3x3 portion of this matrix
by \a vector. The translation and projection components of
- this matrix are ignored.
+ this matrix are ignored. The matrix is applied pre-vector.
\sa map()
*/
@@ -1721,6 +1746,7 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
\fn QVector4D QMatrix4x4::map(const QVector4D& point) const;
Maps \a point by multiplying this matrix by \a point.
+ The matrix is applied pre-point.
\sa mapRect()
*/
@@ -1844,7 +1870,7 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
// of just rotations and translations.
QMatrix4x4 QMatrix4x4::orthonormalInverse() const
{
- QMatrix4x4 result(1); // The '1' says not to load identity
+ QMatrix4x4 result(Qt::Uninitialized);
result.m[0][0] = m[0][0];
result.m[1][0] = m[0][1];
@@ -1882,15 +1908,15 @@ QMatrix4x4 QMatrix4x4::orthonormalInverse() const
Normally the QMatrix4x4 class keeps track of this special type internally
as operations are performed. However, if the matrix is modified
- directly with {QLoggingCategory::operator()}{operator()()} or data(), then QMatrix4x4 will lose track of
- the special type and will revert to the safest but least efficient
- operations thereafter.
+ directly with operator()(int, int) or data(), then QMatrix4x4 will
+ lose track of the special type and will revert to the safest but least
+ efficient operations thereafter.
By calling optimize() after directly modifying the matrix,
the programmer can force QMatrix4x4 to recover the special type if
the elements appear to conform to one of the known optimized types.
- \sa {QLoggingCategory::operator()}{operator()()}, data(), translate()
+ \sa operator()(int, int), data(), translate()
*/
void QMatrix4x4::optimize()
{
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 5664de6729..f8e5bc4314 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMATRIX4X4_H
#define QMATRIX4X4_H
@@ -47,6 +11,8 @@
#include <QtGui/qgenericmatrix.h>
#include <QtCore/qrect.h>
+class tst_QMatrixNxN;
+
QT_BEGIN_NAMESPACE
@@ -107,9 +73,11 @@ public:
friend QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2);
friend QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2);
#ifndef QT_NO_VECTOR3D
+#if QT_DEPRECATED_SINCE(6, 1)
friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
#endif
+#endif
#ifndef QT_NO_VECTOR4D
friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
@@ -117,13 +85,15 @@ public:
friend QPoint operator*(const QPoint& point, const QMatrix4x4& matrix);
friend QPointF operator*(const QPointF& point, const QMatrix4x4& matrix);
friend QMatrix4x4 operator-(const QMatrix4x4& matrix);
+#if QT_DEPRECATED_SINCE(6, 1)
friend QPoint operator*(const QMatrix4x4& matrix, const QPoint& point);
friend QPointF operator*(const QMatrix4x4& matrix, const QPointF& point);
+#endif
friend QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix);
friend QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor);
friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
- friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
+ friend Q_GUI_EXPORT bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
#ifndef QT_NO_VECTOR3D
void scale(const QVector3D& vector);
@@ -157,14 +127,14 @@ public:
QTransform toTransform() const;
QTransform toTransform(float distanceToPlane) const;
- QPoint map(const QPoint& point) const;
- QPointF map(const QPointF& point) const;
+ inline QPoint map(const QPoint& point) const;
+ inline QPointF map(const QPointF& point) const;
#ifndef QT_NO_VECTOR3D
- QVector3D map(const QVector3D& point) const;
- QVector3D mapVector(const QVector3D& vector) const;
+ inline QVector3D map(const QVector3D& point) const;
+ inline QVector3D mapVector(const QVector3D& vector) const;
#endif
#ifndef QT_NO_VECTOR4D
- QVector4D map(const QVector4D& point) const;
+ inline QVector4D map(const QVector4D& point) const;
#endif
QRect mapRect(const QRect& rect) const;
QRectF mapRect(const QRectF& rect) const;
@@ -184,7 +154,13 @@ public:
friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
#endif
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ void projectedRotate(float angle, float x, float y, float z, float distanceToPlane);
+ // ### Qt7: Remove
void projectedRotate(float angle, float x, float y, float z);
+#else
+ void projectedRotate(float angle, float x, float y, float z, float distanceToPlane = 1024.0);
+#endif
// When matrices are multiplied, the flag bits are or-ed together.
// Note that the ordering of the bit values matters. (ident < t < s < r2d < r < p)
@@ -205,10 +181,9 @@ private:
float m[4][4]; // Column-major order to match OpenGL.
Flags flagBits;
- // Construct without initializing identity matrix.
- explicit QMatrix4x4(int) { }
-
QMatrix4x4 orthonormalInverse() const;
+
+ friend class ::tst_QMatrixNxN; // for access to flagBits
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QMatrix4x4::Flags)
@@ -216,7 +191,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QMatrix4x4::Flags)
QT_WARNING_PUSH
QT_WARNING_DISABLE_FLOAT_COMPARE
-Q_DECLARE_TYPEINFO(QMatrix4x4, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QMatrix4x4, Q_PRIMITIVE_TYPE);
inline QMatrix4x4::QMatrix4x4
(float m11, float m12, float m13, float m14,
@@ -429,7 +404,7 @@ inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& o)
const QMatrix4x4 other = o; // prevent aliasing when &o == this ### Qt 6: take o by value
flagBits |= other.flagBits;
- if (flagBits < Rotation2D) {
+ if (flagBits.toInt() < Rotation2D) {
m[3][0] += m[0][0] * other.m[3][0];
m[3][1] += m[1][1] * other.m[3][1];
m[3][2] += m[2][2] * other.m[3][2];
@@ -587,7 +562,7 @@ inline bool QMatrix4x4::operator!=(const QMatrix4x4& other) const
inline QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = m1.m[0][0] + m2.m[0][0];
m.m[0][1] = m1.m[0][1] + m2.m[0][1];
m.m[0][2] = m1.m[0][2] + m2.m[0][2];
@@ -604,13 +579,12 @@ inline QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
m.m[3][1] = m1.m[3][1] + m2.m[3][1];
m.m[3][2] = m1.m[3][2] + m2.m[3][2];
m.m[3][3] = m1.m[3][3] + m2.m[3][3];
- m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = m1.m[0][0] - m2.m[0][0];
m.m[0][1] = m1.m[0][1] - m2.m[0][1];
m.m[0][2] = m1.m[0][2] - m2.m[0][2];
@@ -627,14 +601,13 @@ inline QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
m.m[3][1] = m1.m[3][1] - m2.m[3][1];
m.m[3][2] = m1.m[3][2] - m2.m[3][2];
m.m[3][3] = m1.m[3][3] - m2.m[3][3];
- m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
- if (flagBits < QMatrix4x4::Rotation2D) {
+ if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
QMatrix4x4 m = m1;
m.m[3][0] += m.m[0][0] * m2.m[3][0];
m.m[3][1] += m.m[1][1] * m2.m[3][1];
@@ -647,7 +620,7 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
return m;
}
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = m1.m[0][0] * m2.m[0][0]
+ m1.m[1][0] * m2.m[0][1]
+ m1.m[2][0] * m2.m[0][2]
@@ -721,6 +694,9 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
#ifndef QT_NO_VECTOR3D
+#if QT_DEPRECATED_SINCE(6, 1)
+
+QT_DEPRECATED_VERSION_X_6_1("Extend the QVector3D to a QVector4D with 1.0 as the w coordinate before multiplying")
inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
{
float x, y, z, w;
@@ -746,47 +722,16 @@ inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
return QVector3D(x / w, y / w, z / w);
}
+QT_DEPRECATED_VERSION_X_6_1("Use matrix.map(vector) instead")
inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
{
- float x, y, z, w;
- if (matrix.flagBits == QMatrix4x4::Identity) {
- return vector;
- } else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
- // Translation | Scale
- return QVector3D(vector.x() * matrix.m[0][0] + matrix.m[3][0],
- vector.y() * matrix.m[1][1] + matrix.m[3][1],
- vector.z() * matrix.m[2][2] + matrix.m[3][2]);
- } else if (matrix.flagBits < QMatrix4x4::Rotation) {
- // Translation | Scale | Rotation2D
- return QVector3D(vector.x() * matrix.m[0][0] + vector.y() * matrix.m[1][0] + matrix.m[3][0],
- vector.x() * matrix.m[0][1] + vector.y() * matrix.m[1][1] + matrix.m[3][1],
- vector.z() * matrix.m[2][2] + matrix.m[3][2]);
- } else {
- x = vector.x() * matrix.m[0][0] +
- vector.y() * matrix.m[1][0] +
- vector.z() * matrix.m[2][0] +
- matrix.m[3][0];
- y = vector.x() * matrix.m[0][1] +
- vector.y() * matrix.m[1][1] +
- vector.z() * matrix.m[2][1] +
- matrix.m[3][1];
- z = vector.x() * matrix.m[0][2] +
- vector.y() * matrix.m[1][2] +
- vector.z() * matrix.m[2][2] +
- matrix.m[3][2];
- w = vector.x() * matrix.m[0][3] +
- vector.y() * matrix.m[1][3] +
- vector.z() * matrix.m[2][3] +
- matrix.m[3][3];
- if (w == 1.0f)
- return QVector3D(x, y, z);
- else
- return QVector3D(x / w, y / w, z / w);
- }
+ return matrix.map(vector);
}
#endif
+#endif
+
#ifndef QT_NO_VECTOR4D
inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
@@ -878,76 +823,25 @@ inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
}
}
+#if QT_DEPRECATED_SINCE(6, 1)
+
+QT_DEPRECATED_VERSION_X_6_1("Use matrix.map(point) instead")
inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
{
- float xin, yin;
- float x, y, w;
- xin = point.x();
- yin = point.y();
- if (matrix.flagBits == QMatrix4x4::Identity) {
- return point;
- } else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
- // Translation | Scale
- return QPoint(qRound(xin * matrix.m[0][0] + matrix.m[3][0]),
- qRound(yin * matrix.m[1][1] + matrix.m[3][1]));
- } else if (matrix.flagBits < QMatrix4x4::Perspective) {
- return QPoint(qRound(xin * matrix.m[0][0] + yin * matrix.m[1][0] + matrix.m[3][0]),
- qRound(xin * matrix.m[0][1] + yin * matrix.m[1][1] + matrix.m[3][1]));
- } else {
- x = xin * matrix.m[0][0] +
- yin * matrix.m[1][0] +
- matrix.m[3][0];
- y = xin * matrix.m[0][1] +
- yin * matrix.m[1][1] +
- matrix.m[3][1];
- w = xin * matrix.m[0][3] +
- yin * matrix.m[1][3] +
- matrix.m[3][3];
- if (w == 1.0f)
- return QPoint(qRound(x), qRound(y));
- else
- return QPoint(qRound(x / w), qRound(y / w));
- }
+ return matrix.map(point);
}
+QT_DEPRECATED_VERSION_X_6_1("Use matrix.map(point) instead")
inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
{
- qreal xin, yin;
- qreal x, y, w;
- xin = point.x();
- yin = point.y();
- if (matrix.flagBits == QMatrix4x4::Identity) {
- return point;
- } else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
- // Translation | Scale
- return QPointF(xin * qreal(matrix.m[0][0]) + qreal(matrix.m[3][0]),
- yin * qreal(matrix.m[1][1]) + qreal(matrix.m[3][1]));
- } else if (matrix.flagBits < QMatrix4x4::Perspective) {
- return QPointF(xin * qreal(matrix.m[0][0]) + yin * qreal(matrix.m[1][0]) +
- qreal(matrix.m[3][0]),
- xin * qreal(matrix.m[0][1]) + yin * qreal(matrix.m[1][1]) +
- qreal(matrix.m[3][1]));
- } else {
- x = xin * qreal(matrix.m[0][0]) +
- yin * qreal(matrix.m[1][0]) +
- qreal(matrix.m[3][0]);
- y = xin * qreal(matrix.m[0][1]) +
- yin * qreal(matrix.m[1][1]) +
- qreal(matrix.m[3][1]);
- w = xin * qreal(matrix.m[0][3]) +
- yin * qreal(matrix.m[1][3]) +
- qreal(matrix.m[3][3]);
- if (w == 1.0) {
- return QPointF(qreal(x), qreal(y));
- } else {
- return QPointF(qreal(x / w), qreal(y / w));
- }
- }
+ return matrix.map(point);
}
+#endif
+
inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
{
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = -matrix.m[0][0];
m.m[0][1] = -matrix.m[0][1];
m.m[0][2] = -matrix.m[0][2];
@@ -964,13 +858,12 @@ inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
m.m[3][1] = -matrix.m[3][1];
m.m[3][2] = -matrix.m[3][2];
m.m[3][3] = -matrix.m[3][3];
- m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
{
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = matrix.m[0][0] * factor;
m.m[0][1] = matrix.m[0][1] * factor;
m.m[0][2] = matrix.m[0][2] * factor;
@@ -987,13 +880,12 @@ inline QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
m.m[3][1] = matrix.m[3][1] * factor;
m.m[3][2] = matrix.m[3][2] * factor;
m.m[3][3] = matrix.m[3][3] * factor;
- m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
{
- QMatrix4x4 m(1);
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = matrix.m[0][0] * factor;
m.m[0][1] = matrix.m[0][1] * factor;
m.m[0][2] = matrix.m[0][2] * factor;
@@ -1010,53 +902,123 @@ inline QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
m.m[3][1] = matrix.m[3][1] * factor;
m.m[3][2] = matrix.m[3][2] * factor;
m.m[3][3] = matrix.m[3][3] * factor;
- m.flagBits = QMatrix4x4::General;
return m;
}
-inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2)
-{
- return qFuzzyCompare(m1.m[0][0], m2.m[0][0]) &&
- qFuzzyCompare(m1.m[0][1], m2.m[0][1]) &&
- qFuzzyCompare(m1.m[0][2], m2.m[0][2]) &&
- qFuzzyCompare(m1.m[0][3], m2.m[0][3]) &&
- qFuzzyCompare(m1.m[1][0], m2.m[1][0]) &&
- qFuzzyCompare(m1.m[1][1], m2.m[1][1]) &&
- qFuzzyCompare(m1.m[1][2], m2.m[1][2]) &&
- qFuzzyCompare(m1.m[1][3], m2.m[1][3]) &&
- qFuzzyCompare(m1.m[2][0], m2.m[2][0]) &&
- qFuzzyCompare(m1.m[2][1], m2.m[2][1]) &&
- qFuzzyCompare(m1.m[2][2], m2.m[2][2]) &&
- qFuzzyCompare(m1.m[2][3], m2.m[2][3]) &&
- qFuzzyCompare(m1.m[3][0], m2.m[3][0]) &&
- qFuzzyCompare(m1.m[3][1], m2.m[3][1]) &&
- qFuzzyCompare(m1.m[3][2], m2.m[3][2]) &&
- qFuzzyCompare(m1.m[3][3], m2.m[3][3]);
-}
-
inline QPoint QMatrix4x4::map(const QPoint& point) const
{
- return *this * point;
+ float xin, yin;
+ float x, y, w;
+ xin = point.x();
+ yin = point.y();
+ if (flagBits == QMatrix4x4::Identity) {
+ return point;
+ } else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
+ // Translation | Scale
+ return QPoint(qRound(xin * m[0][0] + m[3][0]),
+ qRound(yin * m[1][1] + m[3][1]));
+ } else if (flagBits.toInt() < QMatrix4x4::Perspective) {
+ return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
+ qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
+ } else {
+ x = xin * m[0][0] +
+ yin * m[1][0] +
+ m[3][0];
+ y = xin * m[0][1] +
+ yin * m[1][1] +
+ m[3][1];
+ w = xin * m[0][3] +
+ yin * m[1][3] +
+ m[3][3];
+ if (w == 1.0f)
+ return QPoint(qRound(x), qRound(y));
+ else
+ return QPoint(qRound(x / w), qRound(y / w));
+ }
}
inline QPointF QMatrix4x4::map(const QPointF& point) const
{
- return *this * point;
+ qreal xin, yin;
+ qreal x, y, w;
+ xin = point.x();
+ yin = point.y();
+ if (flagBits == QMatrix4x4::Identity) {
+ return point;
+ } else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
+ // Translation | Scale
+ return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
+ yin * qreal(m[1][1]) + qreal(m[3][1]));
+ } else if (flagBits.toInt() < QMatrix4x4::Perspective) {
+ return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
+ qreal(m[3][0]),
+ xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
+ qreal(m[3][1]));
+ } else {
+ x = xin * qreal(m[0][0]) +
+ yin * qreal(m[1][0]) +
+ qreal(m[3][0]);
+ y = xin * qreal(m[0][1]) +
+ yin * qreal(m[1][1]) +
+ qreal(m[3][1]);
+ w = xin * qreal(m[0][3]) +
+ yin * qreal(m[1][3]) +
+ qreal(m[3][3]);
+ if (w == 1.0) {
+ return QPointF(qreal(x), qreal(y));
+ } else {
+ return QPointF(qreal(x / w), qreal(y / w));
+ }
+ }
}
#ifndef QT_NO_VECTOR3D
inline QVector3D QMatrix4x4::map(const QVector3D& point) const
{
- return *this * point;
+ float x, y, z, w;
+ if (flagBits == QMatrix4x4::Identity) {
+ return point;
+ } else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
+ // Translation | Scale
+ return QVector3D(point.x() * m[0][0] + m[3][0],
+ point.y() * m[1][1] + m[3][1],
+ point.z() * m[2][2] + m[3][2]);
+ } else if (flagBits.toInt() < QMatrix4x4::Rotation) {
+ // Translation | Scale | Rotation2D
+ return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
+ point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
+ point.z() * m[2][2] + m[3][2]);
+ } else {
+ x = point.x() * m[0][0] +
+ point.y() * m[1][0] +
+ point.z() * m[2][0] +
+ m[3][0];
+ y = point.x() * m[0][1] +
+ point.y() * m[1][1] +
+ point.z() * m[2][1] +
+ m[3][1];
+ z = point.x() * m[0][2] +
+ point.y() * m[1][2] +
+ point.z() * m[2][2] +
+ m[3][2];
+ w = point.x() * m[0][3] +
+ point.y() * m[1][3] +
+ point.z() * m[2][3] +
+ m[3][3];
+ if (w == 1.0f)
+ return QVector3D(x, y, z);
+ else
+ return QVector3D(x / w, y / w, z / w);
+ }
}
inline QVector3D QMatrix4x4::mapVector(const QVector3D& vector) const
{
- if (flagBits < Scale) {
+ if (flagBits.toInt() < Scale) {
// Translation
return vector;
- } else if (flagBits < Rotation2D) {
+ } else if (flagBits.toInt() < Rotation2D) {
// Translation | Scale
return QVector3D(vector.x() * m[0][0],
vector.y() * m[1][1],
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index 5e23996c15..e7c5945208 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquaternion.h"
#include <QtCore/qdatastream.h>
@@ -62,14 +26,14 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QQuaternion::QQuaternion()
+ \fn QQuaternion::QQuaternion() noexcept
Constructs an identity quaternion (1, 0, 0, 0), i.e. with the vector (0, 0, 0)
and scalar 1.
*/
/*!
- \fn QQuaternion::QQuaternion(Qt::Initialization)
+ \fn QQuaternion::QQuaternion(Qt::Initialization) noexcept
\since 5.5
\internal
@@ -77,7 +41,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QQuaternion::QQuaternion(float scalar, float xpos, float ypos, float zpos)
+ \fn QQuaternion::QQuaternion(float scalar, float xpos, float ypos, float zpos) noexcept
Constructs a quaternion with the vector (\a xpos, \a ypos, \a zpos)
and \a scalar.
@@ -86,7 +50,7 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_VECTOR3D
/*!
- \fn QQuaternion::QQuaternion(float scalar, const QVector3D& vector)
+ \fn QQuaternion::QQuaternion(float scalar, const QVector3D &vector) noexcept
Constructs a quaternion vector from the specified \a vector and
\a scalar.
@@ -95,7 +59,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QVector3D QQuaternion::vector() const
+ \fn QVector3D QQuaternion::vector() const noexcept
Returns the vector component of this quaternion.
@@ -103,7 +67,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setVector(const QVector3D& vector)
+ \fn void QQuaternion::setVector(const QVector3D &vector) noexcept
Sets the vector component of this quaternion to \a vector.
@@ -113,7 +77,7 @@ QT_BEGIN_NAMESPACE
#endif
/*!
- \fn void QQuaternion::setVector(float x, float y, float z)
+ \fn void QQuaternion::setVector(float x, float y, float z) noexcept
Sets the vector component of this quaternion to (\a x, \a y, \a z).
@@ -123,13 +87,13 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_VECTOR4D
/*!
- \fn QQuaternion::QQuaternion(const QVector4D& vector)
+ \fn QQuaternion::QQuaternion(const QVector4D &vector) noexcept
Constructs a quaternion from the components of \a vector.
*/
/*!
- \fn QVector4D QQuaternion::toVector4D() const
+ \fn QVector4D QQuaternion::toVector4D() const noexcept
Returns this quaternion as a 4D vector.
*/
@@ -137,14 +101,14 @@ QT_BEGIN_NAMESPACE
#endif
/*!
- \fn bool QQuaternion::isNull() const
+ \fn bool QQuaternion::isNull() const noexcept
Returns \c true if the x, y, z, and scalar components of this
quaternion are set to 0.0; otherwise returns \c false.
*/
/*!
- \fn bool QQuaternion::isIdentity() const
+ \fn bool QQuaternion::isIdentity() const noexcept
Returns \c true if the x, y, and z components of this
quaternion are set to 0.0, and the scalar component is set
@@ -152,7 +116,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn float QQuaternion::x() const
+ \fn float QQuaternion::x() const noexcept
Returns the x coordinate of this quaternion's vector.
@@ -160,7 +124,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn float QQuaternion::y() const
+ \fn float QQuaternion::y() const noexcept
Returns the y coordinate of this quaternion's vector.
@@ -168,7 +132,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn float QQuaternion::z() const
+ \fn float QQuaternion::z() const noexcept
Returns the z coordinate of this quaternion's vector.
@@ -176,7 +140,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn float QQuaternion::scalar() const
+ \fn float QQuaternion::scalar() const noexcept
Returns the scalar component of this quaternion.
@@ -184,7 +148,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setX(float x)
+ \fn void QQuaternion::setX(float x) noexcept
Sets the x coordinate of this quaternion's vector to the given
\a x coordinate.
@@ -193,7 +157,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setY(float y)
+ \fn void QQuaternion::setY(float y) noexcept
Sets the y coordinate of this quaternion's vector to the given
\a y coordinate.
@@ -202,7 +166,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setZ(float z)
+ \fn void QQuaternion::setZ(float z) noexcept
Sets the z coordinate of this quaternion's vector to the given
\a z coordinate.
@@ -211,7 +175,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setScalar(float scalar)
+ \fn void QQuaternion::setScalar(float scalar) noexcept
Sets the scalar component of this quaternion to \a scalar.
@@ -219,7 +183,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn float QQuaternion::dotProduct(const QQuaternion &q1, const QQuaternion &q2)
+ \fn float QQuaternion::dotProduct(const QQuaternion &q1, const QQuaternion &q2) noexcept
\since 5.5
Returns the dot product of \a q1 and \a q2.
@@ -234,12 +198,15 @@ QT_BEGIN_NAMESPACE
*/
float QQuaternion::length() const
{
- return std::sqrt(xp * xp + yp * yp + zp * zp + wp * wp);
+ return qHypot(xp, yp, zp, wp);
}
/*!
Returns the squared length of the quaternion.
+ \note Though cheap to compute, this is susceptible to overflow and underflow
+ that length() avoids in many cases.
+
\sa length(), dotProduct()
*/
float QQuaternion::lengthSquared() const
@@ -259,17 +226,10 @@ float QQuaternion::lengthSquared() const
*/
QQuaternion QQuaternion::normalized() const
{
- // Need some extra precision if the length is very small.
- double len = double(xp) * double(xp) +
- double(yp) * double(yp) +
- double(zp) * double(zp) +
- double(wp) * double(wp);
- if (qFuzzyIsNull(len - 1.0f))
- return *this;
- else if (!qFuzzyIsNull(len))
- return *this / std::sqrt(len);
- else
+ const float scale = length();
+ if (qFuzzyIsNull(scale))
return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
+ return *this / scale;
}
/*!
@@ -280,16 +240,10 @@ QQuaternion QQuaternion::normalized() const
*/
void QQuaternion::normalize()
{
- // Need some extra precision if the length is very small.
- double len = double(xp) * double(xp) +
- double(yp) * double(yp) +
- double(zp) * double(zp) +
- double(wp) * double(wp);
- if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ const float len = length();
+ if (qFuzzyIsNull(len))
return;
- len = std::sqrt(len);
-
xp /= len;
yp /= len;
zp /= len;
@@ -297,7 +251,7 @@ void QQuaternion::normalize()
}
/*!
- \fn QQuaternion QQuaternion::inverted() const
+ \fn QQuaternion QQuaternion::inverted() const noexcept
\since 5.5
Returns the inverse of this quaternion.
@@ -307,7 +261,7 @@ void QQuaternion::normalize()
*/
/*!
- \fn QQuaternion QQuaternion::conjugated() const
+ \fn QQuaternion QQuaternion::conjugated() const noexcept
\since 5.5
Returns the conjugate of this quaternion, which is
@@ -324,13 +278,13 @@ void QQuaternion::normalize()
\snippet code/src_gui_math3d_qquaternion.cpp 1
*/
-QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
+QVector3D QQuaternion::rotatedVector(const QVector3D &vector) const
{
return (*this * QQuaternion(0, vector) * conjugated()).vector();
}
/*!
- \fn QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion)
+ \fn QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion) noexcept
Adds the given \a quaternion to this quaternion and returns a reference to
this quaternion.
@@ -339,7 +293,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
*/
/*!
- \fn QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
+ \fn QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion) noexcept
Subtracts the given \a quaternion from this quaternion and returns a
reference to this quaternion.
@@ -348,7 +302,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
*/
/*!
- \fn QQuaternion &QQuaternion::operator*=(float factor)
+ \fn QQuaternion &QQuaternion::operator*=(float factor) noexcept
Multiplies this quaternion's components by the given \a factor, and
returns a reference to this quaternion.
@@ -357,7 +311,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
*/
/*!
- \fn QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion)
+ \fn QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion) noexcept
Multiplies this quaternion by \a quaternion and returns a reference
to this quaternion.
@@ -375,7 +329,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
#ifndef QT_NO_VECTOR3D
/*!
- \fn void QQuaternion::getAxisAndAngle(QVector3D *axis, float *angle) const
+ \fn void QQuaternion::getAxisAndAngle(QVector3D *axis, float *angle) const noexcept
\since 5.5
\overload
@@ -391,7 +345,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
\sa getAxisAndAngle()
*/
-QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, float angle)
+QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D &axis, float angle)
{
// Algorithm from:
// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56
@@ -421,24 +375,22 @@ void QQuaternion::getAxisAndAngle(float *x, float *y, float *z, float *angle) co
// The quaternion representing the rotation is
// q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)
- float length = xp * xp + yp * yp + zp * zp;
+ const float length = qHypot(xp, yp, zp);
if (!qFuzzyIsNull(length)) {
- *x = xp;
- *y = yp;
- *z = zp;
- if (!qFuzzyIsNull(length - 1.0f)) {
- length = std::sqrt(length);
- *x /= length;
- *y /= length;
- *z /= length;
+ if (qFuzzyCompare(length, 1.0f)) {
+ *x = xp;
+ *y = yp;
+ *z = zp;
+ } else {
+ *x = xp / length;
+ *y = yp / length;
+ *z = zp / length;
}
- *angle = 2.0f * std::acos(wp);
+ *angle = qRadiansToDegrees(2.0f * std::atan2(length, wp));
} else {
// angle is 0 (mod 2*pi), so any axis will fit
*x = *y = *z = *angle = 0.0f;
}
-
- *angle = qRadiansToDegrees(*angle);
}
/*!
@@ -450,8 +402,8 @@ void QQuaternion::getAxisAndAngle(float *x, float *y, float *z, float *angle) co
QQuaternion QQuaternion::fromAxisAndAngle
(float x, float y, float z, float angle)
{
- float length = std::sqrt(x * x + y * y + z * z);
- if (!qFuzzyIsNull(length - 1.0f) && !qFuzzyIsNull(length)) {
+ float length = qHypot(x, y, z);
+ if (!qFuzzyCompare(length, 1.0f) && !qFuzzyIsNull(length)) {
x /= length;
y /= length;
z /= length;
@@ -501,46 +453,47 @@ void QQuaternion::getEulerAngles(float *pitch, float *yaw, float *roll) const
{
Q_ASSERT(pitch && yaw && roll);
- // Algorithm from:
- // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q37
-
- float xx = xp * xp;
- float xy = xp * yp;
- float xz = xp * zp;
- float xw = xp * wp;
- float yy = yp * yp;
- float yz = yp * zp;
- float yw = yp * wp;
- float zz = zp * zp;
- float zw = zp * wp;
-
- const float lengthSquared = xx + yy + zz + wp * wp;
- if (!qFuzzyIsNull(lengthSquared - 1.0f) && !qFuzzyIsNull(lengthSquared)) {
- xx /= lengthSquared;
- xy /= lengthSquared; // same as (xp / length) * (yp / length)
- xz /= lengthSquared;
- xw /= lengthSquared;
- yy /= lengthSquared;
- yz /= lengthSquared;
- yw /= lengthSquared;
- zz /= lengthSquared;
- zw /= lengthSquared;
- }
-
- *pitch = std::asin(-2.0f * (yz - xw));
- if (*pitch < M_PI_2) {
- if (*pitch > -M_PI_2) {
- *yaw = std::atan2(2.0f * (xz + yw), 1.0f - 2.0f * (xx + yy));
- *roll = std::atan2(2.0f * (xy + zw), 1.0f - 2.0f * (xx + zz));
- } else {
- // not a unique solution
- *roll = 0.0f;
- *yaw = -std::atan2(-2.0f * (xy - zw), 1.0f - 2.0f * (yy + zz));
- }
+ // Algorithm adapted from:
+ // https://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf
+ // "A tutorial on SE(3) transformation parameterizations and on-manifold optimization".
+
+ // We can only detect Gimbal lock when we normalize, which we can't do when
+ // length is nearly zero. Do so before multiplying coordinates, to avoid
+ // underflow.
+ const float len = length();
+ const bool rescale = !qFuzzyIsNull(len);
+ const float xps = rescale ? xp / len : xp;
+ const float yps = rescale ? yp / len : yp;
+ const float zps = rescale ? zp / len : zp;
+ const float wps = rescale ? wp / len : wp;
+
+ const float xx = xps * xps;
+ const float xy = xps * yps;
+ const float xz = xps * zps;
+ const float xw = xps * wps;
+ const float yy = yps * yps;
+ const float yz = yps * zps;
+ const float yw = yps * wps;
+ const float zz = zps * zps;
+ const float zw = zps * wps;
+
+ // For the common case, we have a hidden division by cos(pitch) to calculate
+ // yaw and roll: atan2(a / cos(pitch), b / cos(pitch)) = atan2(a, b). This equation
+ // wouldn't work if cos(pitch) is close to zero (i.e. abs(sin(pitch)) =~ 1.0).
+ // This threshold is copied from qFuzzyIsNull() to avoid the hidden division by zero.
+ constexpr float epsilon = 0.00001f;
+
+ const float sinp = -2.0f * (yz - xw);
+ if (std::abs(sinp) < 1.0f - epsilon) {
+ *pitch = std::asin(sinp);
+ *yaw = std::atan2(2.0f * (xz + yw), 1.0f - 2.0f * (xx + yy));
+ *roll = std::atan2(2.0f * (xy + zw), 1.0f - 2.0f * (xx + zz));
} else {
- // not a unique solution
+ // Gimbal lock case, which doesn't have a unique solution. We just use
+ // XY rotation.
+ *pitch = std::copysign(static_cast<float>(M_PI_2), sinp);
+ *yaw = 2.0f * std::atan2(yps, wps);
*roll = 0.0f;
- *yaw = std::atan2(-2.0f * (xy - zw), 1.0f - 2.0f * (yy + zz));
}
*pitch = qRadiansToDegrees(*pitch);
@@ -785,23 +738,21 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
#endif // QT_NO_VECTOR3D
/*!
- \fn bool operator==(const QQuaternion &q1, const QQuaternion &q2)
- \relates QQuaternion
+ \fn bool QQuaternion::operator==(const QQuaternion &q1, const QQuaternion &q2) noexcept
Returns \c true if \a q1 is equal to \a q2; otherwise returns \c false.
This operator uses an exact floating-point comparison.
*/
/*!
- \fn bool operator!=(const QQuaternion &q1, const QQuaternion &q2)
- \relates QQuaternion
+ \fn bool QQuaternion::operator!=(const QQuaternion &q1, const QQuaternion &q2) noexcept
Returns \c true if \a q1 is not equal to \a q2; otherwise returns \c false.
This operator uses an exact floating-point comparison.
*/
/*!
- \fn const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2)
+ \fn const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2) noexcept
\relates QQuaternion
Returns a QQuaternion object that is the sum of the given quaternions,
@@ -811,7 +762,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
*/
/*!
- \fn const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2)
+ \fn const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2) noexcept
\relates QQuaternion
Returns a QQuaternion object that is formed by subtracting
@@ -821,7 +772,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
*/
/*!
- \fn const QQuaternion operator*(float factor, const QQuaternion &quaternion)
+ \fn const QQuaternion operator*(float factor, const QQuaternion &quaternion) noexcept
\relates QQuaternion
Returns a copy of the given \a quaternion, multiplied by the
@@ -831,7 +782,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
*/
/*!
- \fn const QQuaternion operator*(const QQuaternion &quaternion, float factor)
+ \fn const QQuaternion operator*(const QQuaternion &quaternion, float factor) noexcept
\relates QQuaternion
Returns a copy of the given \a quaternion, multiplied by the
@@ -841,7 +792,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
*/
/*!
- \fn const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2)
+ \fn const QQuaternion operator*(const QQuaternion &q1, const QQuaternion &q2) noexcept
\relates QQuaternion
Multiplies \a q1 and \a q2 using quaternion multiplication.
@@ -852,7 +803,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
*/
/*!
- \fn const QQuaternion operator-(const QQuaternion &quaternion)
+ \fn const QQuaternion operator-(const QQuaternion &quaternion) noexcept
\relates QQuaternion
\overload
@@ -875,7 +826,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
#ifndef QT_NO_VECTOR3D
/*!
- \fn QVector3D operator*(const QQuaternion &quaternion, const QVector3D &vec)
+ \fn QVector3D operator*(const QQuaternion &quaternion, const QVector3D &vec) noexcept
\since 5.5
\relates QQuaternion
@@ -885,7 +836,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
#endif
/*!
- \fn bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
+ \fn bool qFuzzyCompare(const QQuaternion &q1, const QQuaternion &q2) noexcept
\relates QQuaternion
Returns \c true if \a q1 and \a q2 are equal, allowing for a small
@@ -904,7 +855,7 @@ QQuaternion QQuaternion::rotationTo(const QVector3D &from, const QVector3D &to)
\sa nlerp()
*/
QQuaternion QQuaternion::slerp
- (const QQuaternion& q1, const QQuaternion& q2, float t)
+ (const QQuaternion &q1, const QQuaternion &q2, float t)
{
// Handle the easy cases first.
if (t <= 0.0f)
@@ -953,7 +904,7 @@ QQuaternion QQuaternion::slerp
\sa slerp()
*/
QQuaternion QQuaternion::nlerp
- (const QQuaternion& q1, const QQuaternion& q2, float t)
+ (const QQuaternion &q1, const QQuaternion &q2, float t)
{
// Handle the easy cases first.
if (t <= 0.0f)
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
index cfe495530e..7cfbd9b818 100644
--- a/src/gui/math3d/qquaternion.h
+++ b/src/gui/math3d/qquaternion.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUATERNION_H
#define QQUATERNION_H
@@ -53,153 +17,165 @@ QT_BEGIN_NAMESPACE
class QMatrix4x4;
class QVariant;
-class Q_GUI_EXPORT QQuaternion
+class QT6_ONLY(Q_GUI_EXPORT) QQuaternion
{
public:
- QQuaternion();
- explicit QQuaternion(Qt::Initialization) {}
- QQuaternion(float scalar, float xpos, float ypos, float zpos);
+ constexpr QQuaternion() noexcept;
+ explicit QQuaternion(Qt::Initialization) noexcept {}
+ constexpr QQuaternion(float scalar, float xpos, float ypos, float zpos) noexcept;
#ifndef QT_NO_VECTOR3D
- QQuaternion(float scalar, const QVector3D& vector);
+ constexpr QQuaternion(float scalar, const QVector3D &vector) noexcept;
#endif
#ifndef QT_NO_VECTOR4D
- explicit QQuaternion(const QVector4D& vector);
+ constexpr explicit QQuaternion(const QVector4D &vector) noexcept;
#endif
- bool isNull() const;
- bool isIdentity() const;
+ constexpr bool isNull() const noexcept;
+ constexpr bool isIdentity() const noexcept;
#ifndef QT_NO_VECTOR3D
- QVector3D vector() const;
- void setVector(const QVector3D& vector);
+ constexpr QVector3D vector() const noexcept;
+ constexpr void setVector(const QVector3D &vector) noexcept;
#endif
- void setVector(float x, float y, float z);
+ constexpr void setVector(float x, float y, float z) noexcept;
- float x() const;
- float y() const;
- float z() const;
- float scalar() const;
+ constexpr float x() const noexcept;
+ constexpr float y() const noexcept;
+ constexpr float z() const noexcept;
+ constexpr float scalar() const noexcept;
- void setX(float x);
- void setY(float y);
- void setZ(float z);
- void setScalar(float scalar);
+ constexpr void setX(float x) noexcept;
+ constexpr void setY(float y) noexcept;
+ constexpr void setZ(float z) noexcept;
+ constexpr void setScalar(float scalar) noexcept;
- constexpr static inline float dotProduct(const QQuaternion &q1, const QQuaternion &q2);
+ constexpr static float dotProduct(const QQuaternion &q1, const QQuaternion &q2) noexcept;
- float length() const;
- float lengthSquared() const;
+ // ### Qt 7: make the next four constexpr
+ // (perhaps using std::hypot, constexpr in C++26, or constexpr qHypot)
+ QT7_ONLY(Q_GUI_EXPORT) float length() const;
+ QT7_ONLY(Q_GUI_EXPORT) float lengthSquared() const;
- Q_REQUIRED_RESULT QQuaternion normalized() const;
- void normalize();
+ [[nodiscard]] QT7_ONLY(Q_GUI_EXPORT) QQuaternion normalized() const;
+ QT7_ONLY(Q_GUI_EXPORT) void normalize();
- inline QQuaternion inverted() const;
+ constexpr QQuaternion inverted() const noexcept;
- Q_REQUIRED_RESULT QQuaternion conjugated() const;
+ [[nodiscard]] constexpr QQuaternion conjugated() const noexcept;
- QVector3D rotatedVector(const QVector3D& vector) const;
+ QT7_ONLY(Q_GUI_EXPORT) QVector3D rotatedVector(const QVector3D &vector) const;
- QQuaternion &operator+=(const QQuaternion &quaternion);
- QQuaternion &operator-=(const QQuaternion &quaternion);
- QQuaternion &operator*=(float factor);
- QQuaternion &operator*=(const QQuaternion &quaternion);
- QQuaternion &operator/=(float divisor);
+ constexpr QQuaternion &operator+=(const QQuaternion &quaternion) noexcept;
+ constexpr QQuaternion &operator-=(const QQuaternion &quaternion) noexcept;
+ constexpr QQuaternion &operator*=(float factor) noexcept;
+ constexpr QQuaternion &operator*=(const QQuaternion &quaternion) noexcept;
+ constexpr QQuaternion &operator/=(float divisor);
- friend inline bool operator==(const QQuaternion &q1, const QQuaternion &q2);
- friend inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2);
- friend inline const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2);
- friend inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2);
- friend inline const QQuaternion operator*(float factor, const QQuaternion &quaternion);
- friend inline const QQuaternion operator*(const QQuaternion &quaternion, float factor);
- friend inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2);
- friend inline const QQuaternion operator-(const QQuaternion &quaternion);
- friend inline const QQuaternion operator/(const QQuaternion &quaternion, float divisor);
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_FLOAT_COMPARE
+ friend constexpr bool operator==(const QQuaternion &q1, const QQuaternion &q2) noexcept
+ {
+ return q1.wp == q2.wp && q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp;
+ }
+ friend constexpr bool operator!=(const QQuaternion &q1, const QQuaternion &q2) noexcept
+ {
+ return !(q1 == q2);
+ }
+QT_WARNING_POP
- friend inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2);
+ friend constexpr QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2) noexcept;
+ friend constexpr QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2) noexcept;
+ friend constexpr QQuaternion operator*(float factor, const QQuaternion &quaternion) noexcept;
+ friend constexpr QQuaternion operator*(const QQuaternion &quaternion, float factor) noexcept;
+ friend constexpr QQuaternion operator*(const QQuaternion &q1, const QQuaternion &q2) noexcept;
+ friend constexpr QQuaternion operator-(const QQuaternion &quaternion) noexcept;
+ friend constexpr QQuaternion operator/(const QQuaternion &quaternion, float divisor);
+
+ friend constexpr bool qFuzzyCompare(const QQuaternion &q1, const QQuaternion &q2) noexcept;
#ifndef QT_NO_VECTOR4D
- QVector4D toVector4D() const;
+ constexpr QVector4D toVector4D() const noexcept;
#endif
- operator QVariant() const;
+ QT7_ONLY(Q_GUI_EXPORT) operator QVariant() const;
#ifndef QT_NO_VECTOR3D
inline void getAxisAndAngle(QVector3D *axis, float *angle) const;
- static QQuaternion fromAxisAndAngle(const QVector3D& axis, float angle);
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromAxisAndAngle(const QVector3D &axis, float angle);
#endif
- void getAxisAndAngle(float *x, float *y, float *z, float *angle) const;
- static QQuaternion fromAxisAndAngle
- (float x, float y, float z, float angle);
+ QT7_ONLY(Q_GUI_EXPORT) void getAxisAndAngle(float *x, float *y, float *z, float *angle) const;
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromAxisAndAngle(float x, float y, float z,
+ float angle);
#ifndef QT_NO_VECTOR3D
inline QVector3D toEulerAngles() const;
- static inline QQuaternion fromEulerAngles(const QVector3D &eulerAngles);
+ QT7_ONLY(Q_GUI_EXPORT) static inline QQuaternion fromEulerAngles(const QVector3D &eulerAngles);
#endif
- void getEulerAngles(float *pitch, float *yaw, float *roll) const;
- static QQuaternion fromEulerAngles(float pitch, float yaw, float roll);
+ QT7_ONLY(Q_GUI_EXPORT) void getEulerAngles(float *pitch, float *yaw, float *roll) const;
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromEulerAngles(float pitch, float yaw, float roll);
- QMatrix3x3 toRotationMatrix() const;
- static QQuaternion fromRotationMatrix(const QMatrix3x3 &rot3x3);
+ QT7_ONLY(Q_GUI_EXPORT) QMatrix3x3 toRotationMatrix() const;
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromRotationMatrix(const QMatrix3x3 &rot3x3);
#ifndef QT_NO_VECTOR3D
- void getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const;
- static QQuaternion fromAxes(const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis);
+ QT7_ONLY(Q_GUI_EXPORT) void getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const;
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromAxes(const QVector3D &xAxis,
+ const QVector3D &yAxis,
+ const QVector3D &zAxis);
- static QQuaternion fromDirection(const QVector3D &direction, const QVector3D &up);
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromDirection(const QVector3D &direction,
+ const QVector3D &up);
- static QQuaternion rotationTo(const QVector3D &from, const QVector3D &to);
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion rotationTo(const QVector3D &from,
+ const QVector3D &to);
#endif
- static QQuaternion slerp
- (const QQuaternion& q1, const QQuaternion& q2, float t);
- static QQuaternion nlerp
- (const QQuaternion& q1, const QQuaternion& q2, float t);
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion slerp(const QQuaternion &q1, const QQuaternion &q2,
+ float t);
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion nlerp(const QQuaternion &q1, const QQuaternion &q2,
+ float t);
private:
float wp, xp, yp, zp;
};
-Q_DECLARE_TYPEINFO(QQuaternion, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QQuaternion, Q_PRIMITIVE_TYPE);
-inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {}
+constexpr QQuaternion::QQuaternion() noexcept : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {}
-inline QQuaternion::QQuaternion(float aScalar, float xpos, float ypos, float zpos) : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}
+constexpr QQuaternion::QQuaternion(float aScalar, float xpos, float ypos, float zpos) noexcept
+ : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}
QT_WARNING_PUSH
QT_WARNING_DISABLE_FLOAT_COMPARE
-inline bool QQuaternion::isNull() const
+constexpr bool QQuaternion::isNull() const noexcept
{
return wp == 0.0f && xp == 0.0f && yp == 0.0f && zp == 0.0f;
}
-inline bool QQuaternion::isIdentity() const
+constexpr bool QQuaternion::isIdentity() const noexcept
{
return wp == 1.0f && xp == 0.0f && yp == 0.0f && zp == 0.0f;
}
-
-inline bool operator==(const QQuaternion &q1, const QQuaternion &q2)
-{
- return q1.wp == q2.wp && q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp;
-}
QT_WARNING_POP
-inline float QQuaternion::x() const { return xp; }
-inline float QQuaternion::y() const { return yp; }
-inline float QQuaternion::z() const { return zp; }
-inline float QQuaternion::scalar() const { return wp; }
+constexpr float QQuaternion::x() const noexcept { return xp; }
+constexpr float QQuaternion::y() const noexcept { return yp; }
+constexpr float QQuaternion::z() const noexcept { return zp; }
+constexpr float QQuaternion::scalar() const noexcept { return wp; }
-inline void QQuaternion::setX(float aX) { xp = aX; }
-inline void QQuaternion::setY(float aY) { yp = aY; }
-inline void QQuaternion::setZ(float aZ) { zp = aZ; }
-inline void QQuaternion::setScalar(float aScalar) { wp = aScalar; }
+constexpr void QQuaternion::setX(float aX) noexcept { xp = aX; }
+constexpr void QQuaternion::setY(float aY) noexcept { yp = aY; }
+constexpr void QQuaternion::setZ(float aZ) noexcept { zp = aZ; }
+constexpr void QQuaternion::setScalar(float aScalar) noexcept { wp = aScalar; }
-constexpr inline float QQuaternion::dotProduct(const QQuaternion &q1, const QQuaternion &q2)
+constexpr float QQuaternion::dotProduct(const QQuaternion &q1, const QQuaternion &q2) noexcept
{
return q1.wp * q2.wp + q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp;
}
-inline QQuaternion QQuaternion::inverted() const
+constexpr QQuaternion QQuaternion::inverted() const noexcept
{
// Need some extra precision if the length is very small.
double len = double(wp) * double(wp) +
@@ -212,12 +188,12 @@ inline QQuaternion QQuaternion::inverted() const
return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
}
-inline QQuaternion QQuaternion::conjugated() const
+constexpr QQuaternion QQuaternion::conjugated() const noexcept
{
return QQuaternion(wp, -xp, -yp, -zp);
}
-inline QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion)
+constexpr QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion) noexcept
{
wp += quaternion.wp;
xp += quaternion.xp;
@@ -226,7 +202,7 @@ inline QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion)
return *this;
}
-inline QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
+constexpr QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion) noexcept
{
wp -= quaternion.wp;
xp -= quaternion.xp;
@@ -235,7 +211,7 @@ inline QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
return *this;
}
-inline QQuaternion &QQuaternion::operator*=(float factor)
+constexpr QQuaternion &QQuaternion::operator*=(float factor) noexcept
{
wp *= factor;
xp *= factor;
@@ -244,7 +220,7 @@ inline QQuaternion &QQuaternion::operator*=(float factor)
return *this;
}
-inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2)
+constexpr QQuaternion operator*(const QQuaternion &q1, const QQuaternion &q2) noexcept
{
float yy = (q1.wp - q1.yp) * (q2.wp + q2.zp);
float zz = (q1.wp + q1.yp) * (q2.wp - q2.zp);
@@ -260,13 +236,13 @@ inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2)
return QQuaternion(w, x, y, z);
}
-inline QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion)
+constexpr QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion) noexcept
{
*this = *this * quaternion;
return *this;
}
-inline QQuaternion &QQuaternion::operator/=(float divisor)
+constexpr QQuaternion &QQuaternion::operator/=(float divisor)
{
wp /= divisor;
xp /= divisor;
@@ -275,42 +251,37 @@ inline QQuaternion &QQuaternion::operator/=(float divisor)
return *this;
}
-inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2)
-{
- return !operator==(q1, q2);
-}
-
-inline const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2)
+constexpr QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2) noexcept
{
return QQuaternion(q1.wp + q2.wp, q1.xp + q2.xp, q1.yp + q2.yp, q1.zp + q2.zp);
}
-inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2)
+constexpr QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2) noexcept
{
return QQuaternion(q1.wp - q2.wp, q1.xp - q2.xp, q1.yp - q2.yp, q1.zp - q2.zp);
}
-inline const QQuaternion operator*(float factor, const QQuaternion &quaternion)
+constexpr QQuaternion operator*(float factor, const QQuaternion &quaternion) noexcept
{
return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
}
-inline const QQuaternion operator*(const QQuaternion &quaternion, float factor)
+constexpr QQuaternion operator*(const QQuaternion &quaternion, float factor) noexcept
{
return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
}
-inline const QQuaternion operator-(const QQuaternion &quaternion)
+constexpr QQuaternion operator-(const QQuaternion &quaternion) noexcept
{
return QQuaternion(-quaternion.wp, -quaternion.xp, -quaternion.yp, -quaternion.zp);
}
-inline const QQuaternion operator/(const QQuaternion &quaternion, float divisor)
+constexpr QQuaternion operator/(const QQuaternion &quaternion, float divisor)
{
return QQuaternion(quaternion.wp / divisor, quaternion.xp / divisor, quaternion.yp / divisor, quaternion.zp / divisor);
}
-inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
+constexpr bool qFuzzyCompare(const QQuaternion &q1, const QQuaternion &q2) noexcept
{
return qFuzzyCompare(q1.wp, q2.wp) &&
qFuzzyCompare(q1.xp, q2.xp) &&
@@ -320,17 +291,17 @@ inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
#ifndef QT_NO_VECTOR3D
-inline QQuaternion::QQuaternion(float aScalar, const QVector3D& aVector)
+constexpr QQuaternion::QQuaternion(float aScalar, const QVector3D &aVector) noexcept
: wp(aScalar), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}
-inline void QQuaternion::setVector(const QVector3D& aVector)
+constexpr void QQuaternion::setVector(const QVector3D &aVector) noexcept
{
xp = aVector.x();
yp = aVector.y();
zp = aVector.z();
}
-inline QVector3D QQuaternion::vector() const
+constexpr QVector3D QQuaternion::vector() const noexcept
{
return QVector3D(xp, yp, zp);
}
@@ -361,7 +332,7 @@ inline QQuaternion QQuaternion::fromEulerAngles(const QVector3D &eulerAngles)
#endif
-inline void QQuaternion::setVector(float aX, float aY, float aZ)
+constexpr void QQuaternion::setVector(float aX, float aY, float aZ) noexcept
{
xp = aX;
yp = aY;
@@ -370,10 +341,10 @@ inline void QQuaternion::setVector(float aX, float aY, float aZ)
#ifndef QT_NO_VECTOR4D
-inline QQuaternion::QQuaternion(const QVector4D& aVector)
+constexpr QQuaternion::QQuaternion(const QVector4D &aVector) noexcept
: wp(aVector.w()), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}
-inline QVector4D QQuaternion::toVector4D() const
+constexpr QVector4D QQuaternion::toVector4D() const noexcept
{
return QVector4D(xp, yp, zp, wp);
}
diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp
deleted file mode 100644
index aa2d332f9e..0000000000
--- a/src/gui/math3d/qvector2d.cpp
+++ /dev/null
@@ -1,560 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvector2d.h"
-#include "qvector3d.h"
-#include "qvector4d.h"
-#include <QtCore/qdatastream.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qvariant.h>
-#include <QtCore/qmath.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_VECTOR2D
-
-static_assert(std::is_standard_layout<QVector2D>::value, "QVector2D is supposed to be standard layout");
-static_assert(sizeof(QVector2D) == sizeof(float) * 2, "QVector2D is not supposed to have padding at the end");
-
-/*!
- \class QVector2D
- \brief The QVector2D class represents a vector or vertex in 2D space.
- \since 4.6
- \ingroup painting
- \ingroup painting-3D
- \inmodule QtGui
-
- The QVector2D class can also be used to represent vertices in 2D space.
- We therefore do not need to provide a separate vertex class.
-
- \sa QVector3D, QVector4D, QQuaternion
-*/
-
-/*!
- \fn QVector2D::QVector2D()
-
- Constructs a null vector, i.e. with coordinates (0, 0).
-*/
-
-/*!
- \fn QVector2D::QVector2D(Qt::Initialization)
- \since 5.5
- \internal
-
- Constructs a vector without initializing the contents.
-*/
-
-/*!
- \fn QVector2D::QVector2D(float xpos, float ypos)
-
- Constructs a vector with coordinates (\a xpos, \a ypos).
-*/
-
-/*!
- \fn QVector2D::QVector2D(const QPoint& point)
-
- Constructs a vector with x and y coordinates from a 2D \a point.
-*/
-
-/*!
- \fn QVector2D::QVector2D(const QPointF& point)
-
- Constructs a vector with x and y coordinates from a 2D \a point.
-*/
-
-#ifndef QT_NO_VECTOR3D
-
-/*!
- Constructs a vector with x and y coordinates from a 3D \a vector.
- The z coordinate of \a vector is dropped.
-
- \sa toVector3D()
-*/
-QVector2D::QVector2D(const QVector3D& vector)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
-}
-
-#endif
-
-#ifndef QT_NO_VECTOR4D
-
-/*!
- Constructs a vector with x and y coordinates from a 3D \a vector.
- The z and w coordinates of \a vector are dropped.
-
- \sa toVector4D()
-*/
-QVector2D::QVector2D(const QVector4D& vector)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
-}
-
-#endif
-
-/*!
- \fn bool QVector2D::isNull() const
-
- Returns \c true if the x and y coordinates are set to 0.0,
- otherwise returns \c false.
-*/
-
-/*!
- \fn float QVector2D::x() const
-
- Returns the x coordinate of this point.
-
- \sa setX(), y()
-*/
-
-/*!
- \fn float QVector2D::y() const
-
- Returns the y coordinate of this point.
-
- \sa setY(), x()
-*/
-
-/*!
- \fn void QVector2D::setX(float x)
-
- Sets the x coordinate of this point to the given \a x coordinate.
-
- \sa x(), setY()
-*/
-
-/*!
- \fn void QVector2D::setY(float y)
-
- Sets the y coordinate of this point to the given \a y coordinate.
-
- \sa y(), setX()
-*/
-
-/*! \fn float &QVector2D::operator[](int i)
- \since 5.2
-
- Returns the component of the vector at index position \a i
- as a modifiable reference.
-
- \a i must be a valid index position in the vector (i.e., 0 <= \a i
- < 2).
-*/
-
-/*! \fn float QVector2D::operator[](int i) const
- \since 5.2
-
- Returns the component of the vector at index position \a i.
-
- \a i must be a valid index position in the vector (i.e., 0 <= \a i
- < 2).
-*/
-
-/*!
- Returns the length of the vector from the origin.
-
- \sa lengthSquared(), normalized()
-*/
-float QVector2D::length() const
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]);
- return float(std::sqrt(len));
-}
-
-/*!
- Returns the squared length of the vector from the origin.
- This is equivalent to the dot product of the vector with itself.
-
- \sa length(), dotProduct()
-*/
-float QVector2D::lengthSquared() const
-{
- return v[0] * v[0] + v[1] * v[1];
-}
-
-/*!
- Returns the normalized unit vector form of this vector.
-
- If this vector is null, then a null vector is returned. If the length
- of the vector is very close to 1, then the vector will be returned as-is.
- Otherwise the normalized form of the vector of length 1 will be returned.
-
- \sa length(), normalize()
-*/
-QVector2D QVector2D::normalized() const
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]);
- if (qFuzzyIsNull(len - 1.0f)) {
- return *this;
- } else if (!qFuzzyIsNull(len)) {
- double sqrtLen = std::sqrt(len);
- return QVector2D(float(double(v[0]) / sqrtLen), float(double(v[1]) / sqrtLen));
- } else {
- return QVector2D();
- }
-}
-
-/*!
- Normalizes the currect vector in place. Nothing happens if this
- vector is a null vector or the length of the vector is very close to 1.
-
- \sa length(), normalized()
-*/
-void QVector2D::normalize()
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]);
- if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
- return;
-
- len = std::sqrt(len);
-
- v[0] = float(double(v[0]) / len);
- v[1] = float(double(v[1]) / len);
-}
-
-/*!
- \since 5.1
-
- Returns the distance from this vertex to a point defined by
- the vertex \a point.
-
- \sa distanceToLine()
-*/
-float QVector2D::distanceToPoint(const QVector2D& point) const
-{
- return (*this - point).length();
-}
-
-/*!
- \since 5.1
-
- Returns the distance that this vertex is from a line defined
- by \a point and the unit vector \a direction.
-
- If \a direction is a null vector, then it does not define a line.
- In that case, the distance from \a point to this vertex is returned.
-
- \sa distanceToPoint()
-*/
-float QVector2D::distanceToLine
- (const QVector2D& point, const QVector2D& direction) const
-{
- if (direction.isNull())
- return (*this - point).length();
- QVector2D p = point + dotProduct(*this - point, direction) * direction;
- return (*this - p).length();
-}
-
-/*!
- \fn QVector2D &QVector2D::operator+=(const QVector2D &vector)
-
- Adds the given \a vector to this vector and returns a reference to
- this vector.
-
- \sa operator-=()
-*/
-
-/*!
- \fn QVector2D &QVector2D::operator-=(const QVector2D &vector)
-
- Subtracts the given \a vector from this vector and returns a reference to
- this vector.
-
- \sa operator+=()
-*/
-
-/*!
- \fn QVector2D &QVector2D::operator*=(float factor)
-
- Multiplies this vector's coordinates by the given \a factor, and
- returns a reference to this vector.
-
- \sa operator/=()
-*/
-
-/*!
- \fn QVector2D &QVector2D::operator*=(const QVector2D &vector)
-
- Multiplies the components of this vector by the corresponding
- components in \a vector.
-*/
-
-/*!
- \fn QVector2D &QVector2D::operator/=(float divisor)
-
- Divides this vector's coordinates by the given \a divisor, and
- returns a reference to this vector.
-
- \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.
-*/
-float QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
-{
- return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1];
-}
-
-/*!
- \fn bool operator==(const QVector2D &v1, const QVector2D &v2)
- \relates QVector2D
-
- Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
- This operator uses an exact floating-point comparison.
-*/
-
-/*!
- \fn bool operator!=(const QVector2D &v1, const QVector2D &v2)
- \relates QVector2D
-
- Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
- This operator uses an exact floating-point comparison.
-*/
-
-/*!
- \fn const QVector2D operator+(const QVector2D &v1, const QVector2D &v2)
- \relates QVector2D
-
- Returns a QVector2D object that is the sum of the given vectors, \a v1
- and \a v2; each component is added separately.
-
- \sa QVector2D::operator+=()
-*/
-
-/*!
- \fn const QVector2D operator-(const QVector2D &v1, const QVector2D &v2)
- \relates QVector2D
-
- Returns a QVector2D object that is formed by subtracting \a v2 from \a v1;
- each component is subtracted separately.
-
- \sa QVector2D::operator-=()
-*/
-
-/*!
- \fn const QVector2D operator*(float factor, const QVector2D &vector)
- \relates QVector2D
-
- Returns a copy of the given \a vector, multiplied by the given \a factor.
-
- \sa QVector2D::operator*=()
-*/
-
-/*!
- \fn const QVector2D operator*(const QVector2D &vector, float factor)
- \relates QVector2D
-
- Returns a copy of the given \a vector, multiplied by the given \a factor.
-
- \sa QVector2D::operator*=()
-*/
-
-/*!
- \fn const QVector2D operator*(const QVector2D &v1, const QVector2D &v2)
- \relates QVector2D
-
- Multiplies the components of \a v1 by the corresponding
- components in \a v2.
-*/
-
-/*!
- \fn const QVector2D operator-(const QVector2D &vector)
- \relates QVector2D
- \overload
-
- Returns a QVector2D object that is formed by changing the sign of
- the components of the given \a vector.
-
- Equivalent to \c {QVector2D(0,0) - vector}.
-*/
-
-/*!
- \fn const QVector2D operator/(const QVector2D &vector, float divisor)
- \relates QVector2D
-
- Returns the QVector2D object formed by dividing all three components of
- the given \a vector by the given \a divisor.
-
- \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
-
- Returns \c true if \a v1 and \a v2 are equal, allowing for a small
- fuzziness factor for floating-point comparisons; false otherwise.
-*/
-
-#ifndef QT_NO_VECTOR3D
-
-/*!
- Returns the 3D form of this 2D vector, with the z coordinate set to zero.
-
- \sa toVector4D(), toPoint()
-*/
-QVector3D QVector2D::toVector3D() const
-{
- return QVector3D(v[0], v[1], 0.0f);
-}
-
-#endif
-
-#ifndef QT_NO_VECTOR4D
-
-/*!
- Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
-
- \sa toVector3D(), toPoint()
-*/
-QVector4D QVector2D::toVector4D() const
-{
- return QVector4D(v[0], v[1], 0.0f, 0.0f);
-}
-
-#endif
-
-/*!
- \fn QPoint QVector2D::toPoint() const
-
- Returns the QPoint form of this 2D vector.
-
- \sa toPointF(), toVector3D()
-*/
-
-/*!
- \fn QPointF QVector2D::toPointF() const
-
- Returns the QPointF form of this 2D vector.
-
- \sa toPoint(), toVector3D()
-*/
-
-/*!
- Returns the 2D vector as a QVariant.
-*/
-QVector2D::operator QVariant() const
-{
- return QVariant::fromValue(*this);
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-
-QDebug operator<<(QDebug dbg, const QVector2D &vector)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace() << "QVector2D(" << vector.x() << ", " << vector.y() << ')';
- return dbg;
-}
-
-#endif
-
-#ifndef QT_NO_DATASTREAM
-
-/*!
- \fn QDataStream &operator<<(QDataStream &stream, const QVector2D &vector)
- \relates QVector2D
-
- Writes the given \a vector to the given \a stream and returns a
- reference to the stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator<<(QDataStream &stream, const QVector2D &vector)
-{
- stream << vector.x() << vector.y();
- return stream;
-}
-
-/*!
- \fn QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
- \relates QVector2D
-
- Reads a 2D vector from the given \a stream into the given \a vector
- and returns a reference to the stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
-{
- float x, y;
- stream >> x;
- stream >> y;
- vector.setX(x);
- vector.setY(y);
- return stream;
-}
-
-#endif // QT_NO_DATASTREAM
-
-#endif // QT_NO_VECTOR2D
-
-QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h
index 983f236f84..a9e55a8ef8 100644
--- a/src/gui/math3d/qvector2d.h
+++ b/src/gui/math3d/qvector2d.h
@@ -1,289 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#ifndef QVECTOR2D_H
-#define QVECTOR2D_H
-
-#include <QtGui/qtguiglobal.h>
-#include <QtCore/qpoint.h>
-#include <QtCore/qmetatype.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QVector3D;
-class QVector4D;
-class QVariant;
-
-#ifndef QT_NO_VECTOR2D
-
-class Q_GUI_EXPORT QVector2D
-{
-public:
- constexpr QVector2D();
- explicit QVector2D(Qt::Initialization) {}
- constexpr QVector2D(float xpos, float ypos);
- constexpr explicit QVector2D(const QPoint& point);
- constexpr explicit QVector2D(const QPointF& point);
-#ifndef QT_NO_VECTOR3D
- explicit QVector2D(const QVector3D& vector);
-#endif
-#ifndef QT_NO_VECTOR4D
- explicit QVector2D(const QVector4D& vector);
-#endif
-
- bool isNull() const;
-
- constexpr float x() const;
- constexpr float y() const;
-
- void setX(float x);
- void setY(float y);
-
- float &operator[](int i);
- float operator[](int i) const;
-
- float length() const;
- float lengthSquared() const; //In Qt 6 convert to inline and constexpr
-
- Q_REQUIRED_RESULT QVector2D normalized() const;
- void normalize();
-
- float distanceToPoint(const QVector2D &point) const;
- float distanceToLine(const QVector2D& point, const QVector2D& direction) const;
-
- QVector2D &operator+=(const QVector2D &vector);
- QVector2D &operator-=(const QVector2D &vector);
- 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
-
- constexpr friend inline bool operator==(const QVector2D &v1, const QVector2D &v2);
- constexpr friend inline bool operator!=(const QVector2D &v1, const QVector2D &v2);
- constexpr friend inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2);
- constexpr friend inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2);
- constexpr friend inline const QVector2D operator*(float factor, const QVector2D &vector);
- constexpr friend inline const QVector2D operator*(const QVector2D &vector, float factor);
- constexpr friend inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2);
- constexpr friend inline const QVector2D operator-(const QVector2D &vector);
- constexpr friend inline const QVector2D operator/(const QVector2D &vector, float divisor);
- constexpr friend inline const QVector2D operator/(const QVector2D &vector, const QVector2D &divisor);
-
- constexpr friend inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2);
-
-#ifndef QT_NO_VECTOR3D
- QVector3D toVector3D() const;
-#endif
-#ifndef QT_NO_VECTOR4D
- QVector4D toVector4D() const;
-#endif
-
- constexpr QPoint toPoint() const;
- constexpr QPointF toPointF() const;
-
- operator QVariant() const;
-
-private:
- float v[2];
-
- friend class QVector3D;
- friend class QVector4D;
-};
-
-Q_DECLARE_TYPEINFO(QVector2D, Q_PRIMITIVE_TYPE);
-
-constexpr inline QVector2D::QVector2D() : v{0.0f, 0.0f} {}
-
-constexpr inline QVector2D::QVector2D(float xpos, float ypos) : v{xpos, ypos} {}
-
-constexpr inline QVector2D::QVector2D(const QPoint& point) : v{float(point.x()), float(point.y())} {}
-
-constexpr inline QVector2D::QVector2D(const QPointF& point) : v{float(point.x()), float(point.y())} {}
-
-inline bool QVector2D::isNull() const
-{
- return qIsNull(v[0]) && qIsNull(v[1]);
-}
-
-constexpr inline float QVector2D::x() const { return v[0]; }
-constexpr inline float QVector2D::y() const { return v[1]; }
-
-inline void QVector2D::setX(float aX) { v[0] = aX; }
-inline void QVector2D::setY(float aY) { v[1] = aY; }
-
-inline float &QVector2D::operator[](int i)
-{
- Q_ASSERT(uint(i) < 2u);
- return v[i];
-}
-
-inline float QVector2D::operator[](int i) const
-{
- Q_ASSERT(uint(i) < 2u);
- return v[i];
-}
-
-inline QVector2D &QVector2D::operator+=(const QVector2D &vector)
-{
- v[0] += vector.v[0];
- v[1] += vector.v[1];
- return *this;
-}
-
-inline QVector2D &QVector2D::operator-=(const QVector2D &vector)
-{
- v[0] -= vector.v[0];
- v[1] -= vector.v[1];
- return *this;
-}
-
-inline QVector2D &QVector2D::operator*=(float factor)
-{
- v[0] *= factor;
- v[1] *= factor;
- return *this;
-}
-
-inline QVector2D &QVector2D::operator*=(const QVector2D &vector)
-{
- v[0] *= vector.v[0];
- v[1] *= vector.v[1];
- return *this;
-}
-
-inline QVector2D &QVector2D::operator/=(float divisor)
-{
- v[0] /= divisor;
- v[1] /= divisor;
- return *this;
-}
-
-inline QVector2D &QVector2D::operator/=(const QVector2D &vector)
-{
- v[0] /= vector.v[0];
- v[1] /= vector.v[1];
- return *this;
-}
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_FLOAT_COMPARE
-
-constexpr inline bool operator==(const QVector2D &v1, const QVector2D &v2)
-{
- return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1];
-}
-
-constexpr inline bool operator!=(const QVector2D &v1, const QVector2D &v2)
-{
- return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1];
-}
-QT_WARNING_POP
-
-constexpr inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2)
-{
- return QVector2D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1]);
-}
-
-constexpr inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2)
-{
- return QVector2D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1]);
-}
-
-constexpr inline const QVector2D operator*(float factor, const QVector2D &vector)
-{
- return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
-}
-
-constexpr inline const QVector2D operator*(const QVector2D &vector, float factor)
-{
- return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
-}
-
-constexpr inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2)
-{
- return QVector2D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1]);
-}
-
-constexpr inline const QVector2D operator-(const QVector2D &vector)
-{
- return QVector2D(-vector.v[0], -vector.v[1]);
-}
-
-constexpr inline const QVector2D operator/(const QVector2D &vector, float divisor)
-{
- return QVector2D(vector.v[0] / divisor, vector.v[1] / divisor);
-}
-
-constexpr inline const QVector2D operator/(const QVector2D &vector, const QVector2D &divisor)
-{
- return QVector2D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1]);
-}
-
-constexpr inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2)
-{
- return qFuzzyCompare(v1.v[0], v2.v[0]) && qFuzzyCompare(v1.v[1], v2.v[1]);
-}
-
-constexpr inline QPoint QVector2D::toPoint() const
-{
- return QPoint(qRound(v[0]), qRound(v[1]));
-}
-
-constexpr inline QPointF QVector2D::toPointF() const
-{
- return QPointF(qreal(v[0]), qreal(v[1]));
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector2D &vector);
-#endif
-
-#ifndef QT_NO_DATASTREAM
-Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QVector2D &);
-Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector2D &);
-#endif
-
-#endif
-
-QT_END_NAMESPACE
+#include <QtGui/qvectornd.h>
+#if 0
+#pragma qt_sync_stop_processing
#endif
diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp
deleted file mode 100644
index 906434aca2..0000000000
--- a/src/gui/math3d/qvector3d.cpp
+++ /dev/null
@@ -1,761 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvector3d.h"
-#include "qvector2d.h"
-#include "qvector4d.h"
-#include "qmatrix4x4.h"
-#include <QtCore/qdatastream.h>
-#include <QtCore/qmath.h>
-#include <QtCore/qvariant.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qrect.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_VECTOR3D
-
-static_assert(std::is_standard_layout<QVector3D>::value, "QVector3D is supposed to be standard layout");
-static_assert(sizeof(QVector3D) == sizeof(float) * 3, "QVector3D is not supposed to have padding at the end");
-
-/*!
- \class QVector3D
- \brief The QVector3D class represents a vector or vertex in 3D space.
- \since 4.6
- \ingroup painting-3D
- \inmodule QtGui
-
- Vectors are one of the main building blocks of 3D representation and
- drawing. They consist of three coordinates, traditionally called
- x, y, and z.
-
- The QVector3D class can also be used to represent vertices in 3D space.
- We therefore do not need to provide a separate vertex class.
-
- \sa QVector2D, QVector4D, QQuaternion
-*/
-
-/*!
- \fn QVector3D::QVector3D()
-
- Constructs a null vector, i.e. with coordinates (0, 0, 0).
-*/
-
-/*!
- \fn QVector3D::QVector3D(Qt::Initialization)
- \since 5.5
- \internal
-
- Constructs a vector without initializing the contents.
-*/
-
-/*!
- \fn QVector3D::QVector3D(float xpos, float ypos, float zpos)
-
- Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos).
-*/
-
-/*!
- \fn QVector3D::QVector3D(const QPoint& point)
-
- Constructs a vector with x and y coordinates from a 2D \a point, and a
- z coordinate of 0.
-*/
-
-/*!
- \fn QVector3D::QVector3D(const QPointF& point)
-
- Constructs a vector with x and y coordinates from a 2D \a point, and a
- z coordinate of 0.
-*/
-
-#ifndef QT_NO_VECTOR2D
-
-/*!
- Constructs a 3D vector from the specified 2D \a vector. The z
- coordinate is set to zero.
-
- \sa toVector2D()
-*/
-QVector3D::QVector3D(const QVector2D& vector)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = 0.0f;
-}
-
-/*!
- Constructs a 3D vector from the specified 2D \a vector. The z
- coordinate is set to \a zpos.
-
- \sa toVector2D()
-*/
-QVector3D::QVector3D(const QVector2D& vector, float zpos)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = zpos;
-}
-
-#endif
-
-#ifndef QT_NO_VECTOR4D
-
-/*!
- Constructs a 3D vector from the specified 4D \a vector. The w
- coordinate is dropped.
-
- \sa toVector4D()
-*/
-QVector3D::QVector3D(const QVector4D& vector)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = vector.v[2];
-}
-
-#endif
-
-/*!
- \fn bool QVector3D::isNull() const
-
- Returns \c true if the x, y, and z coordinates are set to 0.0,
- otherwise returns \c false.
-*/
-
-/*!
- \fn float QVector3D::x() const
-
- Returns the x coordinate of this point.
-
- \sa setX(), y(), z()
-*/
-
-/*!
- \fn float QVector3D::y() const
-
- Returns the y coordinate of this point.
-
- \sa setY(), x(), z()
-*/
-
-/*!
- \fn float QVector3D::z() const
-
- Returns the z coordinate of this point.
-
- \sa setZ(), x(), y()
-*/
-
-/*!
- \fn void QVector3D::setX(float x)
-
- Sets the x coordinate of this point to the given \a x coordinate.
-
- \sa x(), setY(), setZ()
-*/
-
-/*!
- \fn void QVector3D::setY(float y)
-
- Sets the y coordinate of this point to the given \a y coordinate.
-
- \sa y(), setX(), setZ()
-*/
-
-/*!
- \fn void QVector3D::setZ(float z)
-
- Sets the z coordinate of this point to the given \a z coordinate.
-
- \sa z(), setX(), setY()
-*/
-
-/*! \fn float &QVector3D::operator[](int i)
- \since 5.2
-
- Returns the component of the vector at index position \a i
- as a modifiable reference.
-
- \a i must be a valid index position in the vector (i.e., 0 <= \a i
- < 3).
-*/
-
-/*! \fn float QVector3D::operator[](int i) const
- \since 5.2
-
- Returns the component of the vector at index position \a i.
-
- \a i must be a valid index position in the vector (i.e., 0 <= \a i
- < 3).
-*/
-
-/*!
- Returns the normalized unit vector form of this vector.
-
- If this vector is null, then a null vector is returned. If the length
- of the vector is very close to 1, then the vector will be returned as-is.
- Otherwise the normalized form of the vector of length 1 will be returned.
-
- \sa length(), normalize()
-*/
-QVector3D QVector3D::normalized() const
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]) +
- double(v[2]) * double(v[2]);
- if (qFuzzyIsNull(len - 1.0f)) {
- return *this;
- } else if (!qFuzzyIsNull(len)) {
- double sqrtLen = std::sqrt(len);
- return QVector3D(float(double(v[0]) / sqrtLen),
- float(double(v[1]) / sqrtLen),
- float(double(v[2]) / sqrtLen));
- } else {
- return QVector3D();
- }
-}
-
-/*!
- Normalizes the currect vector in place. Nothing happens if this
- vector is a null vector or the length of the vector is very close to 1.
-
- \sa length(), normalized()
-*/
-void QVector3D::normalize()
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]) +
- double(v[2]) * double(v[2]);
- if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
- return;
-
- len = std::sqrt(len);
-
- v[0] = float(double(v[0]) / len);
- v[1] = float(double(v[1]) / len);
- v[2] = float(double(v[2]) / len);
-}
-
-/*!
- \fn QVector3D &QVector3D::operator+=(const QVector3D &vector)
-
- Adds the given \a vector to this vector and returns a reference to
- this vector.
-
- \sa operator-=()
-*/
-
-/*!
- \fn QVector3D &QVector3D::operator-=(const QVector3D &vector)
-
- Subtracts the given \a vector from this vector and returns a reference to
- this vector.
-
- \sa operator+=()
-*/
-
-/*!
- \fn QVector3D &QVector3D::operator*=(float factor)
-
- Multiplies this vector's coordinates by the given \a factor, and
- returns a reference to this vector.
-
- \sa operator/=()
-*/
-
-/*!
- \fn QVector3D &QVector3D::operator*=(const QVector3D& vector)
- \overload
-
- Multiplies the components of this vector by the corresponding
- components in \a vector.
-
- Note: this is not the same as the crossProduct() of this
- vector and \a vector.
-
- \sa crossProduct()
-*/
-
-/*!
- \fn QVector3D &QVector3D::operator/=(float divisor)
-
- Divides this vector's coordinates by the given \a divisor, and
- returns a reference to this vector.
-
- \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.
-*/
-float QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)
-{
- return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2];
-}
-
-/*!
- Returns the cross-product of vectors \a v1 and \a v2, which corresponds
- to the normal vector of a plane defined by \a v1 and \a v2.
-
- \sa normal()
-*/
-QVector3D QVector3D::crossProduct(const QVector3D& v1, const QVector3D& v2)
-{
- return QVector3D(v1.v[1] * v2.v[2] - v1.v[2] * v2.v[1],
- v1.v[2] * v2.v[0] - v1.v[0] * v2.v[2],
- v1.v[0] * v2.v[1] - v1.v[1] * v2.v[0]);
-}
-
-/*!
- Returns the normal vector of a plane defined by vectors \a v1 and \a v2,
- normalized to be a unit vector.
-
- Use crossProduct() to compute the cross-product of \a v1 and \a v2 if you
- do not need the result to be normalized to a unit vector.
-
- \sa crossProduct(), distanceToPlane()
-*/
-QVector3D QVector3D::normal(const QVector3D& v1, const QVector3D& v2)
-{
- return crossProduct(v1, v2).normalized();
-}
-
-/*!
- \overload
-
- Returns the normal vector of a plane defined by vectors
- \a v2 - \a v1 and \a v3 - \a v1, normalized to be a unit vector.
-
- Use crossProduct() to compute the cross-product of \a v2 - \a v1 and
- \a v3 - \a v1 if you do not need the result to be normalized to a
- unit vector.
-
- \sa crossProduct(), distanceToPlane()
-*/
-QVector3D QVector3D::normal
- (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3)
-{
- return crossProduct((v2 - v1), (v3 - v1)).normalized();
-}
-
-/*!
- \since 5.5
-
- Returns the window coordinates of this vector initially in object/model
- coordinates using the model view matrix \a modelView, the projection matrix
- \a projection and the viewport dimensions \a viewport.
-
- When transforming from clip to normalized space, a division by the w
- component on the vector components takes place. To prevent dividing by 0 if
- w equals to 0, it is set to 1.
-
- \note the returned y coordinates are in OpenGL orientation. OpenGL expects
- the bottom to be 0 whereas for Qt top is 0.
-
- \sa unproject()
- */
-QVector3D QVector3D::project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const
-{
- QVector4D tmp(*this, 1.0f);
- tmp = projection * modelView * tmp;
- if (qFuzzyIsNull(tmp.w()))
- tmp.setW(1.0f);
- tmp /= tmp.w();
-
- tmp = tmp * 0.5f + QVector4D(0.5f, 0.5f, 0.5f, 0.5f);
- tmp.setX(tmp.x() * viewport.width() + viewport.x());
- tmp.setY(tmp.y() * viewport.height() + viewport.y());
-
- return tmp.toVector3D();
-}
-
-/*!
- \since 5.5
-
- Returns the object/model coordinates of this vector initially in window
- coordinates using the model view matrix \a modelView, the projection matrix
- \a projection and the viewport dimensions \a viewport.
-
- When transforming from clip to normalized space, a division by the w
- component of the vector components takes place. To prevent dividing by 0 if
- w equals to 0, it is set to 1.
-
- \note y coordinates in \a viewport should use OpenGL orientation. OpenGL
- expects the bottom to be 0 whereas for Qt top is 0.
-
- \sa project()
- */
-QVector3D QVector3D::unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const
-{
- QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted();
-
- QVector4D tmp(*this, 1.0f);
- tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width()));
- tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height()));
- tmp = tmp * 2.0f - QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
-
- QVector4D obj = inverse * tmp;
- if (qFuzzyIsNull(obj.w()))
- obj.setW(1.0f);
- obj /= obj.w();
- return obj.toVector3D();
-}
-
-/*!
- \since 5.1
-
- Returns the distance from this vertex to a point defined by
- the vertex \a point.
-
- \sa distanceToPlane(), distanceToLine()
-*/
-float QVector3D::distanceToPoint(const QVector3D& point) const
-{
- return (*this - point).length();
-}
-
-/*!
- Returns the distance from this vertex to a plane defined by
- the vertex \a plane and a \a normal unit vector. The \a normal
- parameter is assumed to have been normalized to a unit vector.
-
- The return value will be negative if the vertex is below the plane,
- or zero if it is on the plane.
-
- \sa normal(), distanceToLine()
-*/
-float QVector3D::distanceToPlane
- (const QVector3D& plane, const QVector3D& normal) const
-{
- return dotProduct(*this - plane, normal);
-}
-
-/*!
- \overload
-
- Returns the distance from this vertex to a plane defined by
- the vertices \a plane1, \a plane2 and \a plane3.
-
- The return value will be negative if the vertex is below the plane,
- or zero if it is on the plane.
-
- The two vectors that define the plane are \a plane2 - \a plane1
- and \a plane3 - \a plane1.
-
- \sa normal(), distanceToLine()
-*/
-float QVector3D::distanceToPlane
- (const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const
-{
- QVector3D n = normal(plane2 - plane1, plane3 - plane1);
- return dotProduct(*this - plane1, n);
-}
-
-/*!
- Returns the distance that this vertex is from a line defined
- by \a point and the unit vector \a direction.
-
- If \a direction is a null vector, then it does not define a line.
- In that case, the distance from \a point to this vertex is returned.
-
- \sa distanceToPlane()
-*/
-float QVector3D::distanceToLine
- (const QVector3D& point, const QVector3D& direction) const
-{
- if (direction.isNull())
- return (*this - point).length();
- QVector3D p = point + dotProduct(*this - point, direction) * direction;
- return (*this - p).length();
-}
-
-/*!
- \fn bool operator==(const QVector3D &v1, const QVector3D &v2)
- \relates QVector3D
-
- Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
- This operator uses an exact floating-point comparison.
-*/
-
-/*!
- \fn bool operator!=(const QVector3D &v1, const QVector3D &v2)
- \relates QVector3D
-
- Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
- This operator uses an exact floating-point comparison.
-*/
-
-/*!
- \fn const QVector3D operator+(const QVector3D &v1, const QVector3D &v2)
- \relates QVector3D
-
- Returns a QVector3D object that is the sum of the given vectors, \a v1
- and \a v2; each component is added separately.
-
- \sa QVector3D::operator+=()
-*/
-
-/*!
- \fn const QVector3D operator-(const QVector3D &v1, const QVector3D &v2)
- \relates QVector3D
-
- Returns a QVector3D object that is formed by subtracting \a v2 from \a v1;
- each component is subtracted separately.
-
- \sa QVector3D::operator-=()
-*/
-
-/*!
- \fn const QVector3D operator*(float factor, const QVector3D &vector)
- \relates QVector3D
-
- Returns a copy of the given \a vector, multiplied by the given \a factor.
-
- \sa QVector3D::operator*=()
-*/
-
-/*!
- \fn const QVector3D operator*(const QVector3D &vector, float factor)
- \relates QVector3D
-
- Returns a copy of the given \a vector, multiplied by the given \a factor.
-
- \sa QVector3D::operator*=()
-*/
-
-/*!
- \fn const QVector3D operator*(const QVector3D &v1, const QVector3D& v2)
- \relates QVector3D
-
- Multiplies the components of \a v1 by the corresponding components in \a v2.
-
- Note: this is not the same as the crossProduct() of \a v1 and \a v2.
-
- \sa QVector3D::crossProduct()
-*/
-
-/*!
- \fn const QVector3D operator-(const QVector3D &vector)
- \relates QVector3D
- \overload
-
- Returns a QVector3D object that is formed by changing the sign of
- all three components of the given \a vector.
-
- Equivalent to \c {QVector3D(0,0,0) - vector}.
-*/
-
-/*!
- \fn const QVector3D operator/(const QVector3D &vector, float divisor)
- \relates QVector3D
-
- Returns the QVector3D object formed by dividing all three components of
- the given \a vector by the given \a divisor.
-
- \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
-
- Returns \c true if \a v1 and \a v2 are equal, allowing for a small
- fuzziness factor for floating-point comparisons; false otherwise.
-*/
-
-#ifndef QT_NO_VECTOR2D
-
-/*!
- Returns the 2D vector form of this 3D vector, dropping the z coordinate.
-
- \sa toVector4D(), toPoint()
-*/
-QVector2D QVector3D::toVector2D() const
-{
- return QVector2D(v[0], v[1]);
-}
-
-#endif
-
-#ifndef QT_NO_VECTOR4D
-
-/*!
- Returns the 4D form of this 3D vector, with the w coordinate set to zero.
-
- \sa toVector2D(), toPoint()
-*/
-QVector4D QVector3D::toVector4D() const
-{
- return QVector4D(v[0], v[1], v[2], 0.0f);
-}
-
-#endif
-
-/*!
- \fn QPoint QVector3D::toPoint() const
-
- Returns the QPoint form of this 3D vector. The z coordinate
- is dropped.
-
- \sa toPointF(), toVector2D()
-*/
-
-/*!
- \fn QPointF QVector3D::toPointF() const
-
- Returns the QPointF form of this 3D vector. The z coordinate
- is dropped.
-
- \sa toPoint(), toVector2D()
-*/
-
-/*!
- Returns the 3D vector as a QVariant.
-*/
-QVector3D::operator QVariant() const
-{
- return QVariant::fromValue(*this);
-}
-
-/*!
- Returns the length of the vector from the origin.
-
- \sa lengthSquared(), normalized()
-*/
-float QVector3D::length() const
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]) +
- double(v[2]) * double(v[2]);
- return float(std::sqrt(len));
-}
-
-/*!
- Returns the squared length of the vector from the origin.
- This is equivalent to the dot product of the vector with itself.
-
- \sa length(), dotProduct()
-*/
-float QVector3D::lengthSquared() const
-{
- return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-
-QDebug operator<<(QDebug dbg, const QVector3D &vector)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace() << "QVector3D("
- << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';
- return dbg;
-}
-
-#endif
-
-#ifndef QT_NO_DATASTREAM
-
-/*!
- \fn QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)
- \relates QVector3D
-
- Writes the given \a vector to the given \a stream and returns a
- reference to the stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)
-{
- stream << vector.x() << vector.y() << vector.z();
- return stream;
-}
-
-/*!
- \fn QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
- \relates QVector3D
-
- Reads a 3D vector from the given \a stream into the given \a vector
- and returns a reference to the stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
-{
- float x, y, z;
- stream >> x;
- stream >> y;
- stream >> z;
- vector.setX(x);
- vector.setY(y);
- vector.setZ(z);
- return stream;
-}
-
-#endif // QT_NO_DATASTREAM
-
-#endif // QT_NO_VECTOR3D
-
-QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h
index ecfdf82239..a9e55a8ef8 100644
--- a/src/gui/math3d/qvector3d.h
+++ b/src/gui/math3d/qvector3d.h
@@ -1,316 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#ifndef QVECTOR3D_H
-#define QVECTOR3D_H
-
-#include <QtGui/qtguiglobal.h>
-#include <QtCore/qpoint.h>
-#include <QtCore/qmetatype.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMatrix4x4;
-class QVector2D;
-class QVector4D;
-class QRect;
-
-#ifndef QT_NO_VECTOR3D
-
-class Q_GUI_EXPORT QVector3D
-{
-public:
- constexpr QVector3D();
- explicit QVector3D(Qt::Initialization) {}
- constexpr QVector3D(float xpos, float ypos, float zpos) : v{xpos, ypos, zpos} {}
-
- constexpr explicit QVector3D(const QPoint& point);
- constexpr explicit QVector3D(const QPointF& point);
-#ifndef QT_NO_VECTOR2D
- QVector3D(const QVector2D& vector);
- QVector3D(const QVector2D& vector, float zpos);
-#endif
-#ifndef QT_NO_VECTOR4D
- explicit QVector3D(const QVector4D& vector);
-#endif
-
- bool isNull() const;
-
- constexpr float x() const;
- constexpr float y() const;
- constexpr float z() const;
-
- void setX(float x);
- void setY(float y);
- void setZ(float z);
-
- float &operator[](int i);
- float operator[](int i) const;
-
- float length() const;
- float lengthSquared() const;
-
- QVector3D normalized() const;
- void normalize();
-
- QVector3D &operator+=(const QVector3D &vector);
- QVector3D &operator-=(const QVector3D &vector);
- 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
-
- static QVector3D normal(const QVector3D& v1, const QVector3D& v2);
- static QVector3D normal
- (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3);
-
- QVector3D project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const;
- QVector3D unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const;
-
- float distanceToPoint(const QVector3D& point) const;
- float distanceToPlane(const QVector3D& plane, const QVector3D& normal) const;
- float distanceToPlane(const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const;
- float distanceToLine(const QVector3D& point, const QVector3D& direction) const;
-
- constexpr friend inline bool operator==(const QVector3D &v1, const QVector3D &v2);
- constexpr friend inline bool operator!=(const QVector3D &v1, const QVector3D &v2);
- constexpr friend inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2);
- constexpr friend inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2);
- constexpr friend inline const QVector3D operator*(float factor, const QVector3D &vector);
- constexpr friend inline const QVector3D operator*(const QVector3D &vector, float factor);
- constexpr friend const QVector3D operator*(const QVector3D &v1, const QVector3D& v2);
- constexpr friend inline const QVector3D operator-(const QVector3D &vector);
- constexpr friend inline const QVector3D operator/(const QVector3D &vector, float divisor);
- constexpr friend inline const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor);
-
- constexpr friend inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2);
-
-#ifndef QT_NO_VECTOR2D
- QVector2D toVector2D() const;
-#endif
-#ifndef QT_NO_VECTOR4D
- QVector4D toVector4D() const;
-#endif
-
- constexpr QPoint toPoint() const;
- constexpr QPointF toPointF() const;
-
- operator QVariant() const;
-
-private:
- float v[3];
-
- friend class QVector2D;
- friend class QVector4D;
-#ifndef QT_NO_MATRIX4X4
- friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
- friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
-#endif
-};
-
-Q_DECLARE_TYPEINFO(QVector3D, Q_PRIMITIVE_TYPE);
-
-constexpr inline QVector3D::QVector3D() : v{0.0f, 0.0f, 0.0f} {}
-
-constexpr inline QVector3D::QVector3D(const QPoint& point) : v{float(point.x()), float(point.y()), float(0.0f)} {}
-
-constexpr inline QVector3D::QVector3D(const QPointF& point) : v{float(point.x()), float(point.y()), 0.0f} {}
-
-inline bool QVector3D::isNull() const
-{
- return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]);
-}
-
-constexpr inline float QVector3D::x() const { return v[0]; }
-constexpr inline float QVector3D::y() const { return v[1]; }
-constexpr inline float QVector3D::z() const { return v[2]; }
-
-inline void QVector3D::setX(float aX) { v[0] = aX; }
-inline void QVector3D::setY(float aY) { v[1] = aY; }
-inline void QVector3D::setZ(float aZ) { v[2] = aZ; }
-
-inline float &QVector3D::operator[](int i)
-{
- Q_ASSERT(uint(i) < 3u);
- return v[i];
-}
-
-inline float QVector3D::operator[](int i) const
-{
- Q_ASSERT(uint(i) < 3u);
- return v[i];
-}
-
-inline QVector3D &QVector3D::operator+=(const QVector3D &vector)
-{
- v[0] += vector.v[0];
- v[1] += vector.v[1];
- v[2] += vector.v[2];
- return *this;
-}
-
-inline QVector3D &QVector3D::operator-=(const QVector3D &vector)
-{
- v[0] -= vector.v[0];
- v[1] -= vector.v[1];
- v[2] -= vector.v[2];
- return *this;
-}
-
-inline QVector3D &QVector3D::operator*=(float factor)
-{
- v[0] *= factor;
- v[1] *= factor;
- v[2] *= factor;
- return *this;
-}
-
-inline QVector3D &QVector3D::operator*=(const QVector3D& vector)
-{
- v[0] *= vector.v[0];
- v[1] *= vector.v[1];
- v[2] *= vector.v[2];
- return *this;
-}
-
-inline QVector3D &QVector3D::operator/=(float divisor)
-{
- v[0] /= divisor;
- v[1] /= divisor;
- v[2] /= divisor;
- return *this;
-}
-
-inline QVector3D &QVector3D::operator/=(const QVector3D &vector)
-{
- v[0] /= vector.v[0];
- v[1] /= vector.v[1];
- v[2] /= vector.v[2];
- return *this;
-}
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_FLOAT_COMPARE
-
-constexpr inline bool operator==(const QVector3D &v1, const QVector3D &v2)
-{
- return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2];
-}
-
-constexpr inline bool operator!=(const QVector3D &v1, const QVector3D &v2)
-{
- return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2];
-}
-QT_WARNING_POP
-
-constexpr inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2)
-{
- return QVector3D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2]);
-}
-
-constexpr inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2)
-{
- return QVector3D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2]);
-}
-
-constexpr inline const QVector3D operator*(float factor, const QVector3D &vector)
-{
- return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
-}
-
-constexpr inline const QVector3D operator*(const QVector3D &vector, float factor)
-{
- return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
-}
-
-constexpr inline const QVector3D operator*(const QVector3D &v1, const QVector3D& v2)
-{
- return QVector3D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2]);
-}
-
-constexpr inline const QVector3D operator-(const QVector3D &vector)
-{
- return QVector3D(-vector.v[0], -vector.v[1], -vector.v[2]);
-}
-
-constexpr inline const QVector3D operator/(const QVector3D &vector, float divisor)
-{
- return QVector3D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor);
-}
-
-constexpr inline const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor)
-{
- return QVector3D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1], vector.v[2] / divisor.v[2]);
-}
-
-constexpr inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)
-{
- return qFuzzyCompare(v1.v[0], v2.v[0]) &&
- qFuzzyCompare(v1.v[1], v2.v[1]) &&
- qFuzzyCompare(v1.v[2], v2.v[2]);
-}
-
-constexpr inline QPoint QVector3D::toPoint() const
-{
- return QPoint(qRound(v[0]), qRound(v[1]));
-}
-
-constexpr inline QPointF QVector3D::toPointF() const
-{
- return QPointF(qreal(v[0]), qreal(v[1]));
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector3D &vector);
-#endif
-
-#ifndef QT_NO_DATASTREAM
-Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QVector3D &);
-Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector3D &);
-#endif
-
-#endif
-
-QT_END_NAMESPACE
+#include <QtGui/qvectornd.h>
+#if 0
+#pragma qt_sync_stop_processing
#endif
diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp
deleted file mode 100644
index cf0c033e86..0000000000
--- a/src/gui/math3d/qvector4d.cpp
+++ /dev/null
@@ -1,641 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvector4d.h"
-#include "qvector3d.h"
-#include "qvector2d.h"
-#include <QtCore/qdatastream.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qvariant.h>
-#include <QtCore/qmath.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_VECTOR4D
-
-static_assert(std::is_standard_layout<QVector4D>::value, "QVector4D is supposed to be standard layout");
-static_assert(sizeof(QVector4D) == sizeof(float) * 4, "QVector4D is not supposed to have padding at the end");
-
-/*!
- \class QVector4D
- \brief The QVector4D class represents a vector or vertex in 4D space.
- \since 4.6
- \ingroup painting-3D
- \inmodule QtGui
-
- The QVector4D class can also be used to represent vertices in 4D space.
- We therefore do not need to provide a separate vertex class.
-
- \sa QQuaternion, QVector2D, QVector3D
-*/
-
-/*!
- \fn QVector4D::QVector4D()
-
- Constructs a null vector, i.e. with coordinates (0, 0, 0, 0).
-*/
-
-/*!
- \fn QVector4D::QVector4D(Qt::Initialization)
- \since 5.5
- \internal
-
- Constructs a vector without initializing the contents.
-*/
-
-/*!
- \fn QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos)
-
- Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos, \a wpos).
-*/
-
-/*!
- \fn QVector4D::QVector4D(const QPoint& point)
-
- Constructs a vector with x and y coordinates from a 2D \a point, and
- z and w coordinates of 0.
-*/
-
-/*!
- \fn QVector4D::QVector4D(const QPointF& point)
-
- Constructs a vector with x and y coordinates from a 2D \a point, and
- z and w coordinates of 0.
-*/
-
-#ifndef QT_NO_VECTOR2D
-
-/*!
- Constructs a 4D vector from the specified 2D \a vector. The z
- and w coordinates are set to zero.
-
- \sa toVector2D()
-*/
-QVector4D::QVector4D(const QVector2D& vector)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = 0.0f;
- v[3] = 0.0f;
-}
-
-/*!
- Constructs a 4D vector from the specified 2D \a vector. The z
- and w coordinates are set to \a zpos and \a wpos respectively.
-
- \sa toVector2D()
-*/
-QVector4D::QVector4D(const QVector2D& vector, float zpos, float wpos)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = zpos;
- v[3] = wpos;
-}
-
-#endif
-
-#ifndef QT_NO_VECTOR3D
-
-/*!
- Constructs a 4D vector from the specified 3D \a vector. The w
- coordinate is set to zero.
-
- \sa toVector3D()
-*/
-QVector4D::QVector4D(const QVector3D& vector)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = vector.v[2];
- v[3] = 0.0f;
-}
-
-/*!
- Constructs a 4D vector from the specified 3D \a vector. The w
- coordinate is set to \a wpos.
-
- \sa toVector3D()
-*/
-QVector4D::QVector4D(const QVector3D& vector, float wpos)
-{
- v[0] = vector.v[0];
- v[1] = vector.v[1];
- v[2] = vector.v[2];
- v[3] = wpos;
-}
-
-#endif
-
-/*!
- \fn bool QVector4D::isNull() const
-
- Returns \c true if the x, y, z, and w coordinates are set to 0.0,
- otherwise returns \c false.
-*/
-
-/*!
- \fn float QVector4D::x() const
-
- Returns the x coordinate of this point.
-
- \sa setX(), y(), z(), w()
-*/
-
-/*!
- \fn float QVector4D::y() const
-
- Returns the y coordinate of this point.
-
- \sa setY(), x(), z(), w()
-*/
-
-/*!
- \fn float QVector4D::z() const
-
- Returns the z coordinate of this point.
-
- \sa setZ(), x(), y(), w()
-*/
-
-/*!
- \fn float QVector4D::w() const
-
- Returns the w coordinate of this point.
-
- \sa setW(), x(), y(), z()
-*/
-
-/*!
- \fn void QVector4D::setX(float x)
-
- Sets the x coordinate of this point to the given \a x coordinate.
-
- \sa x(), setY(), setZ(), setW()
-*/
-
-/*!
- \fn void QVector4D::setY(float y)
-
- Sets the y coordinate of this point to the given \a y coordinate.
-
- \sa y(), setX(), setZ(), setW()
-*/
-
-/*!
- \fn void QVector4D::setZ(float z)
-
- Sets the z coordinate of this point to the given \a z coordinate.
-
- \sa z(), setX(), setY(), setW()
-*/
-
-/*!
- \fn void QVector4D::setW(float w)
-
- Sets the w coordinate of this point to the given \a w coordinate.
-
- \sa w(), setX(), setY(), setZ()
-*/
-
-/*! \fn float &QVector4D::operator[](int i)
- \since 5.2
-
- Returns the component of the vector at index position \a i
- as a modifiable reference.
-
- \a i must be a valid index position in the vector (i.e., 0 <= \a i
- < 4).
-*/
-
-/*! \fn float QVector4D::operator[](int i) const
- \since 5.2
-
- Returns the component of the vector at index position \a i.
-
- \a i must be a valid index position in the vector (i.e., 0 <= \a i
- < 4).
-*/
-
-/*!
- Returns the length of the vector from the origin.
-
- \sa lengthSquared(), normalized()
-*/
-float QVector4D::length() const
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]) +
- double(v[2]) * double(v[2]) +
- double(v[3]) * double(v[3]);
- return float(std::sqrt(len));
-}
-
-/*!
- Returns the squared length of the vector from the origin.
- This is equivalent to the dot product of the vector with itself.
-
- \sa length(), dotProduct()
-*/
-float QVector4D::lengthSquared() const
-{
- return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
-}
-
-/*!
- Returns the normalized unit vector form of this vector.
-
- If this vector is null, then a null vector is returned. If the length
- of the vector is very close to 1, then the vector will be returned as-is.
- Otherwise the normalized form of the vector of length 1 will be returned.
-
- \sa length(), normalize()
-*/
-QVector4D QVector4D::normalized() const
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]) +
- double(v[2]) * double(v[2]) +
- double(v[3]) * double(v[3]);
- if (qFuzzyIsNull(len - 1.0f)) {
- return *this;
- } else if (!qFuzzyIsNull(len)) {
- double sqrtLen = std::sqrt(len);
- return QVector4D(float(double(v[0]) / sqrtLen),
- float(double(v[1]) / sqrtLen),
- float(double(v[2]) / sqrtLen),
- float(double(v[3]) / sqrtLen));
- } else {
- return QVector4D();
- }
-}
-
-/*!
- Normalizes the currect vector in place. Nothing happens if this
- vector is a null vector or the length of the vector is very close to 1.
-
- \sa length(), normalized()
-*/
-void QVector4D::normalize()
-{
- // Need some extra precision if the length is very small.
- double len = double(v[0]) * double(v[0]) +
- double(v[1]) * double(v[1]) +
- double(v[2]) * double(v[2]) +
- double(v[3]) * double(v[3]);
- if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
- return;
-
- len = std::sqrt(len);
-
- v[0] = float(double(v[0]) / len);
- v[1] = float(double(v[1]) / len);
- v[2] = float(double(v[2]) / len);
- v[3] = float(double(v[3]) / len);
-}
-
-/*!
- \fn QVector4D &QVector4D::operator+=(const QVector4D &vector)
-
- Adds the given \a vector to this vector and returns a reference to
- this vector.
-
- \sa operator-=()
-*/
-
-/*!
- \fn QVector4D &QVector4D::operator-=(const QVector4D &vector)
-
- Subtracts the given \a vector from this vector and returns a reference to
- this vector.
-
- \sa operator+=()
-*/
-
-/*!
- \fn QVector4D &QVector4D::operator*=(float factor)
-
- Multiplies this vector's coordinates by the given \a factor, and
- returns a reference to this vector.
-
- \sa operator/=()
-*/
-
-/*!
- \fn QVector4D &QVector4D::operator*=(const QVector4D &vector)
-
- Multiplies the components of this vector by the corresponding
- components in \a vector.
-*/
-
-/*!
- \fn QVector4D &QVector4D::operator/=(float divisor)
-
- Divides this vector's coordinates by the given \a divisor, and
- returns a reference to this vector.
-
- \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.
-*/
-float QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
-{
- return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2] + v1.v[3] * v2.v[3];
-}
-
-/*!
- \fn bool operator==(const QVector4D &v1, const QVector4D &v2)
- \relates QVector4D
-
- Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
- This operator uses an exact floating-point comparison.
-*/
-
-/*!
- \fn bool operator!=(const QVector4D &v1, const QVector4D &v2)
- \relates QVector4D
-
- Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
- This operator uses an exact floating-point comparison.
-*/
-
-/*!
- \fn const QVector4D operator+(const QVector4D &v1, const QVector4D &v2)
- \relates QVector4D
-
- Returns a QVector4D object that is the sum of the given vectors, \a v1
- and \a v2; each component is added separately.
-
- \sa QVector4D::operator+=()
-*/
-
-/*!
- \fn const QVector4D operator-(const QVector4D &v1, const QVector4D &v2)
- \relates QVector4D
-
- Returns a QVector4D object that is formed by subtracting \a v2 from \a v1;
- each component is subtracted separately.
-
- \sa QVector4D::operator-=()
-*/
-
-/*!
- \fn const QVector4D operator*(float factor, const QVector4D &vector)
- \relates QVector4D
-
- Returns a copy of the given \a vector, multiplied by the given \a factor.
-
- \sa QVector4D::operator*=()
-*/
-
-/*!
- \fn const QVector4D operator*(const QVector4D &vector, float factor)
- \relates QVector4D
-
- Returns a copy of the given \a vector, multiplied by the given \a factor.
-
- \sa QVector4D::operator*=()
-*/
-
-/*!
- \fn const QVector4D operator*(const QVector4D &v1, const QVector4D& v2)
- \relates QVector4D
-
- Returns the vector consisting of the multiplication of the
- components from \a v1 and \a v2.
-
- \sa QVector4D::operator*=()
-*/
-
-/*!
- \fn const QVector4D operator-(const QVector4D &vector)
- \relates QVector4D
- \overload
-
- Returns a QVector4D object that is formed by changing the sign of
- all three components of the given \a vector.
-
- Equivalent to \c {QVector4D(0,0,0,0) - vector}.
-*/
-
-/*!
- \fn const QVector4D operator/(const QVector4D &vector, float divisor)
- \relates QVector4D
-
- Returns the QVector4D object formed by dividing all four components of
- the given \a vector by the given \a divisor.
-
- \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
-
- Returns \c true if \a v1 and \a v2 are equal, allowing for a small
- fuzziness factor for floating-point comparisons; false otherwise.
-*/
-
-#ifndef QT_NO_VECTOR2D
-
-/*!
- Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
-
- \sa toVector2DAffine(), toVector3D(), toPoint()
-*/
-QVector2D QVector4D::toVector2D() const
-{
- return QVector2D(v[0], v[1]);
-}
-
-/*!
- Returns the 2D vector form of this 4D vector, dividing the x and y
- coordinates by the w coordinate and dropping the z coordinate.
- Returns a null vector if w is zero.
-
- \sa toVector2D(), toVector3DAffine(), toPoint()
-*/
-QVector2D QVector4D::toVector2DAffine() const
-{
- if (qIsNull(v[3]))
- return QVector2D();
- return QVector2D(v[0] / v[3], v[1] / v[3]);
-}
-
-#endif
-
-#ifndef QT_NO_VECTOR3D
-
-/*!
- Returns the 3D vector form of this 4D vector, dropping the w coordinate.
-
- \sa toVector3DAffine(), toVector2D(), toPoint()
-*/
-QVector3D QVector4D::toVector3D() const
-{
- return QVector3D(v[0], v[1], v[2]);
-}
-
-/*!
- Returns the 3D vector form of this 4D vector, dividing the x, y, and
- z coordinates by the w coordinate. Returns a null vector if w is zero.
-
- \sa toVector3D(), toVector2DAffine(), toPoint()
-*/
-QVector3D QVector4D::toVector3DAffine() const
-{
- if (qIsNull(v[3]))
- return QVector3D();
- return QVector3D(v[0] / v[3], v[1] / v[3], v[2] / v[3]);
-}
-
-#endif
-
-/*!
- \fn QPoint QVector4D::toPoint() const
-
- Returns the QPoint form of this 4D vector. The z and w coordinates
- are dropped.
-
- \sa toPointF(), toVector2D()
-*/
-
-/*!
- \fn QPointF QVector4D::toPointF() const
-
- Returns the QPointF form of this 4D vector. The z and w coordinates
- are dropped.
-
- \sa toPoint(), toVector2D()
-*/
-
-/*!
- Returns the 4D vector as a QVariant.
-*/
-QVector4D::operator QVariant() const
-{
- return QVariant::fromValue(*this);
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-
-QDebug operator<<(QDebug dbg, const QVector4D &vector)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace() << "QVector4D("
- << vector.x() << ", " << vector.y() << ", "
- << vector.z() << ", " << vector.w() << ')';
- return dbg;
-}
-
-#endif
-
-#ifndef QT_NO_DATASTREAM
-
-/*!
- \fn QDataStream &operator<<(QDataStream &stream, const QVector4D &vector)
- \relates QVector4D
-
- Writes the given \a vector to the given \a stream and returns a
- reference to the stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator<<(QDataStream &stream, const QVector4D &vector)
-{
- stream << vector.x() << vector.y()
- << vector.z() << vector.w();
- return stream;
-}
-
-/*!
- \fn QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
- \relates QVector4D
-
- Reads a 4D vector from the given \a stream into the given \a vector
- and returns a reference to the stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
-{
- float x, y, z, w;
- stream >> x;
- stream >> y;
- stream >> z;
- stream >> w;
- vector.setX(x);
- vector.setY(y);
- vector.setZ(z);
- vector.setW(w);
- return stream;
-}
-
-#endif // QT_NO_DATASTREAM
-
-#endif // QT_NO_VECTOR4D
-
-QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h
index 6f6ec213b9..a9e55a8ef8 100644
--- a/src/gui/math3d/qvector4d.h
+++ b/src/gui/math3d/qvector4d.h
@@ -1,317 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#ifndef QVECTOR4D_H
-#define QVECTOR4D_H
-
-#include <QtGui/qtguiglobal.h>
-#include <QtCore/qpoint.h>
-#include <QtCore/qmetatype.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMatrix4x4;
-class QVector2D;
-class QVector3D;
-
-#ifndef QT_NO_VECTOR4D
-
-class Q_GUI_EXPORT QVector4D
-{
-public:
- constexpr QVector4D();
- explicit QVector4D(Qt::Initialization) {}
- constexpr QVector4D(float xpos, float ypos, float zpos, float wpos);
- constexpr explicit QVector4D(const QPoint& point);
- constexpr explicit QVector4D(const QPointF& point);
-#ifndef QT_NO_VECTOR2D
- QVector4D(const QVector2D& vector);
- QVector4D(const QVector2D& vector, float zpos, float wpos);
-#endif
-#ifndef QT_NO_VECTOR3D
- QVector4D(const QVector3D& vector);
- QVector4D(const QVector3D& vector, float wpos);
-#endif
-
- bool isNull() const;
-
- constexpr float x() const;
- constexpr float y() const;
- constexpr float z() const;
- constexpr float w() const;
-
- void setX(float x);
- void setY(float y);
- void setZ(float z);
- void setW(float w);
-
- float &operator[](int i);
- float operator[](int i) const;
-
- float length() const;
- float lengthSquared() const; //In Qt 6 convert to inline and constexpr
-
- Q_REQUIRED_RESULT QVector4D normalized() const;
- void normalize();
-
- QVector4D &operator+=(const QVector4D &vector);
- QVector4D &operator-=(const QVector4D &vector);
- 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
-
- constexpr friend inline bool operator==(const QVector4D &v1, const QVector4D &v2);
- constexpr friend inline bool operator!=(const QVector4D &v1, const QVector4D &v2);
- constexpr friend inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2);
- constexpr friend inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2);
- constexpr friend inline const QVector4D operator*(float factor, const QVector4D &vector);
- constexpr friend inline const QVector4D operator*(const QVector4D &vector, float factor);
- constexpr friend inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2);
- constexpr friend inline const QVector4D operator-(const QVector4D &vector);
- constexpr friend inline const QVector4D operator/(const QVector4D &vector, float divisor);
- constexpr friend inline const QVector4D operator/(const QVector4D &vector, const QVector4D &divisor);
-
- constexpr friend inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2);
-
-#ifndef QT_NO_VECTOR2D
- QVector2D toVector2D() const;
- QVector2D toVector2DAffine() const;
-#endif
-#ifndef QT_NO_VECTOR3D
- QVector3D toVector3D() const;
- QVector3D toVector3DAffine() const;
-#endif
-
- constexpr QPoint toPoint() const;
- constexpr QPointF toPointF() const;
-
- operator QVariant() const;
-
-private:
- float v[4];
-
- friend class QVector2D;
- friend class QVector3D;
-#ifndef QT_NO_MATRIX4X4
- friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
- friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
-#endif
-};
-
-Q_DECLARE_TYPEINFO(QVector4D, Q_PRIMITIVE_TYPE);
-
-constexpr inline QVector4D::QVector4D() : v{0.0f, 0.0f, 0.0f, 0.0f} {}
-
-constexpr inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos) : v{xpos, ypos, zpos, wpos} {}
-
-constexpr inline QVector4D::QVector4D(const QPoint& point) : v{float(point.x()), float(point.y()), 0.0f, 0.0f} {}
-
-constexpr inline QVector4D::QVector4D(const QPointF& point) : v{float(point.x()), float(point.y()), 0.0f, 0.0f} {}
-
-inline bool QVector4D::isNull() const
-{
- return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]) && qIsNull(v[3]);
-}
-
-constexpr inline float QVector4D::x() const { return v[0]; }
-constexpr inline float QVector4D::y() const { return v[1]; }
-constexpr inline float QVector4D::z() const { return v[2]; }
-constexpr inline float QVector4D::w() const { return v[3]; }
-
-inline void QVector4D::setX(float aX) { v[0] = aX; }
-inline void QVector4D::setY(float aY) { v[1] = aY; }
-inline void QVector4D::setZ(float aZ) { v[2] = aZ; }
-inline void QVector4D::setW(float aW) { v[3] = aW; }
-
-inline float &QVector4D::operator[](int i)
-{
- Q_ASSERT(uint(i) < 4u);
- return v[i];
-}
-
-inline float QVector4D::operator[](int i) const
-{
- Q_ASSERT(uint(i) < 4u);
- return v[i];
-}
-
-inline QVector4D &QVector4D::operator+=(const QVector4D &vector)
-{
- v[0] += vector.v[0];
- v[1] += vector.v[1];
- v[2] += vector.v[2];
- v[3] += vector.v[3];
- return *this;
-}
-
-inline QVector4D &QVector4D::operator-=(const QVector4D &vector)
-{
- v[0] -= vector.v[0];
- v[1] -= vector.v[1];
- v[2] -= vector.v[2];
- v[3] -= vector.v[3];
- return *this;
-}
-
-inline QVector4D &QVector4D::operator*=(float factor)
-{
- v[0] *= factor;
- v[1] *= factor;
- v[2] *= factor;
- v[3] *= factor;
- return *this;
-}
-
-inline QVector4D &QVector4D::operator*=(const QVector4D &vector)
-{
- v[0] *= vector.v[0];
- v[1] *= vector.v[1];
- v[2] *= vector.v[2];
- v[3] *= vector.v[3];
- return *this;
-}
-
-inline QVector4D &QVector4D::operator/=(float divisor)
-{
- v[0] /= divisor;
- v[1] /= divisor;
- v[2] /= divisor;
- v[3] /= divisor;
- return *this;
-}
-
-inline QVector4D &QVector4D::operator/=(const QVector4D &vector)
-{
- v[0] /= vector.v[0];
- v[1] /= vector.v[1];
- v[2] /= vector.v[2];
- v[3] /= vector.v[3];
- return *this;
-}
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_FLOAT_COMPARE
-
-constexpr inline bool operator==(const QVector4D &v1, const QVector4D &v2)
-{
- return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2] && v1.v[3] == v2.v[3];
-}
-
-constexpr inline bool operator!=(const QVector4D &v1, const QVector4D &v2)
-{
- return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2] || v1.v[3] != v2.v[3];
-}
-QT_WARNING_POP
-
-constexpr inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2)
-{
- return QVector4D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2], v1.v[3] + v2.v[3]);
-}
-
-constexpr inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2)
-{
- return QVector4D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2], v1.v[3] - v2.v[3]);
-}
-
-constexpr inline const QVector4D operator*(float factor, const QVector4D &vector)
-{
- return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
-}
-
-constexpr inline const QVector4D operator*(const QVector4D &vector, float factor)
-{
- return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
-}
-
-constexpr inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2)
-{
- return QVector4D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2], v1.v[3] * v2.v[3]);
-}
-
-constexpr inline const QVector4D operator-(const QVector4D &vector)
-{
- return QVector4D(-vector.v[0], -vector.v[1], -vector.v[2], -vector.v[3]);
-}
-
-constexpr inline const QVector4D operator/(const QVector4D &vector, float divisor)
-{
- return QVector4D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor, vector.v[3] / divisor);
-}
-
-constexpr inline const QVector4D operator/(const QVector4D &vector, const QVector4D &divisor)
-{
- return QVector4D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1], vector.v[2] / divisor.v[2], vector.v[3] / divisor.v[3]);
-}
-
-constexpr inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2)
-{
- return qFuzzyCompare(v1.v[0], v2.v[0]) &&
- qFuzzyCompare(v1.v[1], v2.v[1]) &&
- qFuzzyCompare(v1.v[2], v2.v[2]) &&
- qFuzzyCompare(v1.v[3], v2.v[3]);
-}
-
-constexpr inline QPoint QVector4D::toPoint() const
-{
- return QPoint(qRound(v[0]), qRound(v[1]));
-}
-
-constexpr inline QPointF QVector4D::toPointF() const
-{
- return QPointF(qreal(v[0]), qreal(v[1]));
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector4D &vector);
-#endif
-
-#ifndef QT_NO_DATASTREAM
-Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QVector4D &);
-Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector4D &);
-#endif
-
-#endif
-
-QT_END_NAMESPACE
+#include <QtGui/qvectornd.h>
+#if 0
+#pragma qt_sync_stop_processing
#endif
diff --git a/src/gui/math3d/qvectornd.cpp b/src/gui/math3d/qvectornd.cpp
new file mode 100644
index 0000000000..dcd7bdbcf8
--- /dev/null
+++ b/src/gui/math3d/qvectornd.cpp
@@ -0,0 +1,1642 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvectornd.h"
+#include <QtCore/qdatastream.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qvariant.h>
+#include <QtGui/qmatrix4x4.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ \class QVector2D
+ \brief The QVector2D class represents a vector or vertex in 2D space.
+ \since 4.6
+ \ingroup painting
+ \ingroup painting-3D
+ \inmodule QtGui
+
+ Vectors are one of the main building blocks of 2D representation and
+ drawing. They consist of two finite floating-point coordinates,
+ traditionally called x and y.
+
+ The QVector2D class can also be used to represent vertices in 2D space.
+ We therefore do not need to provide a separate vertex class.
+
+ \sa QVector3D, QVector4D, QQuaternion
+*/
+
+/*!
+ \fn QVector2D::QVector2D()
+
+ Constructs a null vector, i.e. with coordinates (0, 0).
+*/
+
+/*!
+ \fn QVector2D::QVector2D(Qt::Initialization)
+ \since 5.5
+ \internal
+
+ Constructs a vector without initializing the contents.
+*/
+
+/*!
+ \fn QVector2D::QVector2D(float xpos, float ypos)
+
+ Constructs a vector with coordinates (\a xpos, \a ypos).
+ Both coordinates must be finite.
+*/
+
+/*!
+ \fn QVector2D::QVector2D(QPoint point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point.
+*/
+
+/*!
+ \fn QVector2D::QVector2D(QPointF point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point.
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \fn QVector2D::QVector2D(QVector3D vector)
+
+ Constructs a vector with x and y coordinates from a 3D \a vector.
+ The z coordinate of \a vector is dropped.
+
+ \sa toVector3D()
+*/
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \fn QVector2D::QVector2D(QVector4D vector)
+
+ Constructs a vector with x and y coordinates from a 3D \a vector.
+ The z and w coordinates of \a vector are dropped.
+
+ \sa toVector4D()
+*/
+
+#endif
+
+/*!
+ \fn bool QVector2D::isNull() const
+
+ Returns \c true if the x and y coordinates are set to 0.0,
+ otherwise returns \c false.
+*/
+
+/*!
+ \fn float QVector2D::x() const
+
+ Returns the x coordinate of this point.
+
+ \sa setX(), y()
+*/
+
+/*!
+ \fn float QVector2D::y() const
+
+ Returns the y coordinate of this point.
+
+ \sa setY(), x()
+*/
+
+/*!
+ \fn void QVector2D::setX(float x)
+
+ Sets the x coordinate of this point to the given finite \a x coordinate.
+
+ \sa x(), setY()
+*/
+
+/*!
+ \fn void QVector2D::setY(float y)
+
+ Sets the y coordinate of this point to the given finite \a y coordinate.
+
+ \sa y(), setX()
+*/
+
+/*! \fn float &QVector2D::operator[](int i)
+ \since 5.2
+
+ Returns the component of the vector at index position \a i
+ as a modifiable reference.
+
+ \a i must be a valid index position in the vector (i.e., 0 <= \a i
+ < 2).
+*/
+
+/*! \fn float QVector2D::operator[](int i) const
+ \since 5.2
+
+ Returns the component of the vector at index position \a i.
+
+ \a i must be a valid index position in the vector (i.e., 0 <= \a i
+ < 2).
+*/
+
+/*!
+ \fn float QVector2D::length() const
+
+ Returns the length of the vector from the origin.
+
+ \sa lengthSquared(), normalized()
+*/
+
+/*!
+ \fn float QVector2D::lengthSquared() const
+
+ Returns the squared length of the vector from the origin.
+ This is equivalent to the dot product of the vector with itself.
+
+ \sa length(), dotProduct()
+*/
+
+/*!
+ \fn QVector2D QVector2D::normalized() const
+
+ Returns the normalized unit vector form of this vector.
+
+ If this vector is null, then a null vector is returned. If the length
+ of the vector is very close to 1, then the vector will be returned as-is.
+ Otherwise the normalized form of the vector of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+
+/*!
+ \fn void QVector2D::normalize()
+
+ Normalizes the current vector in place. Nothing happens if this
+ vector is a null vector or the length of the vector is very close to 1.
+
+ \sa length(), normalized()
+*/
+
+/*!
+ \fn float QVector2D::distanceToPoint(QVector2D point) const
+ \since 5.1
+
+ Returns the distance from this vertex to a point defined by
+ the vertex \a point.
+
+ \sa distanceToLine()
+*/
+
+/*!
+ \fn float QVector2D::distanceToLine(QVector2D point, QVector2D direction) const
+ \since 5.1
+
+ Returns the distance that this vertex is from a line defined
+ by \a point and the unit vector \a direction.
+
+ If \a direction is a null vector, then it does not define a line.
+ In that case, the distance from \a point to this vertex is returned.
+
+ \sa distanceToPoint()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator+=(QVector2D vector)
+
+ Adds the given \a vector to this vector and returns a reference to
+ this vector.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator-=(QVector2D vector)
+
+ Subtracts the given \a vector from this vector and returns a reference to
+ this vector.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator*=(float factor)
+
+ Multiplies this vector's coordinates by the given finite \a factor and
+ returns a reference to this vector.
+
+ \sa operator/=(), operator*()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator*=(QVector2D vector)
+
+ Multiplies each component of this vector by the corresponding component of
+ \a vector and returns a reference to this vector.
+
+ \note This is not a cross product of this vector with \a vector. (Its
+ components add up to the dot product of this vector and \a vector.)
+
+ \sa operator/=(), operator*()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator/=(float divisor)
+
+ Divides this vector's coordinates by the given \a divisor and returns a
+ reference to this vector. The \a divisor must not be either zero or NaN.
+
+ \sa operator*=()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator/=(QVector2D vector)
+ \since 5.5
+
+ Divides each component of this vector by the corresponding component of \a
+ vector and returns a reference to this vector.
+
+ The \a vector must have no component that is either zero or NaN.
+
+ \sa operator*=(), operator/()
+*/
+
+/*!
+ \fn float QVector2D::dotProduct(QVector2D v1, QVector2D v2)
+
+ Returns the dot product of \a v1 and \a v2.
+*/
+
+/*!
+ \fn bool QVector2D::operator==(QVector2D v1, QVector2D v2)
+
+ Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool QVector2D::operator!=(QVector2D v1, QVector2D v2)
+
+ Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator+(QVector2D v1, QVector2D v2)
+
+ Returns a QVector2D object that is the sum of the given vectors, \a v1
+ and \a v2; each component is added separately.
+
+ \sa QVector2D::operator+=()
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator-(QVector2D v1, QVector2D v2)
+
+ Returns a QVector2D object that is formed by subtracting \a v2 from \a v1;
+ each component is subtracted separately.
+
+ \sa QVector2D::operator-=()
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator*(float factor, QVector2D vector)
+
+ Returns a copy of the given \a vector, multiplied by the given finite \a factor.
+
+ \sa QVector2D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator*(QVector2D vector, float factor)
+
+ Returns a copy of the given \a vector, multiplied by the given finite \a factor.
+
+ \sa QVector2D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator*(QVector2D v1, QVector2D v2)
+
+ Returns the QVector2D object formed by multiplying each component of \a v1
+ by the corresponding component of \a v2.
+
+ \note This is not a cross product of \a v1 and \a v2 in any sense.
+ (Its components add up to the dot product of \a v1 and \a v2.)
+
+ \sa QVector2D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator-(QVector2D vector)
+ \overload
+
+ Returns a QVector2D object that is formed by changing the sign of each
+ component of the given \a vector.
+
+ Equivalent to \c {QVector2D(0,0) - vector}.
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator/(QVector2D vector, float divisor)
+
+ Returns the QVector2D object formed by dividing each component of the given
+ \a vector by the given \a divisor.
+
+ The \a divisor must not be either zero or NaN.
+
+ \sa QVector2D::operator/=()
+*/
+
+/*! //! friend
+ \fn const QVector2D QVector2D::operator/(QVector2D vector, QVector2D divisor)
+ \since 5.5
+
+ Returns the QVector2D object formed by dividing each component of the given
+ \a vector by the corresponding component of the given \a divisor.
+
+ The \a divisor must have no component that is either zero or NaN.
+
+ \sa QVector2D::operator/=()
+*/
+
+/*! //! friend
+ \fn bool QVector2D::qFuzzyCompare(QVector2D v1, QVector2D v2)
+
+ Returns \c true if \a v1 and \a v2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept
+{
+ return qFuzzyCompare(v1.v[0], v2.v[0]) && qFuzzyCompare(v1.v[1], v2.v[1]);
+}
+
+#ifndef QT_NO_VECTOR3D
+/*!
+ \fn QVector3D QVector2D::toVector3D() const
+
+ Returns the 3D form of this 2D vector, with the z coordinate set to zero.
+
+ \sa toVector4D(), toPoint()
+*/
+#endif
+
+#ifndef QT_NO_VECTOR4D
+/*!
+ \fn QVector4D QVector2D::toVector4D() const
+
+ Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
+
+ \sa toVector3D(), toPoint()
+*/
+#endif
+
+/*!
+ \fn QPoint QVector2D::toPoint() const
+
+ Returns the QPoint form of this 2D vector.
+ Each coordinate is rounded to the nearest integer.
+
+ \sa toPointF(), toVector3D()
+*/
+
+/*!
+ \fn QPointF QVector2D::toPointF() const
+
+ Returns the QPointF form of this 2D vector.
+
+ \sa toPoint(), toVector3D()
+*/
+
+/*!
+ Returns the 2D vector as a QVariant.
+*/
+QVector2D::operator QVariant() const
+{
+ return QVariant::fromValue(*this);
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, QVector2D vector)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace() << "QVector2D(" << vector.x() << ", " << vector.y() << ')';
+ return dbg;
+}
+
+#endif
+
+#ifndef QT_NO_DATASTREAM
+
+/*!
+ \fn QDataStream &operator<<(QDataStream &stream, QVector2D vector)
+ \relates QVector2D
+
+ Writes the given \a vector to the given \a stream and returns a
+ reference to the stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator<<(QDataStream &stream, QVector2D vector)
+{
+ stream << vector.x() << vector.y();
+ return stream;
+}
+
+/*!
+ \fn QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
+ \relates QVector2D
+
+ Reads a 2D vector from the given \a stream into the given \a vector
+ and returns a reference to the stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
+{
+ float x, y;
+ stream >> x;
+ stream >> y;
+ Q_ASSERT(qIsFinite(x) && qIsFinite(y));
+ vector.setX(x);
+ vector.setY(y);
+ return stream;
+}
+
+#endif // QT_NO_DATASTREAM
+
+#endif // QT_NO_VECTOR2D
+
+
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \class QVector3D
+ \brief The QVector3D class represents a vector or vertex in 3D space.
+ \since 4.6
+ \ingroup painting-3D
+ \inmodule QtGui
+
+ Vectors are one of the main building blocks of 3D representation and
+ drawing. They consist of three finite floating-point coordinates,
+ traditionally called x, y, and z.
+
+ The QVector3D class can also be used to represent vertices in 3D space.
+ We therefore do not need to provide a separate vertex class.
+
+ \sa QVector2D, QVector4D, QQuaternion
+*/
+
+/*!
+ \fn QVector3D::QVector3D()
+
+ Constructs a null vector, i.e. with coordinates (0, 0, 0).
+*/
+
+/*!
+ \fn QVector3D::QVector3D(Qt::Initialization)
+ \since 5.5
+ \internal
+
+ Constructs a vector without initializing the contents.
+*/
+
+/*!
+ \fn QVector3D::QVector3D(float xpos, float ypos, float zpos)
+
+ Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos).
+ All parameters must be finite.
+*/
+
+/*!
+ \fn QVector3D::QVector3D(QPoint point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and a
+ z coordinate of 0.
+*/
+
+/*!
+ \fn QVector3D::QVector3D(QPointF point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and a
+ z coordinate of 0.
+*/
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ \fn QVector3D::QVector3D(QVector2D vector)
+
+ Constructs a 3D vector from the specified 2D \a vector. The z
+ coordinate is set to zero.
+
+ \sa toVector2D()
+*/
+
+/*!
+ \fn QVector3D::QVector3D(QVector2D vector, float zpos)
+
+ Constructs a 3D vector from the specified 2D \a vector. The z
+ coordinate is set to \a zpos, which must be finite.
+
+ \sa toVector2D()
+*/
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \fn QVector3D::QVector3D(QVector4D vector)
+
+ Constructs a 3D vector from the specified 4D \a vector. The w
+ coordinate is dropped.
+
+ \sa toVector4D()
+*/
+
+#endif
+
+/*!
+ \fn bool QVector3D::isNull() const
+
+ Returns \c true if the x, y, and z coordinates are set to 0.0,
+ otherwise returns \c false.
+*/
+
+/*!
+ \fn float QVector3D::x() const
+
+ Returns the x coordinate of this point.
+
+ \sa setX(), y(), z()
+*/
+
+/*!
+ \fn float QVector3D::y() const
+
+ Returns the y coordinate of this point.
+
+ \sa setY(), x(), z()
+*/
+
+/*!
+ \fn float QVector3D::z() const
+
+ Returns the z coordinate of this point.
+
+ \sa setZ(), x(), y()
+*/
+
+/*!
+ \fn void QVector3D::setX(float x)
+
+ Sets the x coordinate of this point to the given finite \a x coordinate.
+
+ \sa x(), setY(), setZ()
+*/
+
+/*!
+ \fn void QVector3D::setY(float y)
+
+ Sets the y coordinate of this point to the given finite \a y coordinate.
+
+ \sa y(), setX(), setZ()
+*/
+
+/*!
+ \fn void QVector3D::setZ(float z)
+
+ Sets the z coordinate of this point to the given finite \a z coordinate.
+
+ \sa z(), setX(), setY()
+*/
+
+/*! \fn float &QVector3D::operator[](int i)
+ \since 5.2
+
+ Returns the component of the vector at index position \a i
+ as a modifiable reference.
+
+ \a i must be a valid index position in the vector (i.e., 0 <= \a i
+ < 3).
+*/
+
+/*! \fn float QVector3D::operator[](int i) const
+ \since 5.2
+
+ Returns the component of the vector at index position \a i.
+
+ \a i must be a valid index position in the vector (i.e., 0 <= \a i
+ < 3).
+*/
+
+/*!
+ \fn QVector3D QVector3D::normalized() const
+
+ Returns the normalized unit vector form of this vector.
+
+ If this vector is null, then a null vector is returned. If the length
+ of the vector is very close to 1, then the vector will be returned as-is.
+ Otherwise the normalized form of the vector of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+
+/*!
+ \fn void QVector3D::normalize()
+
+ Normalizes the current vector in place. Nothing happens if this
+ vector is a null vector or the length of the vector is very close to 1.
+
+ \sa length(), normalized()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator+=(QVector3D vector)
+
+ Adds the given \a vector to this vector and returns a reference to
+ this vector.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator-=(QVector3D vector)
+
+ Subtracts the given \a vector from this vector and returns a reference to
+ this vector.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator*=(float factor)
+
+ Multiplies this vector's coordinates by the given finite \a factor and
+ returns a reference to this vector.
+
+ \sa operator/=(), operator*()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator*=(QVector3D vector)
+ \overload
+
+ Multiplies each component of this vector by the corresponding component in
+ \a vector and returns a reference to this vector.
+
+ Note: this is not the same as the crossProduct() of this vector and
+ \a vector. (Its components add up to the dot product of this vector and
+ \a vector.)
+
+ \sa crossProduct(), operator/=(), operator*()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator/=(float divisor)
+
+ Divides this vector's coordinates by the given \a divisor, and returns a
+ reference to this vector. The \a divisor must not be either zero or NaN.
+
+ \sa operator*=(), operator/()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator/=(QVector3D vector)
+ \since 5.5
+
+ Divides each component of this vector by the corresponding component in \a
+ vector and returns a reference to this vector.
+
+ The \a vector must have no component that is either zero or NaN.
+
+ \sa operator*=(), operator/()
+*/
+
+/*!
+ \fn float QVector3D::dotProduct(QVector3D v1, QVector3D v2)
+
+ Returns the dot product of \a v1 and \a v2.
+*/
+
+/*!
+ \fn QVector3D QVector3D::crossProduct(QVector3D v1, QVector3D v2)
+
+ Returns the cross-product of vectors \a v1 and \a v2, which is normal to the
+ plane spanned by \a v1 and \a v2. It will be zero if the two vectors are
+ parallel.
+
+ \sa normal()
+*/
+
+/*!
+ \fn QVector3D QVector3D::normal(QVector3D v1, QVector3D v2)
+
+ Returns the unit normal vector of a plane spanned by vectors \a v1 and \a
+ v2, which must not be parallel to one another.
+
+ Use crossProduct() to compute the cross-product of \a v1 and \a v2 if you
+ do not need the result to be normalized to a unit vector.
+
+ \sa crossProduct(), distanceToPlane()
+*/
+
+/*!
+ \fn QVector3D QVector3D::normal(QVector3D v1, QVector3D v2, QVector3D v3)
+
+ Returns the unit normal vector of a plane spanned by vectors \a v2 - \a v1
+ and \a v3 - \a v1, which must not be parallel to one another.
+
+ Use crossProduct() to compute the cross-product of \a v2 - \a v1 and
+ \a v3 - \a v1 if you do not need the result to be normalized to a
+ unit vector.
+
+ \sa crossProduct(), distanceToPlane()
+*/
+
+/*!
+ \since 5.5
+
+ Returns the window coordinates of this vector initially in object/model
+ coordinates using the model view matrix \a modelView, the projection matrix
+ \a projection and the viewport dimensions \a viewport.
+
+ When transforming from clip to normalized space, a division by the w
+ component on the vector components takes place. To prevent dividing by 0 if
+ w equals to 0, it is set to 1.
+
+ \note the returned y coordinates are in OpenGL orientation. OpenGL expects
+ the bottom to be 0 whereas for Qt top is 0.
+
+ \sa unproject()
+ */
+QVector3D QVector3D::project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const
+{
+ QVector4D tmp(*this, 1.0f);
+ tmp = projection * modelView * tmp;
+ if (qFuzzyIsNull(tmp.w()))
+ tmp.setW(1.0f);
+ tmp /= tmp.w();
+
+ tmp = tmp * 0.5f + QVector4D(0.5f, 0.5f, 0.5f, 0.5f);
+ tmp.setX(tmp.x() * viewport.width() + viewport.x());
+ tmp.setY(tmp.y() * viewport.height() + viewport.y());
+
+ return tmp.toVector3D();
+}
+
+/*!
+ \since 5.5
+
+ Returns the object/model coordinates of this vector initially in window
+ coordinates using the model view matrix \a modelView, the projection matrix
+ \a projection and the viewport dimensions \a viewport.
+
+ When transforming from clip to normalized space, a division by the w
+ component of the vector components takes place. To prevent dividing by 0 if
+ w equals to 0, it is set to 1.
+
+ \note y coordinates in \a viewport should use OpenGL orientation. OpenGL
+ expects the bottom to be 0 whereas for Qt top is 0.
+
+ \sa project()
+ */
+QVector3D QVector3D::unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const
+{
+ QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted();
+
+ QVector4D tmp(*this, 1.0f);
+ tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width()));
+ tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height()));
+ tmp = tmp * 2.0f - QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
+
+ QVector4D obj = inverse * tmp;
+ if (qFuzzyIsNull(obj.w()))
+ obj.setW(1.0f);
+ obj /= obj.w();
+ return obj.toVector3D();
+}
+
+/*!
+ \fn float QVector3D::distanceToPoint(QVector3D point) const
+
+ \since 5.1
+
+ Returns the distance from this vertex to a point defined by
+ the vertex \a point.
+
+ \sa distanceToPlane(), distanceToLine()
+*/
+
+/*!
+ \fn float QVector3D::distanceToPlane(QVector3D plane, QVector3D normal) const
+
+ Returns the distance from this vertex to a plane defined by
+ the vertex \a plane and a \a normal unit vector. The \a normal
+ parameter is assumed to have been normalized to a unit vector.
+
+ The return value will be negative if the vertex is below the plane,
+ or zero if it is on the plane.
+
+ \sa normal(), distanceToLine()
+*/
+
+/*!
+ \fn float QVector3D::distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const
+
+ Returns the distance from this vertex to a plane defined by
+ the vertices \a plane1, \a plane2 and \a plane3.
+
+ The return value will be negative if the vertex is below the plane,
+ or zero if it is on the plane.
+
+ The two vectors that define the plane are \a plane2 - \a plane1
+ and \a plane3 - \a plane1.
+
+ \sa normal(), distanceToLine()
+*/
+
+/*!
+ \fn float QVector3D::distanceToLine(QVector3D point, QVector3D direction) const
+
+ Returns the distance that this vertex is from a line defined
+ by \a point and the unit vector \a direction.
+
+ If \a direction is a null vector, then it does not define a line.
+ In that case, the distance from \a point to this vertex is returned.
+
+ \sa distanceToPlane()
+*/
+
+/*!
+ \fn bool QVector3D::operator==(QVector3D v1, QVector3D v2)
+
+ Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool QVector3D::operator!=(QVector3D v1, QVector3D v2)
+
+ Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator+(QVector3D v1, QVector3D v2)
+
+ Returns a QVector3D object that is the sum of the given vectors, \a v1
+ and \a v2; each component is added separately.
+
+ \sa QVector3D::operator+=()
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator-(QVector3D v1, QVector3D v2)
+
+ Returns a QVector3D object that is formed by subtracting \a v2 from \a v1;
+ each component is subtracted separately.
+
+ \sa QVector3D::operator-=()
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator*(float factor, QVector3D vector)
+
+ Returns a copy of the given \a vector, multiplied by the given finite \a factor.
+
+ \sa QVector3D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator*(QVector3D vector, float factor)
+
+ Returns a copy of the given \a vector, multiplied by the given finite \a factor.
+
+ \sa QVector3D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator*(QVector3D v1, QVector3D v2)
+
+ Returns the QVector3D object formed by multiplying each component of \a v1
+ by the corresponding component of \a v2.
+
+ \note This is not the same as the crossProduct() of \a v1 and \a v2.
+ (Its components add up to the dot product of \a v1 and \a v2.)
+
+ \sa QVector3D::crossProduct()
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator-(QVector3D vector)
+ \overload
+
+ Returns a QVector3D object that is formed by changing the sign of each
+ component of the given \a vector.
+
+ Equivalent to \c {QVector3D(0,0,0) - vector}.
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator/(QVector3D vector, float divisor)
+
+ Returns the QVector3D object formed by dividing each component of the given
+ \a vector by the given \a divisor.
+
+ The \a divisor must not be either zero or NaN.
+
+ \sa QVector3D::operator/=()
+*/
+
+/*! //! friend
+ \fn const QVector3D QVector3D::operator/(QVector3D vector, QVector3D divisor)
+ \since 5.5
+
+ Returns the QVector3D object formed by dividing each component of the given
+ \a vector by the corresponding component of the given \a divisor.
+
+ The \a divisor must have no component that is either zero or NaN.
+
+ \sa QVector3D::operator/=()
+*/
+
+/*! //! friend
+ \fn bool QVector3D::qFuzzyCompare(QVector3D v1, QVector3D v2)
+
+ Returns \c true if \a v1 and \a v2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept
+{
+ return qFuzzyCompare(v1.v[0], v2.v[0]) &&
+ qFuzzyCompare(v1.v[1], v2.v[1]) &&
+ qFuzzyCompare(v1.v[2], v2.v[2]);
+}
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ \fn QVector2D QVector3D::toVector2D() const
+
+ Returns the 2D vector form of this 3D vector, dropping the z coordinate.
+
+ \sa toVector4D(), toPoint()
+*/
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \fn QVector4D QVector3D::toVector4D() const
+
+ Returns the 4D form of this 3D vector, with the w coordinate set to zero.
+
+ \sa toVector2D(), toPoint()
+*/
+
+#endif
+
+/*!
+ \fn QPoint QVector3D::toPoint() const
+
+ Returns the QPoint form of this 3D vector. The z coordinate is dropped. The
+ x and y coordinates are rounded to nearest integers.
+
+ \sa toPointF(), toVector2D()
+*/
+
+/*!
+ \fn QPointF QVector3D::toPointF() const
+
+ Returns the QPointF form of this 3D vector. The z coordinate
+ is dropped.
+
+ \sa toPoint(), toVector2D()
+*/
+
+/*!
+ Returns the 3D vector as a QVariant.
+*/
+QVector3D::operator QVariant() const
+{
+ return QVariant::fromValue(*this);
+}
+
+/*!
+ \fn float QVector3D::length() const
+
+ Returns the length of the vector from the origin.
+
+ \sa lengthSquared(), normalized()
+*/
+
+/*!
+ \fn float QVector3D::lengthSquared() const
+
+ Returns the squared length of the vector from the origin.
+ This is equivalent to the dot product of the vector with itself.
+
+ \sa length(), dotProduct()
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, QVector3D vector)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace() << "QVector3D("
+ << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';
+ return dbg;
+}
+
+#endif
+
+#ifndef QT_NO_DATASTREAM
+
+/*!
+ \fn QDataStream &operator<<(QDataStream &stream, QVector3D vector)
+ \relates QVector3D
+
+ Writes the given \a vector to the given \a stream and returns a
+ reference to the stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator<<(QDataStream &stream, QVector3D vector)
+{
+ stream << vector.x() << vector.y() << vector.z();
+ return stream;
+}
+
+/*!
+ \fn QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
+ \relates QVector3D
+
+ Reads a 3D vector from the given \a stream into the given \a vector
+ and returns a reference to the stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
+{
+ float x, y, z;
+ stream >> x;
+ stream >> y;
+ stream >> z;
+ Q_ASSERT(qIsFinite(x) && qIsFinite(y) && qIsFinite(z));
+ vector.setX(x);
+ vector.setY(y);
+ vector.setZ(z);
+ return stream;
+}
+
+#endif // QT_NO_DATASTREAM
+
+#endif // QT_NO_VECTOR3D
+
+
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \class QVector4D
+ \brief The QVector4D class represents a vector or vertex in 4D space.
+ \since 4.6
+ \ingroup painting-3D
+ \inmodule QtGui
+
+ Vectors are one of the main building blocks of 4D affine representations of
+ 3D space. They consist of four finite floating-point coordinates,
+ traditionally called x, y, z and w.
+
+ The QVector4D class can also be used to represent vertices in 4D space.
+ We therefore do not need to provide a separate vertex class.
+
+ \sa QQuaternion, QVector2D, QVector3D
+*/
+
+/*!
+ \fn QVector4D::QVector4D()
+
+ Constructs a null vector, i.e. with coordinates (0, 0, 0, 0).
+*/
+
+/*!
+ \fn QVector4D::QVector4D(Qt::Initialization)
+ \since 5.5
+ \internal
+
+ Constructs a vector without initializing the contents.
+*/
+
+/*!
+ \fn QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos)
+
+ Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos, \a wpos).
+ All parameters must be finite.
+*/
+
+/*!
+ \fn QVector4D::QVector4D(QPoint point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and
+ z and w coordinates of 0.
+*/
+
+/*!
+ \fn QVector4D::QVector4D(QPointF point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and
+ z and w coordinates of 0.
+*/
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ \fn QVector4D::QVector4D(QVector2D vector)
+
+ Constructs a 4D vector from the specified 2D \a vector. The z
+ and w coordinates are set to zero.
+
+ \sa toVector2D()
+*/
+
+/*!
+ \fn QVector4D::QVector4D(QVector2D vector, float zpos, float wpos)
+
+ Constructs a 4D vector from the specified 2D \a vector. The z
+ and w coordinates are set to \a zpos and \a wpos respectively,
+ each of which must be finite.
+
+ \sa toVector2D()
+*/
+
+#endif
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \fn QVector4D::QVector4D(QVector3D vector)
+
+ Constructs a 4D vector from the specified 3D \a vector. The w
+ coordinate is set to zero.
+
+ \sa toVector3D()
+*/
+
+/*!
+ \fn QVector4D::QVector4D(QVector3D vector, float wpos)
+
+ Constructs a 4D vector from the specified 3D \a vector. The w
+ coordinate is set to \a wpos, which must be finite.
+
+ \sa toVector3D()
+*/
+
+#endif
+
+/*!
+ \fn bool QVector4D::isNull() const
+
+ Returns \c true if the x, y, z, and w coordinates are set to 0.0,
+ otherwise returns \c false.
+*/
+
+/*!
+ \fn float QVector4D::x() const
+
+ Returns the x coordinate of this point.
+
+ \sa setX(), y(), z(), w()
+*/
+
+/*!
+ \fn float QVector4D::y() const
+
+ Returns the y coordinate of this point.
+
+ \sa setY(), x(), z(), w()
+*/
+
+/*!
+ \fn float QVector4D::z() const
+
+ Returns the z coordinate of this point.
+
+ \sa setZ(), x(), y(), w()
+*/
+
+/*!
+ \fn float QVector4D::w() const
+
+ Returns the w coordinate of this point.
+
+ \sa setW(), x(), y(), z()
+*/
+
+/*!
+ \fn void QVector4D::setX(float x)
+
+ Sets the x coordinate of this point to the given finite \a x coordinate.
+
+ \sa x(), setY(), setZ(), setW()
+*/
+
+/*!
+ \fn void QVector4D::setY(float y)
+
+ Sets the y coordinate of this point to the given finite \a y coordinate.
+
+ \sa y(), setX(), setZ(), setW()
+*/
+
+/*!
+ \fn void QVector4D::setZ(float z)
+
+ Sets the z coordinate of this point to the given finite \a z coordinate.
+
+ \sa z(), setX(), setY(), setW()
+*/
+
+/*!
+ \fn void QVector4D::setW(float w)
+
+ Sets the w coordinate of this point to the given finite \a w coordinate.
+
+ \sa w(), setX(), setY(), setZ()
+*/
+
+/*! \fn float &QVector4D::operator[](int i)
+ \since 5.2
+
+ Returns the component of the vector at index position \a i
+ as a modifiable reference.
+
+ \a i must be a valid index position in the vector (i.e., 0 <= \a i
+ < 4).
+*/
+
+/*! \fn float QVector4D::operator[](int i) const
+ \since 5.2
+
+ Returns the component of the vector at index position \a i.
+
+ \a i must be a valid index position in the vector (i.e., 0 <= \a i
+ < 4).
+*/
+
+/*!
+ \fn float QVector4D::length() const
+
+ Returns the length of the vector from the origin.
+
+ \sa lengthSquared(), normalized()
+*/
+
+/*!
+ \fn float QVector4D::lengthSquared() const
+
+ Returns the squared length of the vector from the origin.
+ This is equivalent to the dot product of the vector with itself.
+
+ \sa length(), dotProduct()
+*/
+
+/*!
+ \fn QVector4D QVector4D::normalized() const
+
+ Returns the normalized unit vector form of this vector.
+
+ If this vector is null, then a null vector is returned. If the length
+ of the vector is very close to 1, then the vector will be returned as-is.
+ Otherwise the normalized form of the vector of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+
+/*!
+ \fn void QVector4D::normalize()
+
+ Normalizes the current vector in place. Nothing happens if this
+ vector is a null vector or the length of the vector is very close to 1.
+
+ \sa length(), normalized()
+*/
+
+
+/*!
+ \fn QVector4D &QVector4D::operator+=(QVector4D vector)
+
+ Adds the given \a vector to this vector and returns a reference to
+ this vector.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator-=(QVector4D vector)
+
+ Subtracts the given \a vector from this vector and returns a reference to
+ this vector.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator*=(float factor)
+
+ Multiplies this vector's coordinates by the given finite \a factor, and
+ returns a reference to this vector.
+
+ \sa operator/=(), operator*()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator*=(QVector4D vector)
+
+ Multiplies each component of this vector by the corresponding component of
+ \a vector and returns a reference to this vector.
+
+ \sa operator/=(), operator*()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator/=(float divisor)
+
+ Divides this vector's coordinates by the given \a divisor, and returns a
+ reference to this vector. The \a divisor must not be either zero or NaN.
+
+ \sa operator*=()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator/=(QVector4D vector)
+ \since 5.5
+
+ Divides each component of this vector by the corresponding component of \a
+ vector and returns a reference to this vector.
+
+ The \a vector must have no component that is either zero or NaN.
+
+ \sa operator*=(), operator/()
+*/
+
+/*!
+ \fn float QVector4D::dotProduct(QVector4D v1, QVector4D v2)
+
+ Returns the dot product of \a v1 and \a v2.
+*/
+
+/*!
+ \fn bool QVector4D::operator==(QVector4D v1, QVector4D v2)
+
+ Returns \c true if \a v1 is equal to \a v2; otherwise returns \c false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool QVector4D::operator!=(QVector4D v1, QVector4D v2)
+
+ Returns \c true if \a v1 is not equal to \a v2; otherwise returns \c false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator+(QVector4D v1, QVector4D v2)
+
+ Returns a QVector4D object that is the sum of the given vectors, \a v1
+ and \a v2; each component is added separately.
+
+ \sa QVector4D::operator+=()
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator-(QVector4D v1, QVector4D v2)
+
+ Returns a QVector4D object that is formed by subtracting \a v2 from \a v1;
+ each component is subtracted separately.
+
+ \sa QVector4D::operator-=()
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator*(float factor, QVector4D vector)
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector4D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator*(QVector4D vector, float factor)
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector4D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator*(QVector4D v1, QVector4D v2)
+
+ Returns the QVector4D object formed by multiplying each component of \a v1
+ by the corresponding component of \a v2.
+
+ \note This is not a cross product of \a v1 and \a v2 in any sense.
+ (Its components add up to the dot product of \a v1 and \a v2.)
+
+ \sa QVector4D::operator*=()
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator-(QVector4D vector)
+ \overload
+
+ Returns a QVector4D object that is formed by changing the sign of
+ all three components of the given \a vector.
+
+ Equivalent to \c {QVector4D(0,0,0,0) - vector}.
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator/(QVector4D vector, float divisor)
+
+ Returns the QVector4D object formed by dividing each component of the given
+ \a vector by the given \a divisor.
+
+ The \a divisor must not be either zero or NaN.
+
+ \sa QVector4D::operator/=()
+*/
+
+/*! //! friend
+ \fn const QVector4D QVector4D::operator/(QVector4D vector, QVector4D divisor)
+ \since 5.5
+
+ Returns the QVector4D object formed by dividing each component of the given
+ \a vector by the corresponding component of the given \a divisor.
+
+ The \a divisor must have no component that is either zero or NaN.
+
+ \sa QVector4D::operator/=()
+*/
+
+/*! //! friend
+ \fn bool QVector4D::qFuzzyCompare(QVector4D v1, QVector4D v2)
+
+ Returns \c true if \a v1 and \a v2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept
+{
+ return qFuzzyCompare(v1.v[0], v2.v[0]) &&
+ qFuzzyCompare(v1.v[1], v2.v[1]) &&
+ qFuzzyCompare(v1.v[2], v2.v[2]) &&
+ qFuzzyCompare(v1.v[3], v2.v[3]);
+}
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ \fn QVector2D QVector4D::toVector2D() const
+
+ Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
+
+ \sa toVector2DAffine(), toVector3D(), toPoint()
+*/
+
+/*!
+ \fn QVector2D QVector4D::toVector2DAffine() const
+
+ Returns the 2D vector form of this 4D vector, dividing the x and y
+ coordinates by the w coordinate and dropping the z coordinate.
+ Returns a null vector if w is zero.
+
+ \sa toVector2D(), toVector3DAffine(), toPoint()
+*/
+
+#endif
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \fn QVector3D QVector4D::toVector3D() const
+
+ Returns the 3D vector form of this 4D vector, dropping the w coordinate.
+
+ \sa toVector3DAffine(), toVector2D(), toPoint()
+*/
+
+/*!
+ \fn QVector3D QVector4D::toVector3DAffine() const
+
+ Returns the 3D vector form of this 4D vector, dividing the x, y, and
+ z coordinates by the w coordinate. Returns a null vector if w is zero.
+
+ \sa toVector3D(), toVector2DAffine(), toPoint()
+*/
+
+#endif
+
+/*!
+ \fn QPoint QVector4D::toPoint() const
+
+ Returns the QPoint form of this 4D vector. The z and w coordinates are
+ dropped. The x and y coordinates are rounded to nearest integers.
+
+ \sa toPointF(), toVector2D()
+*/
+
+/*!
+ \fn QPointF QVector4D::toPointF() const
+
+ Returns the QPointF form of this 4D vector. The z and w coordinates
+ are dropped.
+
+ \sa toPoint(), toVector2D()
+*/
+
+/*!
+ Returns the 4D vector as a QVariant.
+*/
+QVector4D::operator QVariant() const
+{
+ return QVariant::fromValue(*this);
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, QVector4D vector)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace() << "QVector4D("
+ << vector.x() << ", " << vector.y() << ", "
+ << vector.z() << ", " << vector.w() << ')';
+ return dbg;
+}
+
+#endif
+
+#ifndef QT_NO_DATASTREAM
+
+/*!
+ \fn QDataStream &operator<<(QDataStream &stream, QVector4D vector)
+ \relates QVector4D
+
+ Writes the given \a vector to the given \a stream and returns a
+ reference to the stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator<<(QDataStream &stream, QVector4D vector)
+{
+ stream << vector.x() << vector.y()
+ << vector.z() << vector.w();
+ return stream;
+}
+
+/*!
+ \fn QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
+ \relates QVector4D
+
+ Reads a 4D vector from the given \a stream into the given \a vector
+ and returns a reference to the stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
+{
+ float x, y, z, w;
+ stream >> x;
+ stream >> y;
+ stream >> z;
+ stream >> w;
+ Q_ASSERT(qIsFinite(x) && qIsFinite(y) && qIsFinite(z) && qIsFinite(w));
+ vector.setX(x);
+ vector.setY(y);
+ vector.setZ(z);
+ vector.setW(w);
+ return stream;
+}
+
+#endif // QT_NO_DATASTREAM
+
+#endif // QT_NO_VECTOR4D
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvectornd.h b/src/gui/math3d/qvectornd.h
new file mode 100644
index 0000000000..a8adf12801
--- /dev/null
+++ b/src/gui/math3d/qvectornd.h
@@ -0,0 +1,1086 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVECTORND_H
+#define QVECTORND_H
+
+#include <QtGui/qtguiglobal.h>
+#include <QtCore/qpoint.h>
+#include <QtCore/qrect.h>
+#include <QtCore/qmath.h>
+
+#include <QtCore/q20type_traits.h>
+#include <QtCore/q23utility.h>
+
+QT_BEGIN_NAMESPACE
+
+// QT_ENABLE_P0846_SEMANTICS_FOR(get) // from qpoint.h
+
+class QVector2D;
+class QVector3D;
+class QVector4D;
+class QMatrix4x4;
+class QVariant;
+
+/***************************** QVector2D *****************************/
+
+#ifndef QT_NO_VECTOR2D
+
+class QVector2D
+{
+public:
+ constexpr QVector2D() noexcept;
+ explicit QVector2D(Qt::Initialization) noexcept {}
+ constexpr QVector2D(float xpos, float ypos) noexcept;
+ constexpr explicit QVector2D(QPoint point) noexcept;
+ constexpr explicit QVector2D(QPointF point) noexcept;
+#ifndef QT_NO_VECTOR3D
+ constexpr explicit QVector2D(QVector3D vector) noexcept;
+#endif
+#ifndef QT_NO_VECTOR4D
+ constexpr explicit QVector2D(QVector4D vector) noexcept;
+#endif
+
+ constexpr bool isNull() const noexcept;
+
+ constexpr float x() const noexcept;
+ constexpr float y() const noexcept;
+
+ constexpr void setX(float x) noexcept;
+ constexpr void setY(float y) noexcept;
+
+ constexpr float &operator[](int i);
+ constexpr float operator[](int i) const;
+
+ [[nodiscard]] float length() const noexcept;
+ [[nodiscard]] constexpr float lengthSquared() const noexcept;
+
+ [[nodiscard]] QVector2D normalized() const noexcept;
+ void normalize() noexcept;
+
+ [[nodiscard]] float distanceToPoint(QVector2D point) const noexcept;
+ [[nodiscard]] float distanceToLine(QVector2D point, QVector2D direction) const noexcept;
+
+ constexpr QVector2D &operator+=(QVector2D vector) noexcept;
+ constexpr QVector2D &operator-=(QVector2D vector) noexcept;
+ constexpr QVector2D &operator*=(float factor) noexcept;
+ constexpr QVector2D &operator*=(QVector2D vector) noexcept;
+ constexpr QVector2D &operator/=(float divisor);
+ constexpr QVector2D &operator/=(QVector2D vector);
+
+ [[nodiscard]] static constexpr float dotProduct(QVector2D v1, QVector2D v2) noexcept;
+
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_FLOAT_COMPARE
+ constexpr friend inline bool operator==(QVector2D v1, QVector2D v2) noexcept
+ {
+ return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1];
+ }
+
+ constexpr friend inline bool operator!=(QVector2D v1, QVector2D v2) noexcept
+ {
+ return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1];
+ }
+QT_WARNING_POP
+
+ constexpr friend inline QVector2D operator+(QVector2D v1, QVector2D v2) noexcept
+ {
+ return QVector2D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1]);
+ }
+
+ constexpr friend inline QVector2D operator-(QVector2D v1, QVector2D v2) noexcept
+ {
+ return QVector2D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1]);
+ }
+
+ constexpr friend inline QVector2D operator*(float factor, QVector2D vector) noexcept
+ {
+ return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
+ }
+
+ constexpr friend inline QVector2D operator*(QVector2D vector, float factor) noexcept
+ {
+ return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
+ }
+
+ constexpr friend inline QVector2D operator*(QVector2D v1, QVector2D v2) noexcept
+ {
+ return QVector2D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1]);
+ }
+
+ constexpr friend inline QVector2D operator-(QVector2D vector) noexcept
+ {
+ return QVector2D(-vector.v[0], -vector.v[1]);
+ }
+
+ constexpr friend inline QVector2D operator/(QVector2D vector, float divisor)
+ {
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ return QVector2D(vector.v[0] / divisor, vector.v[1] / divisor);
+ }
+
+ constexpr friend inline QVector2D operator/(QVector2D vector, QVector2D divisor)
+ {
+ Q_ASSERT(divisor.v[0] < 0 || divisor.v[0] > 0);
+ Q_ASSERT(divisor.v[1] < 0 || divisor.v[1] > 0);
+ return QVector2D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1]);
+ }
+
+ friend Q_GUI_EXPORT bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept;
+
+#ifndef QT_NO_VECTOR3D
+ constexpr QVector3D toVector3D() const noexcept;
+#endif
+#ifndef QT_NO_VECTOR4D
+ constexpr QVector4D toVector4D() const noexcept;
+#endif
+
+ constexpr QPoint toPoint() const noexcept;
+ constexpr QPointF toPointF() const noexcept;
+
+ Q_GUI_EXPORT operator QVariant() const;
+
+private:
+ float v[2];
+
+ friend class QVector3D;
+ friend class QVector4D;
+
+ template <std::size_t I,
+ typename V,
+ std::enable_if_t<(I < 2), bool> = true,
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<V>, QVector2D>, bool> = true>
+ friend constexpr decltype(auto) get(V &&vec) noexcept
+ {
+ return q23::forward_like<V>(vec.v[I]);
+ }
+};
+
+Q_DECLARE_TYPEINFO(QVector2D, Q_PRIMITIVE_TYPE);
+
+#endif // QT_NO_VECTOR2D
+
+
+
+/***************************** QVector3D *****************************/
+
+#ifndef QT_NO_VECTOR3D
+
+class QVector3D
+{
+public:
+ constexpr QVector3D() noexcept;
+ explicit QVector3D(Qt::Initialization) noexcept {}
+ constexpr QVector3D(float xpos, float ypos, float zpos) noexcept : v{xpos, ypos, zpos} {}
+
+ constexpr explicit QVector3D(QPoint point) noexcept;
+ constexpr explicit QVector3D(QPointF point) noexcept;
+#ifndef QT_NO_VECTOR2D
+ constexpr explicit QVector3D(QVector2D vector) noexcept;
+ constexpr QVector3D(QVector2D vector, float zpos) noexcept;
+#endif
+#ifndef QT_NO_VECTOR4D
+ constexpr explicit QVector3D(QVector4D vector) noexcept;
+#endif
+
+ constexpr bool isNull() const noexcept;
+
+ constexpr float x() const noexcept;
+ constexpr float y() const noexcept;
+ constexpr float z() const noexcept;
+
+ constexpr void setX(float x) noexcept;
+ constexpr void setY(float y) noexcept;
+ constexpr void setZ(float z) noexcept;
+
+ constexpr float &operator[](int i);
+ constexpr float operator[](int i) const;
+
+ [[nodiscard]] float length() const noexcept;
+ [[nodiscard]] constexpr float lengthSquared() const noexcept;
+
+ [[nodiscard]] QVector3D normalized() const noexcept;
+ void normalize() noexcept;
+
+ constexpr QVector3D &operator+=(QVector3D vector) noexcept;
+ constexpr QVector3D &operator-=(QVector3D vector) noexcept;
+ constexpr QVector3D &operator*=(float factor) noexcept;
+ constexpr QVector3D &operator*=(QVector3D vector) noexcept;
+ constexpr QVector3D &operator/=(float divisor);
+ constexpr QVector3D &operator/=(QVector3D vector);
+
+ [[nodiscard]] static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept;
+ [[nodiscard]] static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept;
+
+ [[nodiscard]] static QVector3D normal(QVector3D v1, QVector3D v2) noexcept;
+ [[nodiscard]] static QVector3D normal(QVector3D v1, QVector3D v2, QVector3D v3) noexcept;
+
+ Q_GUI_EXPORT QVector3D project(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const;
+ Q_GUI_EXPORT QVector3D unproject(const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const;
+
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_FLOAT_COMPARE
+ constexpr friend inline bool operator==(QVector3D v1, QVector3D v2) noexcept
+ {
+ return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2];
+ }
+
+ constexpr friend inline bool operator!=(QVector3D v1, QVector3D v2) noexcept
+ {
+ return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2];
+ }
+QT_WARNING_POP
+ float distanceToPoint(QVector3D point) const noexcept;
+ constexpr float distanceToPlane(QVector3D plane, QVector3D normal) const noexcept;
+ float distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept;
+ float distanceToLine(QVector3D point, QVector3D direction) const noexcept;
+
+
+ constexpr friend inline QVector3D operator+(QVector3D v1, QVector3D v2) noexcept
+ {
+ return QVector3D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2]);
+ }
+
+ constexpr friend inline QVector3D operator-(QVector3D v1, QVector3D v2) noexcept
+ {
+ return QVector3D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2]);
+ }
+
+ constexpr friend inline QVector3D operator*(float factor, QVector3D vector) noexcept
+ {
+ return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
+ }
+
+ constexpr friend inline QVector3D operator*(QVector3D vector, float factor) noexcept
+ {
+ return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
+ }
+
+ constexpr friend inline QVector3D operator*(QVector3D v1, QVector3D v2) noexcept
+ {
+ return QVector3D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2]);
+ }
+
+ constexpr friend inline QVector3D operator-(QVector3D vector) noexcept
+ {
+ return QVector3D(-vector.v[0], -vector.v[1], -vector.v[2]);
+ }
+
+ constexpr friend inline QVector3D operator/(QVector3D vector, float divisor)
+ {
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ return QVector3D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor);
+ }
+
+ constexpr friend inline QVector3D operator/(QVector3D vector, QVector3D divisor)
+ {
+ Q_ASSERT(divisor.v[0] > 0 || divisor.v[0] < 0);
+ Q_ASSERT(divisor.v[1] > 0 || divisor.v[1] < 0);
+ Q_ASSERT(divisor.v[2] > 0 || divisor.v[2] < 0);
+ return QVector3D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1],
+ vector.v[2] / divisor.v[2]);
+ }
+
+ friend Q_GUI_EXPORT bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept;
+
+#ifndef QT_NO_VECTOR2D
+ constexpr QVector2D toVector2D() const noexcept;
+#endif
+#ifndef QT_NO_VECTOR4D
+ constexpr QVector4D toVector4D() const noexcept;
+#endif
+
+ constexpr QPoint toPoint() const noexcept;
+ constexpr QPointF toPointF() const noexcept;
+
+ Q_GUI_EXPORT operator QVariant() const;
+
+private:
+ float v[3];
+
+ friend class QVector2D;
+ friend class QVector4D;
+#ifndef QT_NO_MATRIX4X4
+ friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
+ friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
+#endif
+
+ template <std::size_t I,
+ typename V,
+ std::enable_if_t<(I < 3), bool> = true,
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<V>, QVector3D>, bool> = true>
+ friend constexpr decltype(auto) get(V &&vec) noexcept
+ {
+ return q23::forward_like<V>(vec.v[I]);
+ }
+};
+
+Q_DECLARE_TYPEINFO(QVector3D, Q_PRIMITIVE_TYPE);
+
+#endif // QT_NO_VECTOR3D
+
+
+
+/***************************** QVector4D *****************************/
+
+#ifndef QT_NO_VECTOR4D
+
+class QVector4D
+{
+public:
+ constexpr QVector4D() noexcept;
+ explicit QVector4D(Qt::Initialization) noexcept {}
+ constexpr QVector4D(float xpos, float ypos, float zpos, float wpos) noexcept;
+ constexpr explicit QVector4D(QPoint point) noexcept;
+ constexpr explicit QVector4D(QPointF point) noexcept;
+#ifndef QT_NO_VECTOR2D
+ constexpr explicit QVector4D(QVector2D vector) noexcept;
+ constexpr QVector4D(QVector2D vector, float zpos, float wpos) noexcept;
+#endif
+#ifndef QT_NO_VECTOR3D
+ constexpr explicit QVector4D(QVector3D vector) noexcept;
+ constexpr QVector4D(QVector3D vector, float wpos) noexcept;
+#endif
+
+ constexpr bool isNull() const noexcept;
+
+ constexpr float x() const noexcept;
+ constexpr float y() const noexcept;
+ constexpr float z() const noexcept;
+ constexpr float w() const noexcept;
+
+ constexpr void setX(float x) noexcept;
+ constexpr void setY(float y) noexcept;
+ constexpr void setZ(float z) noexcept;
+ constexpr void setW(float w) noexcept;
+
+ constexpr float &operator[](int i);
+ constexpr float operator[](int i) const;
+
+ [[nodiscard]] float length() const noexcept;
+ [[nodiscard]] constexpr float lengthSquared() const noexcept;
+
+ [[nodiscard]] QVector4D normalized() const noexcept;
+ void normalize() noexcept;
+
+ constexpr QVector4D &operator+=(QVector4D vector) noexcept;
+ constexpr QVector4D &operator-=(QVector4D vector) noexcept;
+ constexpr QVector4D &operator*=(float factor) noexcept;
+ constexpr QVector4D &operator*=(QVector4D vector) noexcept;
+ constexpr QVector4D &operator/=(float divisor);
+ constexpr inline QVector4D &operator/=(QVector4D vector);
+
+ [[nodiscard]] static constexpr float dotProduct(QVector4D v1, QVector4D v2) noexcept;
+
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_FLOAT_COMPARE
+ constexpr friend inline bool operator==(QVector4D v1, QVector4D v2) noexcept
+ {
+ return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2] && v1.v[3] == v2.v[3];
+ }
+
+ constexpr friend inline bool operator!=(QVector4D v1, QVector4D v2) noexcept
+ {
+ return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2] || v1.v[3] != v2.v[3];
+ }
+QT_WARNING_POP
+ constexpr friend inline QVector4D operator+(QVector4D v1, QVector4D v2) noexcept
+ {
+ return QVector4D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2], v1.v[3] + v2.v[3]);
+ }
+
+ constexpr friend inline QVector4D operator-(QVector4D v1, QVector4D v2) noexcept
+ {
+ return QVector4D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2], v1.v[3] - v2.v[3]);
+ }
+
+ constexpr friend inline QVector4D operator*(float factor, QVector4D vector) noexcept
+ {
+ return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
+ }
+
+ constexpr friend inline QVector4D operator*(QVector4D vector, float factor) noexcept
+ {
+ return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
+ }
+
+ constexpr friend inline QVector4D operator*(QVector4D v1, QVector4D v2) noexcept
+ {
+ return QVector4D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2], v1.v[3] * v2.v[3]);
+ }
+
+ constexpr friend inline QVector4D operator-(QVector4D vector) noexcept
+ {
+ return QVector4D(-vector.v[0], -vector.v[1], -vector.v[2], -vector.v[3]);
+ }
+
+ constexpr friend inline QVector4D operator/(QVector4D vector, float divisor)
+ {
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ return QVector4D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor, vector.v[3] / divisor);
+ }
+
+ constexpr friend inline QVector4D operator/(QVector4D vector, QVector4D divisor)
+ {
+ Q_ASSERT(divisor.v[0] > 0 || divisor.v[0] < 0);
+ Q_ASSERT(divisor.v[1] > 0 || divisor.v[1] < 0);
+ Q_ASSERT(divisor.v[2] > 0 || divisor.v[2] < 0);
+ Q_ASSERT(divisor.v[3] > 0 || divisor.v[3] < 0);
+ return QVector4D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1],
+ vector.v[2] / divisor.v[2], vector.v[3] / divisor.v[3]);
+ }
+
+ friend Q_GUI_EXPORT bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept;
+
+#ifndef QT_NO_VECTOR2D
+ constexpr QVector2D toVector2D() const noexcept;
+ constexpr QVector2D toVector2DAffine() const noexcept;
+#endif
+#ifndef QT_NO_VECTOR3D
+ constexpr QVector3D toVector3D() const noexcept;
+ constexpr QVector3D toVector3DAffine() const noexcept;
+#endif
+
+ constexpr QPoint toPoint() const noexcept;
+ constexpr QPointF toPointF() const noexcept;
+
+ Q_GUI_EXPORT operator QVariant() const;
+
+private:
+ float v[4];
+
+ friend class QVector2D;
+ friend class QVector3D;
+ friend class QMatrix4x4;
+#ifndef QT_NO_MATRIX4X4
+ friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
+ friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
+#endif
+
+ template <std::size_t I,
+ typename V,
+ std::enable_if_t<(I < 4), bool> = true,
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<V>, QVector4D>, bool> = true>
+ friend constexpr decltype(auto) get(V &&vec) noexcept
+ {
+ return q23::forward_like<V>(vec.v[I]);
+ }
+};
+
+Q_DECLARE_TYPEINFO(QVector4D, Q_PRIMITIVE_TYPE);
+
+#endif // QT_NO_VECTOR4D
+
+
+
+/***************************** QVector2D *****************************/
+
+#ifndef QT_NO_VECTOR2D
+
+constexpr inline QVector2D::QVector2D() noexcept : v{0.0f, 0.0f} {}
+
+constexpr inline QVector2D::QVector2D(float xpos, float ypos) noexcept : v{xpos, ypos} {}
+
+constexpr inline QVector2D::QVector2D(QPoint point) noexcept : v{float(point.x()), float(point.y())} {}
+
+constexpr inline QVector2D::QVector2D(QPointF point) noexcept : v{float(point.x()), float(point.y())} {}
+
+#ifndef QT_NO_VECTOR3D
+constexpr inline QVector2D::QVector2D(QVector3D vector) noexcept : v{vector[0], vector[1]} {}
+#endif
+#ifndef QT_NO_VECTOR4D
+constexpr inline QVector2D::QVector2D(QVector4D vector) noexcept : v{vector[0], vector[1]} {}
+#endif
+
+constexpr inline bool QVector2D::isNull() const noexcept
+{
+ return qIsNull(v[0]) && qIsNull(v[1]);
+}
+
+constexpr inline float QVector2D::x() const noexcept { return v[0]; }
+constexpr inline float QVector2D::y() const noexcept { return v[1]; }
+
+constexpr inline void QVector2D::setX(float aX) noexcept { v[0] = aX; }
+constexpr inline void QVector2D::setY(float aY) noexcept { v[1] = aY; }
+
+constexpr inline float &QVector2D::operator[](int i)
+{
+ Q_ASSERT(uint(i) < 2u);
+ return v[i];
+}
+
+constexpr inline float QVector2D::operator[](int i) const
+{
+ Q_ASSERT(uint(i) < 2u);
+ return v[i];
+}
+
+inline float QVector2D::length() const noexcept
+{
+ return qHypot(v[0], v[1]);
+}
+
+constexpr inline float QVector2D::lengthSquared() const noexcept
+{
+ return v[0] * v[0] + v[1] * v[1];
+}
+
+inline QVector2D QVector2D::normalized() const noexcept
+{
+ const float len = length();
+ return qFuzzyIsNull(len - 1.0f) ? *this : qFuzzyIsNull(len) ? QVector2D()
+ : QVector2D(v[0] / len, v[1] / len);
+}
+
+inline void QVector2D::normalize() noexcept
+{
+ const float len = length();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ v[0] /= len;
+ v[1] /= len;
+}
+
+inline float QVector2D::distanceToPoint(QVector2D point) const noexcept
+{
+ return (*this - point).length();
+}
+
+inline float QVector2D::distanceToLine(QVector2D point, QVector2D direction) const noexcept
+{
+ if (direction.isNull())
+ return (*this - point).length();
+ QVector2D p = point + dotProduct(*this - point, direction) * direction;
+ return (*this - p).length();
+}
+
+constexpr inline QVector2D &QVector2D::operator+=(QVector2D vector) noexcept
+{
+ v[0] += vector.v[0];
+ v[1] += vector.v[1];
+ return *this;
+}
+
+constexpr inline QVector2D &QVector2D::operator-=(QVector2D vector) noexcept
+{
+ v[0] -= vector.v[0];
+ v[1] -= vector.v[1];
+ return *this;
+}
+
+constexpr inline QVector2D &QVector2D::operator*=(float factor) noexcept
+{
+ v[0] *= factor;
+ v[1] *= factor;
+ return *this;
+}
+
+constexpr inline QVector2D &QVector2D::operator*=(QVector2D vector) noexcept
+{
+ v[0] *= vector.v[0];
+ v[1] *= vector.v[1];
+ return *this;
+}
+
+constexpr inline QVector2D &QVector2D::operator/=(float divisor)
+{
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ v[0] /= divisor;
+ v[1] /= divisor;
+ return *this;
+}
+
+constexpr inline QVector2D &QVector2D::operator/=(QVector2D vector)
+{
+ Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
+ Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
+ v[0] /= vector.v[0];
+ v[1] /= vector.v[1];
+ return *this;
+}
+
+constexpr inline float QVector2D::dotProduct(QVector2D v1, QVector2D v2) noexcept
+{
+ return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1];
+}
+
+#ifndef QT_NO_VECTOR3D
+constexpr inline QVector3D QVector2D::toVector3D() const noexcept
+{
+ return QVector3D(v[0], v[1], 0.0f);
+}
+#endif
+#ifndef QT_NO_VECTOR4D
+constexpr inline QVector4D QVector2D::toVector4D() const noexcept
+{
+ return QVector4D(v[0], v[1], 0.0f, 0.0f);
+}
+#endif
+
+
+constexpr inline QPoint QVector2D::toPoint() const noexcept
+{
+ return QPoint(qRound(v[0]), qRound(v[1]));
+}
+
+constexpr inline QPointF QVector2D::toPointF() const noexcept
+{
+ return QPointF(qreal(v[0]), qreal(v[1]));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, QVector2D vector);
+#endif
+
+#ifndef QT_NO_DATASTREAM
+Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, QVector2D );
+Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector2D &);
+#endif
+
+#endif // QT_NO_VECTOR2D
+
+
+
+/***************************** QVector3D *****************************/
+
+#ifndef QT_NO_VECTOR3D
+
+constexpr inline QVector3D::QVector3D() noexcept : v{0.0f, 0.0f, 0.0f} {}
+
+constexpr inline QVector3D::QVector3D(QPoint point) noexcept : v{float(point.x()), float(point.y()), 0.0f} {}
+
+constexpr inline QVector3D::QVector3D(QPointF point) noexcept : v{float(point.x()), float(point.y()), 0.0f} {}
+
+#ifndef QT_NO_VECTOR2D
+constexpr inline QVector3D::QVector3D(QVector2D vector) noexcept : v{vector[0], vector[1], 0.0f} {}
+constexpr inline QVector3D::QVector3D(QVector2D vector, float zpos) noexcept : v{vector[0], vector[1], zpos} {}
+#endif
+
+#ifndef QT_NO_VECTOR4D
+constexpr inline QVector3D::QVector3D(QVector4D vector) noexcept : v{vector[0], vector[1], vector[2]} {}
+#endif
+
+constexpr inline bool QVector3D::isNull() const noexcept
+{
+ return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]);
+}
+
+constexpr inline float QVector3D::x() const noexcept { return v[0]; }
+constexpr inline float QVector3D::y() const noexcept { return v[1]; }
+constexpr inline float QVector3D::z() const noexcept { return v[2]; }
+
+constexpr inline void QVector3D::setX(float aX) noexcept { v[0] = aX; }
+constexpr inline void QVector3D::setY(float aY) noexcept { v[1] = aY; }
+constexpr inline void QVector3D::setZ(float aZ) noexcept { v[2] = aZ; }
+
+constexpr inline float &QVector3D::operator[](int i)
+{
+ Q_ASSERT(uint(i) < 3u);
+ return v[i];
+}
+
+constexpr inline float QVector3D::operator[](int i) const
+{
+ Q_ASSERT(uint(i) < 3u);
+ return v[i];
+}
+
+inline float QVector3D::length() const noexcept
+{
+ return qHypot(v[0], v[1], v[2]);
+}
+
+inline QVector3D QVector3D::normalized() const noexcept
+{
+ const float len = length();
+ return qFuzzyIsNull(len - 1.0f) ? *this : qFuzzyIsNull(len) ? QVector3D()
+ : QVector3D(v[0] / len, v[1] / len, v[2] / len);
+}
+
+inline void QVector3D::normalize() noexcept
+{
+ const float len = length();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ v[0] /= len;
+ v[1] /= len;
+ v[2] /= len;
+}
+
+constexpr inline float QVector3D::lengthSquared() const noexcept
+{
+ return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
+}
+
+constexpr inline QVector3D &QVector3D::operator+=(QVector3D vector) noexcept
+{
+ v[0] += vector.v[0];
+ v[1] += vector.v[1];
+ v[2] += vector.v[2];
+ return *this;
+}
+
+constexpr inline QVector3D &QVector3D::operator-=(QVector3D vector) noexcept
+{
+ v[0] -= vector.v[0];
+ v[1] -= vector.v[1];
+ v[2] -= vector.v[2];
+ return *this;
+}
+
+constexpr inline QVector3D &QVector3D::operator*=(float factor) noexcept
+{
+ v[0] *= factor;
+ v[1] *= factor;
+ v[2] *= factor;
+ return *this;
+}
+
+constexpr inline QVector3D &QVector3D::operator*=(QVector3D vector) noexcept
+{
+ v[0] *= vector.v[0];
+ v[1] *= vector.v[1];
+ v[2] *= vector.v[2];
+ return *this;
+}
+
+constexpr inline QVector3D &QVector3D::operator/=(float divisor)
+{
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ v[0] /= divisor;
+ v[1] /= divisor;
+ v[2] /= divisor;
+ return *this;
+}
+
+constexpr inline QVector3D &QVector3D::operator/=(QVector3D vector)
+{
+ Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
+ Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
+ Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
+ v[0] /= vector.v[0];
+ v[1] /= vector.v[1];
+ v[2] /= vector.v[2];
+ return *this;
+}
+
+constexpr inline float QVector3D::dotProduct(QVector3D v1, QVector3D v2) noexcept
+{
+ return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2];
+}
+
+constexpr inline QVector3D QVector3D::crossProduct(QVector3D v1, QVector3D v2) noexcept
+{
+ return QVector3D(v1.v[1] * v2.v[2] - v1.v[2] * v2.v[1],
+ v1.v[2] * v2.v[0] - v1.v[0] * v2.v[2],
+ v1.v[0] * v2.v[1] - v1.v[1] * v2.v[0]);
+}
+
+inline QVector3D QVector3D::normal(QVector3D v1, QVector3D v2) noexcept
+{
+ return crossProduct(v1, v2).normalized();
+}
+
+inline QVector3D QVector3D::normal(QVector3D v1, QVector3D v2, QVector3D v3) noexcept
+{
+ return crossProduct((v2 - v1), (v3 - v1)).normalized();
+}
+
+inline float QVector3D::distanceToPoint(QVector3D point) const noexcept
+{
+ return (*this - point).length();
+}
+
+constexpr inline float QVector3D::distanceToPlane(QVector3D plane, QVector3D normal) const noexcept
+{
+ return dotProduct(*this - plane, normal);
+}
+
+inline float QVector3D::distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept
+{
+ QVector3D n = normal(plane2 - plane1, plane3 - plane1);
+ return dotProduct(*this - plane1, n);
+}
+
+inline float QVector3D::distanceToLine(QVector3D point, QVector3D direction) const noexcept
+{
+ if (direction.isNull())
+ return (*this - point).length();
+ QVector3D p = point + dotProduct(*this - point, direction) * direction;
+ return (*this - p).length();
+}
+
+#ifndef QT_NO_VECTOR2D
+constexpr inline QVector2D QVector3D::toVector2D() const noexcept
+{
+ return QVector2D(v[0], v[1]);
+}
+#endif
+#ifndef QT_NO_VECTOR4D
+constexpr inline QVector4D QVector3D::toVector4D() const noexcept
+{
+ return QVector4D(v[0], v[1], v[2], 0.0f);
+}
+#endif
+
+constexpr inline QPoint QVector3D::toPoint() const noexcept
+{
+ return QPoint(qRound(v[0]), qRound(v[1]));
+}
+
+constexpr inline QPointF QVector3D::toPointF() const noexcept
+{
+ return QPointF(qreal(v[0]), qreal(v[1]));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, QVector3D vector);
+#endif
+
+#ifndef QT_NO_DATASTREAM
+Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, QVector3D );
+Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector3D &);
+#endif
+
+#endif // QT_NO_VECTOR3D
+
+
+
+/***************************** QVector4D *****************************/
+
+#ifndef QT_NO_VECTOR4D
+
+constexpr inline QVector4D::QVector4D() noexcept : v{0.0f, 0.0f, 0.0f, 0.0f} {}
+
+constexpr inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos) noexcept : v{xpos, ypos, zpos, wpos} {}
+
+constexpr inline QVector4D::QVector4D(QPoint point) noexcept : v{float(point.x()), float(point.y()), 0.0f, 0.0f} {}
+
+constexpr inline QVector4D::QVector4D(QPointF point) noexcept : v{float(point.x()), float(point.y()), 0.0f, 0.0f} {}
+
+#ifndef QT_NO_VECTOR2D
+constexpr QVector4D::QVector4D(QVector2D vector) noexcept : v{vector[0], vector[1], 0.0f, 0.0f} {}
+constexpr QVector4D::QVector4D(QVector2D vector, float zpos, float wpos) noexcept : v{vector[0], vector[1], zpos, wpos} {}
+#endif
+#ifndef QT_NO_VECTOR3D
+constexpr QVector4D::QVector4D(QVector3D vector) noexcept : v{vector[0], vector[1], vector[2], 0.0f} {}
+constexpr QVector4D::QVector4D(QVector3D vector, float wpos) noexcept : v{vector[0], vector[1], vector[2], wpos} {}
+#endif
+
+constexpr inline bool QVector4D::isNull() const noexcept
+{
+ return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]) && qIsNull(v[3]);
+}
+
+constexpr inline float QVector4D::x() const noexcept { return v[0]; }
+constexpr inline float QVector4D::y() const noexcept { return v[1]; }
+constexpr inline float QVector4D::z() const noexcept { return v[2]; }
+constexpr inline float QVector4D::w() const noexcept { return v[3]; }
+
+constexpr inline void QVector4D::setX(float aX) noexcept { v[0] = aX; }
+constexpr inline void QVector4D::setY(float aY) noexcept { v[1] = aY; }
+constexpr inline void QVector4D::setZ(float aZ) noexcept { v[2] = aZ; }
+constexpr inline void QVector4D::setW(float aW) noexcept { v[3] = aW; }
+
+constexpr inline float &QVector4D::operator[](int i)
+{
+ Q_ASSERT(uint(i) < 4u);
+ return v[i];
+}
+
+constexpr inline float QVector4D::operator[](int i) const
+{
+ Q_ASSERT(uint(i) < 4u);
+ return v[i];
+}
+
+inline float QVector4D::length() const noexcept
+{
+ return qHypot(v[0], v[1], v[2], v[3]);
+}
+
+constexpr inline float QVector4D::lengthSquared() const noexcept
+{
+ return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
+}
+
+inline QVector4D QVector4D::normalized() const noexcept
+{
+ const float len = length();
+ return qFuzzyIsNull(len - 1.0f) ? *this : qFuzzyIsNull(len) ? QVector4D()
+ : QVector4D(v[0] / len, v[1] / len, v[2] / len, v[3] / len);
+}
+
+inline void QVector4D::normalize() noexcept
+{
+ const float len = length();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ v[0] /= len;
+ v[1] /= len;
+ v[2] /= len;
+ v[3] /= len;
+}
+
+constexpr inline QVector4D &QVector4D::operator+=(QVector4D vector) noexcept
+{
+ v[0] += vector.v[0];
+ v[1] += vector.v[1];
+ v[2] += vector.v[2];
+ v[3] += vector.v[3];
+ return *this;
+}
+
+constexpr inline QVector4D &QVector4D::operator-=(QVector4D vector) noexcept
+{
+ v[0] -= vector.v[0];
+ v[1] -= vector.v[1];
+ v[2] -= vector.v[2];
+ v[3] -= vector.v[3];
+ return *this;
+}
+
+constexpr inline QVector4D &QVector4D::operator*=(float factor) noexcept
+{
+ v[0] *= factor;
+ v[1] *= factor;
+ v[2] *= factor;
+ v[3] *= factor;
+ return *this;
+}
+
+constexpr inline QVector4D &QVector4D::operator*=(QVector4D vector) noexcept
+{
+ v[0] *= vector.v[0];
+ v[1] *= vector.v[1];
+ v[2] *= vector.v[2];
+ v[3] *= vector.v[3];
+ return *this;
+}
+
+constexpr inline QVector4D &QVector4D::operator/=(float divisor)
+{
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ v[0] /= divisor;
+ v[1] /= divisor;
+ v[2] /= divisor;
+ v[3] /= divisor;
+ return *this;
+}
+
+constexpr inline QVector4D &QVector4D::operator/=(QVector4D vector)
+{
+ Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
+ Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
+ Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
+ Q_ASSERT(vector.v[3] > 0 || vector.v[3] < 0);
+ v[0] /= vector.v[0];
+ v[1] /= vector.v[1];
+ v[2] /= vector.v[2];
+ v[3] /= vector.v[3];
+ return *this;
+}
+
+constexpr float QVector4D::dotProduct(QVector4D v1, QVector4D v2) noexcept
+{
+ return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2] + v1.v[3] * v2.v[3];
+}
+
+#ifndef QT_NO_VECTOR2D
+
+constexpr inline QVector2D QVector4D::toVector2D() const noexcept
+{
+ return QVector2D(v[0], v[1]);
+}
+
+constexpr inline QVector2D QVector4D::toVector2DAffine() const noexcept
+{
+ if (qIsNull(v[3]))
+ return QVector2D();
+ return QVector2D(v[0] / v[3], v[1] / v[3]);
+}
+
+#endif // QT_NO_VECTOR2D
+
+#ifndef QT_NO_VECTOR3D
+
+constexpr inline QVector3D QVector4D::toVector3D() const noexcept
+{
+ return QVector3D(v[0], v[1], v[2]);
+}
+
+constexpr QVector3D QVector4D::toVector3DAffine() const noexcept
+{
+ if (qIsNull(v[3]))
+ return QVector3D();
+ return QVector3D(v[0] / v[3], v[1] / v[3], v[2] / v[3]);
+}
+
+#endif // QT_NO_VECTOR3D
+
+constexpr inline QPoint QVector4D::toPoint() const noexcept
+{
+ return QPoint(qRound(v[0]), qRound(v[1]));
+}
+
+constexpr inline QPointF QVector4D::toPointF() const noexcept
+{
+ return QPointF(qreal(v[0]), qreal(v[1]));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, QVector4D vector);
+#endif
+
+#ifndef QT_NO_DATASTREAM
+Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, QVector4D );
+Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector4D &);
+#endif
+
+#endif // QT_NO_VECTOR4D
+
+
+QT_END_NAMESPACE
+
+/***************************** Tuple protocol *****************************/
+
+namespace std {
+#ifndef QT_NO_VECTOR2D
+ template <>
+ class tuple_size<QT_PREPEND_NAMESPACE(QVector2D)> : public integral_constant<size_t, 2> {};
+ template <>
+ class tuple_element<0, QT_PREPEND_NAMESPACE(QVector2D)> { public: using type = float; };
+ template <>
+ class tuple_element<1, QT_PREPEND_NAMESPACE(QVector2D)> { public: using type = float; };
+#endif // QT_NO_VECTOR2D
+
+#ifndef QT_NO_VECTOR3D
+ template <>
+ class tuple_size<QT_PREPEND_NAMESPACE(QVector3D)> : public integral_constant<size_t, 3> {};
+ template <>
+ class tuple_element<0, QT_PREPEND_NAMESPACE(QVector3D)> { public: using type = float; };
+ template <>
+ class tuple_element<1, QT_PREPEND_NAMESPACE(QVector3D)> { public: using type = float; };
+ template <>
+ class tuple_element<2, QT_PREPEND_NAMESPACE(QVector3D)> { public: using type = float; };
+#endif // QT_NO_VECTOR3D
+
+#ifndef QT_NO_VECTOR4D
+ template <>
+ class tuple_size<QT_PREPEND_NAMESPACE(QVector4D)> : public integral_constant<size_t, 4> {};
+ template <>
+ class tuple_element<0, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
+ template <>
+ class tuple_element<1, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
+ template <>
+ class tuple_element<2, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
+ template <>
+ class tuple_element<3, QT_PREPEND_NAMESPACE(QVector4D)> { public: using type = float; };
+#endif // QT_NO_VECTOR4D
+}
+
+#endif // QVECTORND_H