QtBase
v6.3.1
|
The QPoint class defines a point in the plane using integer precision. More...
#include <qpoint.h>
Public Member Functions | |
constexpr | QPoint () noexcept |
constexpr | QPoint (int xpos, int ypos) noexcept |
constexpr bool | isNull () const noexcept |
constexpr int | x () const noexcept |
constexpr int | y () const noexcept |
constexpr void | setX (int x) noexcept |
constexpr void | setY (int y) noexcept |
constexpr int | manhattanLength () const |
constexpr QPoint | transposed () const noexcept |
constexpr int & | rx () noexcept |
constexpr int & | ry () noexcept |
constexpr QPoint & | operator+= (const QPoint &p) |
constexpr QPoint & | operator-= (const QPoint &p) |
constexpr QPoint & | operator*= (float factor) |
constexpr QPoint & | operator*= (double factor) |
constexpr QPoint & | operator*= (int factor) |
constexpr QPoint & | operator/= (qreal divisor) |
Static Public Member Functions | |
constexpr static int | dotProduct (const QPoint &p1, const QPoint &p2) |
Friends | |
class | QTransform |
constexpr friend bool | operator== (const QPoint &p1, const QPoint &p2) noexcept |
constexpr friend bool | operator!= (const QPoint &p1, const QPoint &p2) noexcept |
constexpr friend QPoint | operator+ (const QPoint &p1, const QPoint &p2) noexcept |
constexpr friend QPoint | operator- (const QPoint &p1, const QPoint &p2) noexcept |
constexpr friend QPoint | operator* (const QPoint &p, float factor) |
constexpr friend QPoint | operator* (const QPoint &p, double factor) |
constexpr friend QPoint | operator* (const QPoint &p, int factor) noexcept |
constexpr friend QPoint | operator* (float factor, const QPoint &p) |
constexpr friend QPoint | operator* (double factor, const QPoint &p) |
constexpr friend QPoint | operator* (int factor, const QPoint &p) noexcept |
constexpr friend QPoint | operator+ (const QPoint &p) noexcept |
constexpr friend QPoint | operator- (const QPoint &p) noexcept |
constexpr friend QPoint | operator/ (const QPoint &p, qreal c) |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QPoint &point) |
QDataStream & | operator>> (QDataStream &stream, QPoint &point) |
The QPoint class defines a point in the plane using integer precision.
\inmodule QtCore
\reentrant
A point is specified by a x coordinate and an y coordinate which can be accessed using the x() and y() functions. The isNull() function returns true
if both x and y are set to 0. The coordinates can be set (or altered) using the setX() and setY() functions, or alternatively the rx() and ry() functions which return references to the coordinates (allowing direct manipulation).
Given a point p, the following statements are all equivalent:
A QPoint object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). A QPoint object can also be divided or multiplied by an int
or a qreal
.
In addition, the QPoint class provides the manhattanLength() function which gives an inexpensive approximation of the length of the QPoint object interpreted as a vector. Finally, QPoint objects can be streamed as well as compared.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" of the vector from the origin to the point. For example:
This is a useful, and quick to calculate, approximation to the true length:
The tradition of "Manhattan length" arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.
Definition at line 175 of file qpoint.h.
|
inlineconstexpr |
Multiplies this point's coordinates by the given factor, and returns a reference to this point. For example:
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
Definition at line 211 of file qpoint.h.
|
inlineconstexpr |
Multiplies this point's coordinates by the given factor, and returns a reference to this point.
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
Definition at line 204 of file qpoint.h.
|
inlineconstexpr |
Multiplies this point's coordinates by the given factor, and returns a reference to this point.
Adds the given point to this point and returns a reference to this point. For example:
Subtracts the given point from this point and returns a reference to this point. For example:
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Divides both x and y by the given divisor, and returns a reference to this point. For example:
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
Definition at line 225 of file qpoint.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
friend |
Returns a copy of the given point multiplied by the given factor.
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
Returns a copy of the given point multiplied by the given factor.
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
Returns a copy of the given point multiplied by the given factor.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a copy of the given point multiplied by the given factor.
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a copy of the given point multiplied by the given factor.
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a copy of the given point multiplied by the given factor.
Returns a QPoint object that is the sum of the given points, p1 and p2; each component is added separately.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QPoint object that is formed by changing the sign of both components of the given point.
Equivalent to {QPoint(0,0) - point}.
Returns a QPoint object that is formed by subtracting p2 from p1; each component is subtracted separately.
Returns the QPoint formed by dividing both components of the given point by the given divisor.
Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.
|
related |
Writes the given point to the given stream and returns a reference to the stream.
Definition at line 398 of file qpoint.cpp.
|
related |
Reads a point from the given stream into the given point and returns a reference to the stream.
Definition at line 417 of file qpoint.cpp.
|
friend |