9#include <QtGui/qtguiglobal.h>
10#include <QtCore/qpoint.h>
11#include <QtCore/qrect.h>
12#include <QtCore/qmath.h>
14#include <QtCore/q20type_traits.h>
15#include <QtCore/q23utility.h>
37 constexpr explicit QVector2D(QPoint point)
noexcept;
38 constexpr explicit QVector2D(QPointF point)
noexcept;
46 constexpr bool isNull()
const noexcept;
48 constexpr float x()
const noexcept;
49 constexpr float y()
const noexcept;
51 constexpr void setX(
float x)
noexcept;
52 constexpr void setY(
float y)
noexcept;
55 constexpr float operator[](
int i)
const;
57 [[nodiscard]]
float length()
const noexcept;
76QT_WARNING_DISABLE_FLOAT_COMPARE
133#ifndef QT_NO_VECTOR3D
136#ifndef QT_NO_VECTOR4D
155 friend constexpr decltype(
auto)
get(
V &&
vec)
noexcept
169#ifndef QT_NO_VECTOR3D
179 constexpr explicit QVector3D(QPointF point)
noexcept;
180#ifndef QT_NO_VECTOR2D
184#ifndef QT_NO_VECTOR4D
188 constexpr bool isNull()
const noexcept;
190 constexpr float x()
const noexcept;
191 constexpr float y()
const noexcept;
192 constexpr float z()
const noexcept;
194 constexpr void setX(
float x)
noexcept;
195 constexpr void setY(
float y)
noexcept;
196 constexpr void setZ(
float z)
noexcept;
199 constexpr float operator[](
int i)
const;
201 [[nodiscard]]
float length()
const noexcept;
202 [[nodiscard]]
constexpr float lengthSquared()
const noexcept;
224QT_WARNING_DISABLE_FLOAT_COMPARE
243 return QVector3D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2]);
248 return QVector3D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2]);
253 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
258 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
263 return QVector3D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2]);
268 return QVector3D(-vector.v[0], -vector.v[1], -vector.v[2]);
273 Q_ASSERT(divisor < 0 || divisor > 0);
274 return QVector3D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor);
279 Q_ASSERT(divisor.v[0] > 0 || divisor.v[0] < 0);
280 Q_ASSERT(divisor.v[1] > 0 || divisor.v[1] < 0);
281 Q_ASSERT(divisor.v[2] > 0 || divisor.v[2] < 0);
282 return QVector3D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1],
283 vector.v[2] / divisor.v[2]);
288#ifndef QT_NO_VECTOR2D
291#ifndef QT_NO_VECTOR4D
305#ifndef QT_NO_MATRIX4X4
314 friend constexpr decltype(
auto)
get(
V &&
vec)
noexcept
328#ifndef QT_NO_VECTOR4D
336 constexpr explicit QVector4D(QPoint point)
noexcept;
337 constexpr explicit QVector4D(QPointF point)
noexcept;
338#ifndef QT_NO_VECTOR2D
342#ifndef QT_NO_VECTOR3D
347 constexpr bool isNull()
const noexcept;
349 constexpr float x()
const noexcept;
350 constexpr float y()
const noexcept;
351 constexpr float z()
const noexcept;
352 constexpr float w()
const noexcept;
354 constexpr void setX(
float x)
noexcept;
355 constexpr void setY(
float y)
noexcept;
356 constexpr void setZ(
float z)
noexcept;
357 constexpr void setW(
float w)
noexcept;
360 constexpr float operator[](
int i)
const;
362 [[nodiscard]]
float length()
const noexcept;
363 [[nodiscard]]
constexpr float lengthSquared()
const noexcept;
378QT_WARNING_DISABLE_FLOAT_COMPARE
437#ifndef QT_NO_VECTOR2D
441#ifndef QT_NO_VECTOR3D
456 friend class QMatrix4x4;
457#ifndef QT_NO_MATRIX4X4
466 friend constexpr decltype(
auto)
get(
V &&
vec)
noexcept
480#ifndef QT_NO_VECTOR2D
484constexpr inline QVector2D::QVector2D(
float xpos,
float ypos)
noexcept : v{xpos, ypos} {}
486constexpr inline QVector2D::
QVector2D(QPoint point)
noexcept : v{
float(point.x()),
float(point.y())} {}
488constexpr inline QVector2D::
QVector2D(QPointF point)
noexcept : v{
float(point.x()),
float(point.y())} {}
490#ifndef QT_NO_VECTOR3D
493#ifndef QT_NO_VECTOR4D
499 return qIsNull(v[0]) && qIsNull(v[1]);
502constexpr inline float QVector2D::
x()
const noexcept {
return v[0]; }
503constexpr inline float QVector2D::
y()
const noexcept {
return v[1]; }
510 Q_ASSERT(uint(i) < 2u);
516 Q_ASSERT(uint(i) < 2u);
522 return qHypot(v[0], v[1]);
527 return v[0] * v[0] + v[1] * v[1];
533 return qFuzzyIsNull(len - 1.0f) ? *
this : qFuzzyIsNull(len) ?
QVector2D()
534 : QVector2D(v[0] / len, v[1] / len);
540 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
549 return (*
this - point).length();
555 return (*
this - point).length();
557 return (*
this - p).length();
590 Q_ASSERT(divisor < 0 || divisor > 0);
598 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
599 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
607 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1];
610#ifndef QT_NO_VECTOR3D
613 return QVector3D(v[0], v[1], 0.0f);
616#ifndef QT_NO_VECTOR4D
619 return QVector4D(v[0], v[1], 0.0f, 0.0f);
626 return QPoint(qRound(v[0]), qRound(v[1]));
631 return QPointF(qreal(v[0]), qreal(v[1]));
634#ifndef QT_NO_DEBUG_STREAM
638#ifndef QT_NO_DATASTREAM
649#ifndef QT_NO_VECTOR3D
653constexpr inline QVector3D::
QVector3D(QPoint point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f} {}
655constexpr inline QVector3D::
QVector3D(QPointF point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f} {}
657#ifndef QT_NO_VECTOR2D
662#ifndef QT_NO_VECTOR4D
668 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]);
671constexpr inline float QVector3D::
x()
const noexcept {
return v[0]; }
672constexpr inline float QVector3D::
y()
const noexcept {
return v[1]; }
673constexpr inline float QVector3D::
z()
const noexcept {
return v[2]; }
681 Q_ASSERT(uint(i) < 3u);
687 Q_ASSERT(uint(i) < 3u);
693 return qHypot(v[0], v[1], v[2]);
699 return qFuzzyIsNull(len - 1.0f) ? *
this : qFuzzyIsNull(len) ?
QVector3D()
700 : QVector3D(v[0] / len, v[1] / len, v[2] / len);
706 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
716 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
753 Q_ASSERT(divisor < 0 || divisor > 0);
762 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
763 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
764 Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
773 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2];
778 return QVector3D(v1.v[1] * v2.v[2] - v1.v[2] * v2.v[1],
779 v1.v[2] * v2.v[0] - v1.v[0] * v2.v[2],
780 v1.v[0] * v2.v[1] - v1.v[1] * v2.v[0]);
817#ifndef QT_NO_VECTOR2D
820 return QVector2D(v[0], v[1]);
823#ifndef QT_NO_VECTOR4D
826 return QVector4D(v[0], v[1], v[2], 0.0f);
832 return QPoint(qRound(v[0]), qRound(v[1]));
837 return QPointF(qreal(v[0]), qreal(v[1]));
840#ifndef QT_NO_DEBUG_STREAM
844#ifndef QT_NO_DATASTREAM
855#ifndef QT_NO_VECTOR4D
859constexpr inline QVector4D::QVector4D(
float xpos,
float ypos,
float zpos,
float wpos)
noexcept : v{xpos, ypos, zpos, wpos} {}
861constexpr inline QVector4D::
QVector4D(QPoint point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f, 0.0f} {}
863constexpr inline QVector4D::
QVector4D(QPointF point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f, 0.0f} {}
865#ifndef QT_NO_VECTOR2D
869#ifndef QT_NO_VECTOR3D
876 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]) && qIsNull(v[3]);
879constexpr inline float QVector4D::
x()
const noexcept {
return v[0]; }
880constexpr inline float QVector4D::
y()
const noexcept {
return v[1]; }
881constexpr inline float QVector4D::
z()
const noexcept {
return v[2]; }
882constexpr inline float QVector4D::
w()
const noexcept {
return v[3]; }
891 Q_ASSERT(uint(i) < 4u);
897 Q_ASSERT(uint(i) < 4u);
903 return qHypot(v[0], v[1], v[2], v[3]);
908 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
914 return qFuzzyIsNull(len - 1.0f) ? *
this : qFuzzyIsNull(len) ?
QVector4D()
915 : QVector4D(v[0] / len, v[1] / len, v[2] / len, v[3] / len);
921 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
968 Q_ASSERT(divisor < 0 || divisor > 0);
978 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
979 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
980 Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
981 Q_ASSERT(vector.v[3] > 0 || vector.v[3] < 0);
991 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];
994#ifndef QT_NO_VECTOR2D
998 return QVector2D(v[0], v[1]);
1005 return QVector2D(v[0] / v[3], v[1] / v[3]);
1010#ifndef QT_NO_VECTOR3D
1014 return QVector3D(v[0], v[1], v[2]);
1021 return QVector3D(v[0] / v[3], v[1] / v[3], v[2] / v[3]);
1028 return QPoint(qRound(v[0]), qRound(v[1]));
1033 return QPointF(qreal(v[0]), qreal(v[1]));
1036#ifndef QT_NO_DEBUG_STREAM
1040#ifndef QT_NO_DATASTREAM
1053#ifndef QT_NO_VECTOR2D
1062#ifndef QT_NO_VECTOR3D
1073#ifndef QT_NO_VECTOR4D
\inmodule QtCore\reentrant
The QVector2D class represents a vector or vertex in 2D space.
float length() const noexcept
Returns the length of the vector from the origin.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr QVector2D(QPoint point) noexcept
Constructs a vector with x and y coordinates from a 2D point.
constexpr float & operator[](int i)
QVector2D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
constexpr QVector3D toVector3D() const noexcept
Returns the 3D form of this 2D vector, with the z coordinate set to zero.
constexpr QVector2D & operator*=(float factor) noexcept
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vecto...
constexpr QVector2D & operator+=(QVector2D vector) noexcept
Adds the given vector to this vector and returns a reference to this vector.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr QVector2D(QVector4D vector) noexcept
Constructs a vector with x and y coordinates from a 3D vector.
static constexpr float dotProduct(QVector2D v1, QVector2D v2) noexcept
Returns the dot product of v1 and v2.
constexpr QVector2D & operator*=(QVector2D vector) noexcept
Multiplies each component of this vector by the corresponding component of vector and returns a refer...
constexpr QVector2D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor and returns a reference to this vector.
float distanceToPoint(QVector2D point) const noexcept
constexpr QVector2D() noexcept
Constructs a null vector, i.e.
constexpr QVector2D & operator-=(QVector2D vector) noexcept
Subtracts the given vector from this vector and returns a reference to this vector.
constexpr float operator[](int i) const
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
constexpr QPointF toPointF() const noexcept
Returns the QPointF form of this 2D vector.
constexpr QVector2D(QVector3D vector) noexcept
Constructs a vector with x and y coordinates from a 3D vector.
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
constexpr QPoint toPoint() const noexcept
Returns the QPoint form of this 2D vector.
constexpr QVector4D toVector4D() const noexcept
Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
void normalize() noexcept
Normalizes the current vector in place.
float distanceToLine(QVector2D point, QVector2D direction) const noexcept
constexpr bool isNull() const noexcept
Returns true if the x and y coordinates are set to 0.0, otherwise returns false.
constexpr QVector2D & operator/=(QVector2D vector)
The QVector3D class represents a vector or vertex in 3D space.
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
float distanceToLine(QVector3D point, QVector3D direction) const noexcept
Returns the distance that this vertex is from a line defined by point and the unit vector direction.
constexpr bool isNull() const noexcept
Returns true if the x, y, and z coordinates are set to 0.0, otherwise returns false.
constexpr QVector3D & operator*=(float factor) noexcept
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vecto...
constexpr float distanceToPlane(QVector3D plane, QVector3D normal) const noexcept
Returns the distance from this vertex to a plane defined by the vertex plane and a normal unit vector...
static QVector3D normal(QVector3D v1, QVector3D v2) noexcept
Returns the unit normal vector of a plane spanned by vectors v1 and v2, which must not be parallel to...
float length() const noexcept
Returns the length of the vector from the origin.
constexpr friend QVector3D operator*(QVector3D v1, QVector3D v2) noexcept
//!
constexpr friend QVector3D operator+(QVector3D v1, QVector3D v2) noexcept
//!
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
constexpr friend QVector3D operator*(QVector3D vector, float factor) noexcept
//!
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
static QVector3D normal(QVector3D v1, QVector3D v2, QVector3D v3) noexcept
Returns the unit normal vector of a plane spanned by vectors v2 - v1 and v3 - v1, which must not be p...
friend QVector3D operator*(const QVector3D &vector, const QMatrix4x4 &matrix)
constexpr float & operator[](int i)
constexpr QPoint toPoint() const noexcept
Returns the QPoint form of this 3D vector.
constexpr QPointF toPointF() const noexcept
Returns the QPointF form of this 3D vector.
constexpr QVector3D & operator-=(QVector3D vector) noexcept
Subtracts the given vector from this vector and returns a reference to this vector.
constexpr friend QVector3D operator-(QVector3D vector) noexcept
//!
constexpr QVector3D(QVector4D vector) noexcept
Constructs a 3D vector from the specified 4D vector.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr QVector2D toVector2D() const noexcept
Returns the 2D vector form of this 3D vector, dropping the z coordinate.
constexpr float operator[](int i) const
constexpr friend QVector3D operator/(QVector3D vector, float divisor)
//!
constexpr friend QVector3D operator/(QVector3D vector, QVector3D divisor)
//!
constexpr QVector4D toVector4D() const noexcept
Returns the 4D form of this 3D vector, with the w coordinate set to zero.
constexpr QVector3D(QPointF point) noexcept
Constructs a vector with x and y coordinates from a 2D point, and a z coordinate of 0.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr QVector3D(QVector2D vector, float zpos) noexcept
Constructs a 3D vector from the specified 2D vector.
constexpr QVector3D & operator*=(QVector3D vector) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
constexpr QVector3D & operator/=(QVector3D vector)
friend QVector3D operator*(const QMatrix4x4 &matrix, const QVector3D &vector)
constexpr QVector3D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
float distanceToPlane(QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept
Returns the distance from this vertex to a plane defined by the vertices plane1, plane2 and plane3.
constexpr QVector3D() noexcept
Constructs a null vector, i.e.
constexpr QVector3D & operator+=(QVector3D vector) noexcept
Adds the given vector to this vector and returns a reference to this vector.
static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2.
constexpr QVector3D(QVector2D vector) noexcept
Constructs a 3D vector from the specified 2D vector.
constexpr friend QVector3D operator*(float factor, QVector3D vector) noexcept
//!
void normalize() noexcept
Normalizes the current vector in place.
constexpr friend QVector3D operator-(QVector3D v1, QVector3D v2) noexcept
//!
constexpr float z() const noexcept
Returns the z coordinate of this point.
The QVector4D class represents a vector or vertex in 4D space.
constexpr QVector4D & operator-=(QVector4D vector) noexcept
Subtracts the given vector from this vector and returns a reference to this vector.
constexpr QVector4D(QVector2D vector) noexcept
Constructs a 4D vector from the specified 2D vector.
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
QVector4D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
constexpr QVector4D & operator*=(float factor) noexcept
Multiplies this vector's coordinates by the given finite factor, and returns a reference to this vect...
constexpr bool isNull() const noexcept
Returns true if the x, y, z, and w coordinates are set to 0.0, otherwise returns false.
constexpr float x() const noexcept
Returns the x coordinate of this point.
float length() const noexcept
Returns the length of the vector from the origin.
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
constexpr float w() const noexcept
Returns the w coordinate of this point.
friend QVector4D operator*(const QVector4D &vector, const QMatrix4x4 &matrix)
constexpr QVector4D(QPoint point) noexcept
Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0.
constexpr QVector2D toVector2D() const noexcept
Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
constexpr QVector2D toVector2DAffine() const noexcept
Returns the 2D vector form of this 4D vector, dividing the x and y coordinates by the w coordinate an...
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
constexpr QVector4D & operator/=(QVector4D vector)
friend QVector4D operator*(const QMatrix4x4 &matrix, const QVector4D &vector)
constexpr QVector4D(QVector3D vector) noexcept
Constructs a 4D vector from the specified 3D vector.
constexpr QVector4D & operator+=(QVector4D vector) noexcept
Adds the given vector to this vector and returns a reference to this vector.
void normalize() noexcept
Normalizes the current vector in place.
constexpr QVector4D & operator/=(float divisor)
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
constexpr float operator[](int i) const
constexpr QVector4D(QVector3D vector, float wpos) noexcept
Constructs a 4D vector from the specified 3D vector.
constexpr QVector4D & operator*=(QVector4D vector) noexcept
Multiplies each component of this vector by the corresponding component of vector and returns a refer...
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr QPointF toPointF() const noexcept
Returns the QPointF form of this 4D vector.
constexpr QVector4D(QVector2D vector, float zpos, float wpos) noexcept
Constructs a 4D vector from the specified 2D vector.
static constexpr float dotProduct(QVector4D v1, QVector4D v2) noexcept
Returns the dot product of v1 and v2.
constexpr float & operator[](int i)
constexpr QPoint toPoint() const noexcept
Returns the QPoint form of this 4D vector.
constexpr QVector3D toVector3D() const noexcept
Returns the 3D vector form of this 4D vector, dropping the w coordinate.
constexpr QVector4D() noexcept
Constructs a null vector, i.e.
constexpr float z() const noexcept
Returns the z coordinate of this point.
constexpr void setW(float w) noexcept
Sets the w coordinate of this point to the given finite w coordinate.
constexpr QVector3D toVector3DAffine() const noexcept
Returns the 3D vector form of this 4D vector, dividing the x, y, and z coordinates by the w coordinat...
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
QDataStream & operator<<(QDataStream &stream, QVector2D vector)
QDataStream & operator<<(QDataStream &stream, QVector3D vector)
QDataStream & operator>>(QDataStream &stream, QVector2D &vector)
QDataStream & operator<<(QDataStream &stream, QVector4D vector)
QDebug operator<<(QDebug dbg, QVector2D vector)
bool qFuzzyCompare(QVector4D v1, QVector4D v2) noexcept
bool qFuzzyCompare(QVector3D v1, QVector3D v2) noexcept
QDebug operator<<(QDebug dbg, QVector4D vector)
QDebug operator<<(QDebug dbg, QVector3D vector)
QDataStream & operator>>(QDataStream &stream, QVector3D &vector)
QDataStream & operator>>(QDataStream &stream, QVector4D &vector)
bool qFuzzyCompare(QVector2D v1, QVector2D v2) noexcept
Q_DECLARE_TYPEINFO(QVector3D, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QVector4D, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QVector2D, Q_PRIMITIVE_TYPE)