8#include <QtGui/qtguiglobal.h>
9#include <QtCore/qpoint.h>
10#include <QtCore/qrect.h>
11#include <QtCore/qmath.h>
13#include <QtCore/q20type_traits.h>
14#include <QtCore/q23utility.h>
36 constexpr explicit QVector2D(QPoint point)
noexcept;
37 constexpr explicit QVector2D(QPointF point)
noexcept;
45 constexpr bool isNull()
const noexcept;
47 constexpr float x()
const noexcept;
48 constexpr float y()
const noexcept;
50 constexpr void setX(
float x)
noexcept;
51 constexpr void setY(
float y)
noexcept;
54 constexpr float operator[](
int i)
const;
75QT_WARNING_DISABLE_FLOAT_COMPARE
132#ifndef QT_NO_VECTOR3D
135#ifndef QT_NO_VECTOR4D
154 friend constexpr decltype(
auto)
get(
V &&
vec)
noexcept
168#ifndef QT_NO_VECTOR3D
178 constexpr explicit QVector3D(QPointF point)
noexcept;
179#ifndef QT_NO_VECTOR2D
183#ifndef QT_NO_VECTOR4D
187 constexpr bool isNull()
const noexcept;
189 constexpr float x()
const noexcept;
190 constexpr float y()
const noexcept;
191 constexpr float z()
const noexcept;
193 constexpr void setX(
float x)
noexcept;
194 constexpr void setY(
float y)
noexcept;
195 constexpr void setZ(
float z)
noexcept;
198 constexpr float operator[](
int i)
const;
223QT_WARNING_DISABLE_FLOAT_COMPARE
242 return QVector3D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2]);
247 return QVector3D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2]);
252 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
257 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor);
262 return QVector3D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2]);
267 return QVector3D(-vector.v[0], -vector.v[1], -vector.v[2]);
272 Q_ASSERT(divisor < 0 || divisor > 0);
273 return QVector3D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor);
278 Q_ASSERT(divisor.v[0] > 0 || divisor.v[0] < 0);
279 Q_ASSERT(divisor.v[1] > 0 || divisor.v[1] < 0);
280 Q_ASSERT(divisor.v[2] > 0 || divisor.v[2] < 0);
281 return QVector3D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1],
282 vector.v[2] / divisor.v[2]);
287#ifndef QT_NO_VECTOR2D
290#ifndef QT_NO_VECTOR4D
304#ifndef QT_NO_MATRIX4X4
313 friend constexpr decltype(
auto)
get(
V &&
vec)
noexcept
327#ifndef QT_NO_VECTOR4D
335 constexpr explicit QVector4D(QPoint point)
noexcept;
336 constexpr explicit QVector4D(QPointF point)
noexcept;
337#ifndef QT_NO_VECTOR2D
341#ifndef QT_NO_VECTOR3D
346 constexpr bool isNull()
const noexcept;
348 constexpr float x()
const noexcept;
349 constexpr float y()
const noexcept;
350 constexpr float z()
const noexcept;
351 constexpr float w()
const noexcept;
353 constexpr void setX(
float x)
noexcept;
354 constexpr void setY(
float y)
noexcept;
355 constexpr void setZ(
float z)
noexcept;
356 constexpr void setW(
float w)
noexcept;
359 constexpr float operator[](
int i)
const;
377QT_WARNING_DISABLE_FLOAT_COMPARE
436#ifndef QT_NO_VECTOR2D
440#ifndef QT_NO_VECTOR3D
455 friend class QMatrix4x4;
456#ifndef QT_NO_MATRIX4X4
465 friend constexpr decltype(
auto)
get(
V &&
vec)
noexcept
479#ifndef QT_NO_VECTOR2D
483constexpr inline QVector2D::QVector2D(
float xpos,
float ypos)
noexcept : v{xpos, ypos} {}
485constexpr inline QVector2D::
QVector2D(QPoint point)
noexcept : v{
float(point.x()),
float(point.y())} {}
487constexpr inline QVector2D::
QVector2D(QPointF point)
noexcept : v{
float(point.x()),
float(point.y())} {}
489#ifndef QT_NO_VECTOR3D
492#ifndef QT_NO_VECTOR4D
498 return qIsNull(v[0]) && qIsNull(v[1]);
501constexpr inline float QVector2D::
x()
const noexcept {
return v[0]; }
502constexpr inline float QVector2D::
y()
const noexcept {
return v[1]; }
509 Q_ASSERT(uint(i) < 2u);
515 Q_ASSERT(uint(i) < 2u);
521 return qHypot(v[0], v[1]);
526 return v[0] * v[0] + v[1] * v[1];
532 return qFuzzyIsNull(len - 1.0f) ? *
this : qFuzzyIsNull(len) ?
QVector2D()
533 : QVector2D(v[0] / len, v[1] / len);
539 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
548 return (*
this - point).length();
554 return (*
this - point).length();
556 return (*
this - p).length();
589 Q_ASSERT(divisor < 0 || divisor > 0);
597 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
598 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
606 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1];
609#ifndef QT_NO_VECTOR3D
612 return QVector3D(v[0], v[1], 0.0f);
615#ifndef QT_NO_VECTOR4D
618 return QVector4D(v[0], v[1], 0.0f, 0.0f);
625 return QPoint(qRound(v[0]), qRound(v[1]));
630 return QPointF(qreal(v[0]), qreal(v[1]));
633#ifndef QT_NO_DEBUG_STREAM
637#ifndef QT_NO_DATASTREAM
648#ifndef QT_NO_VECTOR3D
652constexpr inline QVector3D::
QVector3D(QPoint point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f} {}
654constexpr inline QVector3D::
QVector3D(QPointF point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f} {}
656#ifndef QT_NO_VECTOR2D
661#ifndef QT_NO_VECTOR4D
667 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]);
670constexpr inline float QVector3D::
x()
const noexcept {
return v[0]; }
671constexpr inline float QVector3D::
y()
const noexcept {
return v[1]; }
672constexpr inline float QVector3D::
z()
const noexcept {
return v[2]; }
680 Q_ASSERT(uint(i) < 3u);
686 Q_ASSERT(uint(i) < 3u);
692 return qHypot(v[0], v[1], v[2]);
698 return qFuzzyIsNull(len - 1.0f) ? *
this : qFuzzyIsNull(len) ?
QVector3D()
699 : QVector3D(v[0] / len, v[1] / len, v[2] / len);
705 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
715 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
752 Q_ASSERT(divisor < 0 || divisor > 0);
761 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
762 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
763 Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
772 return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2];
777 return QVector3D(v1.v[1] * v2.v[2] - v1.v[2] * v2.v[1],
778 v1.v[2] * v2.v[0] - v1.v[0] * v2.v[2],
779 v1.v[0] * v2.v[1] - v1.v[1] * v2.v[0]);
816#ifndef QT_NO_VECTOR2D
819 return QVector2D(v[0], v[1]);
822#ifndef QT_NO_VECTOR4D
825 return QVector4D(v[0], v[1], v[2], 0.0f);
831 return QPoint(qRound(v[0]), qRound(v[1]));
836 return QPointF(qreal(v[0]), qreal(v[1]));
839#ifndef QT_NO_DEBUG_STREAM
843#ifndef QT_NO_DATASTREAM
854#ifndef QT_NO_VECTOR4D
858constexpr inline QVector4D::QVector4D(
float xpos,
float ypos,
float zpos,
float wpos)
noexcept : v{xpos, ypos, zpos, wpos} {}
860constexpr inline QVector4D::
QVector4D(QPoint point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f, 0.0f} {}
862constexpr inline QVector4D::
QVector4D(QPointF point)
noexcept : v{
float(point.x()),
float(point.y()), 0.0f, 0.0f} {}
864#ifndef QT_NO_VECTOR2D
868#ifndef QT_NO_VECTOR3D
875 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]) && qIsNull(v[3]);
878constexpr inline float QVector4D::
x()
const noexcept {
return v[0]; }
879constexpr inline float QVector4D::
y()
const noexcept {
return v[1]; }
880constexpr inline float QVector4D::
z()
const noexcept {
return v[2]; }
881constexpr inline float QVector4D::
w()
const noexcept {
return v[3]; }
890 Q_ASSERT(uint(i) < 4u);
896 Q_ASSERT(uint(i) < 4u);
902 return qHypot(v[0], v[1], v[2], v[3]);
907 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
913 return qFuzzyIsNull(len - 1.0f) ? *
this : qFuzzyIsNull(len) ?
QVector4D()
914 : QVector4D(v[0] / len, v[1] / len, v[2] / len, v[3] / len);
920 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
967 Q_ASSERT(divisor < 0 || divisor > 0);
977 Q_ASSERT(vector.v[0] > 0 || vector.v[0] < 0);
978 Q_ASSERT(vector.v[1] > 0 || vector.v[1] < 0);
979 Q_ASSERT(vector.v[2] > 0 || vector.v[2] < 0);
980 Q_ASSERT(vector.v[3] > 0 || vector.v[3] < 0);
990 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];
993#ifndef QT_NO_VECTOR2D
997 return QVector2D(v[0], v[1]);
1004 return QVector2D(v[0] / v[3], v[1] / v[3]);
1009#ifndef QT_NO_VECTOR3D
1013 return QVector3D(v[0], v[1], v[2]);
1020 return QVector3D(v[0] / v[3], v[1] / v[3], v[2] / v[3]);
1027 return QPoint(qRound(v[0]), qRound(v[1]));
1032 return QPointF(qreal(v[0]), qreal(v[1]));
1035#ifndef QT_NO_DEBUG_STREAM
1039#ifndef QT_NO_DATASTREAM
1052#ifndef QT_NO_VECTOR2D
1061#ifndef QT_NO_VECTOR3D
1072#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)