CopperSpice API  2.0.0
QPointF Class Reference

The QPointF class defines a point in the plane using floating point precision. More...

Public Methods

 QPointF ()
 
 QPointF (const QPoint &point)
 
 QPointF (qreal xPos, qreal yPos)
 
bool isNull () const
 
qreal manhattanLength () const
 
QPointF & operator*= (qreal factor)
 
QPointF & operator+= (const QPointF &point)
 
QPointF & operator-= (const QPointF &point)
 
QPointF & operator/= (qreal factor)
 
qrealrx ()
 
qrealry ()
 
void setX (qreal xPos)
 
void setY (qreal yPos)
 
QPoint toPoint () const
 
qreal x () const
 
qreal y () const
 

Static Public Methods

static qreal dotProduct (const QPointF &p1, const QPointF &p2)
 

Friends

bool operator!= (const QPointF &point1, const QPointF &point2)
 
const QPointF operator* (const QPointF &point, qreal factor)
 
const QPointF operator* (qreal factor, const QPointF &point)
 
const QPointF operator+ (const QPointF &point1, const QPointF &point2)
 
const QPointF operator- (const QPointF &point)
 
const QPointF operator- (const QPointF &point1, const QPointF &point2)
 
const QPointF operator/ (const QPointF &point, qreal factor)
 
bool operator== (const QPointF &point1, const QPointF &point2)
 
class QMatrix
 
class QTransform
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QPointF &pointF)
 
QDataStreamoperator>> (QDataStream &stream, QPointF &pointF)
 

Detailed Description

The QPointF class defines a point using an X coordinate and a Y coordinate. The coordinates of the point are specified using floating point numbers for accuracy. The value of the coordinates can be retrieved by calling x() and y(). The methods rx() and ry() return a reference to the coordinates. To set or modify the coordinates, call setX() and setY().

The isNull() method returns true if both x and y are set to 0.0.

Methods

The QPointF class provides a constructor converting a QPoint into a QPointF. The method toPoint() returns a QPoint with the x and y coordinates truncated to integer values.

Addition and subtraction of a QPointF is done by adding both x coordinates and then adding both y coordinates. A QPointF can also be multiplied or divided by an int or a double value.

Example

Given a point p the following code shows three different ways to increment the X coordinate.

p.setX(p.x() + 1.0); // approach one
p += QPointF(1.0, 0.0); // approach two
p.rx()++; // approach three
See also
QPoint, QPolygonF

Constructor & Destructor Documentation

QPointF::QPointF ( )
inline

Constructs a new QPointF with the coordinates (0.0, 0.0). This is considered to be a null point.

See also
isNull()
QPointF::QPointF ( const QPoint point)
inline

Constructs a copy of the given point.

See also
toPoint()
QPointF::QPointF ( qreal  xPos,
qreal  yPos 
)
inline

Constructs a new QPointF with the given coordinates (xPos, yPos).

See also
setX(), setY()

Method Documentation

qreal QPointF::dotProduct ( const QPointF &  p1,
const QPointF &  p2 
)
inlinestatic

Returns the dot product of p1 and p2.

QPointF p1( 8.3, 7.9);
QPointF p2(-1.2, 12.5);
int result = QPointF::dotProduct(p1, p2); // result = (8.3 * -1.2) + (7.9 * 12.5) = -9.96 + 98.75 = 88.79
bool QPointF::isNull ( ) const
inline

Returns true if both the x and y coordinates are set to +0.0, otherwise returns false.

Since this method treats +0.0 and -0.0 differently, points with zero-valued coordinates where either or both values have a negative sign are not defined to be null points.

qreal QPointF::manhattanLength ( ) const

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.

See also
QPoint::manhattanLength()
QPointF & QPointF::operator*= ( qreal  factor)
inline

Multiplies the coordinates by the given factor and returns a reference to this QPointF.

QPointF p(-1.1, 4.1);
p *= 2.5; // p becomes (-2.75, 10.25)
See also
operator/=()
QPointF & QPointF::operator+= ( const QPointF &  point)
inline

Adds the given point to this QPointF and returns a reference to this QPointF.

QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
p += q; // p becomes (2.1, 11.2)
See also
operator-=()
QPointF & QPointF::operator-= ( const QPointF &  point)
inline

Subtracts the given point from this QPointF and returns a reference to this QPointF.

QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
p -= q; // p becomes (4.1, 3.0)
See also
operator+=()
QPointF & QPointF::operator/= ( qreal  factor)
inline

Divides both x and y by the given factor,and returns a reference to this QPointF.

QPointF p(-2.75, 10.25);
p /= 2.5; // p becomes (-1.1, 4.1)
See also
operator*=()
qreal & QPointF::rx ( )
inline

Returns a reference to the x coordinate of this point. Using a reference makes it possible to directly modify x.

QPointF p(1.1, 2.5);
--(p.rx()); // p becomes (0.1, 2.5)
See also
x(), setX()
qreal & QPointF::ry ( )
inline

Returns a reference to the y coordinate of this point. Using a reference makes it possible to directly modify y.

QPointF p(1.1, 2.5);
++(p.ry()); // p becomes (1.1, 3.5)
See also
y(), setY()
void QPointF::setX ( qreal  xPos)
inline

Sets the x coordinate of this QPointF to the given xPos coordinate.

See also
x(), setY()
void QPointF::setY ( qreal  yPos)
inline

Sets the y coordinate of this QPointF to the given yPos coordinate.

See also
y(), setX()
QPoint QPointF::toPoint ( ) const
inline

Rounds the coordinates of this QPointF to the nearest integer, and returns a QPoint object with the rounded coordinates.

See also
QPointF()
qreal QPointF::x ( ) const
inline

Returns the x coordinate of this QPointF.

See also
setX(), rx()
qreal QPointF::y ( ) const
inline

Returns the y coordinate of this QPointF.

See also
setY(), ry()

Friends And Related Function Documentation

bool operator!= ( const QPointF &  point1,
const QPointF &  point2 
)
friend

Returns true if point1 is not equal to point2, otherwise returns false.

const QPointF operator* ( const QPointF &  point,
qreal  factor 
)
friend

Returns a copy of the given point multiplied by the given factor.

See also
QPointF::operator*=()
const QPointF operator* ( qreal  factor,
const QPointF &  point 
)
friend

Returns a copy of the given point, multiplied by the given factor.

const QPointF operator+ ( const QPointF &  point1,
const QPointF &  point2 
)
friend

Returns a QPointF which is the sum of the given points, point1 and point2. Each component is added separately.

See also
QPointF::operator+=()
const QPointF operator- ( const QPointF &  point)
friend

Returns a QPointF which is formed by changing the sign of both components of the given point.

Equivalent to QPointF(0,0) - point.

const QPointF operator- ( const QPointF &  point1,
const QPointF &  point2 
)
friend

Returns a QPointF which is formed by subtracting point2 from point1. Each component is subtracted separately.

See also
QPointF::operator-=()
const QPointF operator/ ( const QPointF &  point,
qreal  factor 
)
friend

Returns the QPointF which is formed by dividing both components of the given point by the given factor.

See also
QPointF::operator/=()
QDataStream & operator<< ( QDataStream stream,
const QPointF &  pointF 
)
related

Writes the given pointF to the stream. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.

bool operator== ( const QPointF &  point1,
const QPointF &  point2 
)
friend

Returns true if point1 is equal to point2, otherwise returns false.

QDataStream & operator>> ( QDataStream stream,
QPointF &  pointF 
)
related

Reads from the stream into the given pointF. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.