![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QVector2D class represents a vector or vertex in 2D space. More...
#include <qvectornd.h>
Public Member Functions | |
constexpr | QVector2D () noexcept |
Constructs a null vector, i.e. | |
QVector2D (Qt::Initialization) noexcept | |
constexpr | QVector2D (float xpos, float ypos) noexcept |
Constructs a vector with coordinates (xpos, ypos). | |
constexpr | QVector2D (QPoint point) noexcept |
Constructs a vector with x and y coordinates from a 2D point. | |
constexpr | QVector2D (QPointF point) noexcept |
Constructs a vector with x and y coordinates from a 2D point. | |
constexpr | QVector2D (QVector3D vector) noexcept |
Constructs a vector with x and y coordinates from a 3D vector. | |
constexpr | QVector2D (QVector4D vector) noexcept |
Constructs a vector with x and y coordinates from a 3D vector. | |
constexpr bool | isNull () const noexcept |
Returns true if the x and y coordinates are set to 0.0, otherwise returns false . | |
constexpr float | x () const noexcept |
Returns the x coordinate of this point. | |
constexpr float | y () const noexcept |
Returns the y coordinate of this point. | |
constexpr void | setX (float x) noexcept |
Sets the x coordinate of this point to the given finite x coordinate. | |
constexpr void | setY (float y) noexcept |
Sets the y coordinate of this point to the given finite y coordinate. | |
constexpr float & | operator[] (int i) |
constexpr float | operator[] (int i) const |
float | length () const noexcept |
Returns the length of the vector from the origin. | |
constexpr float | lengthSquared () const noexcept |
Returns the squared length of the vector from the origin. | |
QVector2D | normalized () const noexcept |
Returns the normalized unit vector form of this vector. | |
void | normalize () noexcept |
Normalizes the current vector in place. | |
float | distanceToPoint (QVector2D point) const noexcept |
float | distanceToLine (QVector2D point, QVector2D direction) const noexcept |
constexpr QVector2D & | operator+= (QVector2D vector) noexcept |
Adds the given vector to this vector and returns a reference to this vector. | |
constexpr QVector2D & | operator-= (QVector2D vector) noexcept |
Subtracts the given vector from this vector and returns a reference to this vector. | |
constexpr QVector2D & | operator*= (float factor) noexcept |
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vector. | |
constexpr QVector2D & | operator*= (QVector2D vector) noexcept |
Multiplies each component of this vector by the corresponding component of vector and returns a reference to this vector. | |
constexpr QVector2D & | operator/= (float divisor) |
Divides this vector's coordinates by the given divisor and returns a reference to this vector. | |
constexpr QVector2D & | operator/= (QVector2D vector) |
constexpr QVector3D | toVector3D () const noexcept |
Returns the 3D form of this 2D vector, with the z coordinate set to zero. | |
constexpr QVector4D | toVector4D () const noexcept |
Returns the 4D form of this 2D vector, with the z and w coordinates set to zero. | |
constexpr QPoint | toPoint () const noexcept |
Returns the QPoint form of this 2D vector. | |
constexpr QPointF | toPointF () const noexcept |
Returns the QPointF form of this 2D vector. | |
Q_GUI_EXPORT | operator QVariant () const |
Returns the 2D vector as a QVariant. | |
Static Public Member Functions | |
static constexpr float | dotProduct (QVector2D v1, QVector2D v2) noexcept |
Returns the dot product of v1 and v2. | |
Friends | |
class | QVector3D |
class | QVector4D |
QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr friend bool | operator== (QVector2D v1, QVector2D v2) noexcept |
Returns true if v1 is equal to v2; otherwise returns false . | |
constexpr friend bool | operator!= (QVector2D v1, QVector2D v2) noexcept |
Returns true if v1 is not equal to v2; otherwise returns false . | |
QT_WARNING_POP constexpr friend QVector2D | operator+ (QVector2D v1, QVector2D v2) noexcept |
//! | |
constexpr friend QVector2D | operator- (QVector2D v1, QVector2D v2) noexcept |
//! | |
constexpr friend QVector2D | operator* (float factor, QVector2D vector) noexcept |
//! | |
constexpr friend QVector2D | operator* (QVector2D vector, float factor) noexcept |
//! | |
constexpr friend QVector2D | operator* (QVector2D v1, QVector2D v2) noexcept |
//! | |
constexpr friend QVector2D | operator- (QVector2D vector) noexcept |
//! | |
constexpr friend QVector2D | operator/ (QVector2D vector, float divisor) |
//! | |
constexpr friend QVector2D | operator/ (QVector2D vector, QVector2D divisor) |
//! | |
Q_GUI_EXPORT bool | qFuzzyCompare (QVector2D v1, QVector2D v2) |
//! | |
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> | |
constexpr decltype(auto) | get (V &&vec) noexcept |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &stream, QVector2D vector) |
Writes the given vector to the given stream and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &stream, QVector2D &vector) |
Reads a 2D vector from the given stream into the given vector and returns a reference to the stream. | |
The QVector2D class represents a vector or vertex in 2D space.
\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.
Definition at line 30 of file qvectornd.h.
|
inlineconstexprnoexcept |
Constructs a null vector, i.e.
with coordinates (0, 0).
Definition at line 481 of file qvectornd.h.
Referenced by normalized(), and QVector4D::toVector2DAffine().
|
inlineexplicitnoexcept |
Constructs a vector without initializing the contents.
Definition at line 34 of file qvectornd.h.
|
inlineconstexprnoexcept |
Constructs a vector with coordinates (xpos, ypos).
Both coordinates must be finite.
Definition at line 483 of file qvectornd.h.
|
inlineexplicitconstexprnoexcept |
Constructs a vector with x and y coordinates from a 2D point.
Definition at line 485 of file qvectornd.h.
|
inlineexplicitconstexprnoexcept |
Constructs a vector with x and y coordinates from a 2D point.
Definition at line 487 of file qvectornd.h.
|
inlineexplicitconstexprnoexcept |
Constructs a vector with x and y coordinates from a 3D vector.
The z coordinate of vector is dropped.
Definition at line 490 of file qvectornd.h.
References QVector3D::operator[]().
|
inlineexplicitconstexprnoexcept |
Constructs a vector with x and y coordinates from a 3D vector.
The z and w coordinates of vector are dropped.
Definition at line 493 of file qvectornd.h.
References QVector4D::operator[]().
|
inlinenodiscardnoexcept |
Returns the distance that this vertex is from a line defined by point and the unit vector direction.
If direction is a null vector, then it does not define a line. In that case, the distance from point to this vertex is returned.
Definition at line 551 of file qvectornd.h.
References dotProduct(), and isNull().
|
inlinenodiscardnoexcept |
Returns the distance from this vertex to a point defined by the vertex point.
Definition at line 546 of file qvectornd.h.
Returns the dot product of v1 and v2.
Definition at line 604 of file qvectornd.h.
Referenced by distanceToLine().
|
inlineconstexprnoexcept |
Returns true
if the x and y coordinates are set to 0.0, otherwise returns false
.
Definition at line 496 of file qvectornd.h.
Referenced by distanceToLine().
|
inlinenodiscardnoexcept |
Returns the length of the vector from the origin.
Definition at line 519 of file qvectornd.h.
Referenced by normalize(), and normalized().
|
inlinenodiscardconstexprnoexcept |
Returns the squared length of the vector from the origin.
This is equivalent to the dot product of the vector with itself.
Definition at line 524 of file qvectornd.h.
|
inlinenoexcept |
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.
Definition at line 536 of file qvectornd.h.
References length().
|
inlinenodiscardnoexcept |
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.
Definition at line 529 of file qvectornd.h.
References QVector2D(), and length().
QVector2D::operator QVariant | ( | ) | const |
Returns the 2D vector as a QVariant.
Definition at line 421 of file qvectornd.cpp.
|
inlineconstexprnoexcept |
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vector.
Definition at line 573 of file qvectornd.h.
Multiplies each component of this vector by the corresponding component of vector and returns a reference to this vector.
Definition at line 580 of file qvectornd.h.
Adds the given vector to this vector and returns a reference to this vector.
Definition at line 559 of file qvectornd.h.
Subtracts the given vector from this vector and returns a reference to this vector.
Definition at line 566 of file qvectornd.h.
|
inlineconstexpr |
Divides this vector's coordinates by the given divisor and returns a reference to this vector.
The divisor must not be either zero or NaN.
Definition at line 587 of file qvectornd.h.
Divides each component of this vector by the corresponding component of vector and returns a reference to this vector.
The vector must have no component that is either zero or NaN.
Definition at line 595 of file qvectornd.h.
|
inlineconstexpr |
Returns the component of the vector at index position i as a modifiable reference.
i must be a valid index position in the vector (i.e., 0 <= i < 2).
Definition at line 507 of file qvectornd.h.
Referenced by QVector3D::QVector3D(), QVector3D::QVector3D(), QVector4D::QVector4D(), and QVector4D::QVector4D().
|
inlineconstexpr |
Returns the component of the vector at index position i.
i must be a valid index position in the vector (i.e., 0 <= i < 2).
Definition at line 513 of file qvectornd.h.
|
inlineconstexprnoexcept |
Sets the x coordinate of this point to the given finite x coordinate.
Definition at line 504 of file qvectornd.h.
Referenced by operator>>().
|
inlineconstexprnoexcept |
Sets the y coordinate of this point to the given finite y coordinate.
Definition at line 505 of file qvectornd.h.
Referenced by operator>>().
|
inlineconstexprnoexcept |
Returns the QPoint form of this 2D vector.
Each coordinate is rounded to the nearest integer.
Definition at line 623 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the QPointF form of this 2D vector.
Definition at line 628 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the 3D form of this 2D vector, with the z coordinate set to zero.
Definition at line 610 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
Definition at line 616 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the x coordinate of this point.
Definition at line 501 of file qvectornd.h.
Referenced by operator<<(), and operator<<().
|
inlineconstexprnoexcept |
Returns the y coordinate of this point.
Definition at line 502 of file qvectornd.h.
Referenced by operator<<(), and operator<<().
|
friend |
Definition at line 154 of file qvectornd.h.
Returns true
if v1 is not equal to v2; otherwise returns false
.
This operator uses an exact floating-point comparison.
Definition at line 81 of file qvectornd.h.
//!
friend
Returns a copy of the given vector, multiplied by the given finite factor.
Definition at line 97 of file qvectornd.h.
//!
friend
Returns the QVector2D object formed by multiplying each component of v1 by the corresponding component of v2.
Definition at line 107 of file qvectornd.h.
//!
friend
Returns a copy of the given vector, multiplied by the given finite factor.
Definition at line 102 of file qvectornd.h.
|
friend |
//!
friend
Returns a QVector2D object that is the sum of the given vectors, v1 and v2; each component is added separately.
Definition at line 87 of file qvectornd.h.
//!
friend
Returns a QVector2D object that is formed by subtracting v2 from v1; each component is subtracted separately.
Definition at line 92 of file qvectornd.h.
//!
friend
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QVector2D object that is formed by changing the sign of each component of the given vector.
Equivalent to {QVector2D(0,0)
- vector}.
Definition at line 112 of file qvectornd.h.
//!
friend
Returns the QVector2D object formed by dividing each component of the given vector by the given divisor.
The divisor must not be either zero or NaN.
Definition at line 117 of file qvectornd.h.
//!
friend
Returns the QVector2D object formed by dividing each component of the given vector by the corresponding component of the given divisor.
The divisor must have no component that is either zero or NaN.
Definition at line 123 of file qvectornd.h.
|
|
friend |
Returns true
if v1 is equal to v2; otherwise returns false
.
This operator uses an exact floating-point comparison.
Definition at line 76 of file qvectornd.h.
|
//!
friend
Returns true
if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
Definition at line 376 of file qvectornd.cpp.
|
friend |
Definition at line 147 of file qvectornd.h.
|
friend |
Definition at line 148 of file qvectornd.h.