Point Class Reference

#include <Pt/Gfx/Point.h>

Floating-point X and Y coordinates. More...

Public Member Functions

bool isOrigin () const
 Returns true if both X and Y are zero.
Point operator- () const
 Returns the negation of this point.
Float length () const
 Returns the Euclidean length of the vector from the origin.
Float lengthSquared () const
 Returns the squared Euclidean length; cheaper than length().
Point toNormalized () const
 Returns a unit-length copy of this point, or a zero point if the length is zero.
 Point (const PointI &pt)
 Constructs from a PointI by widening the coordinates.
Point & operator= (const PointI &pt)
 Assigns from a PointI by widening the coordinates.
PointI round () const
 Rounds each coordinate to the nearest integer and returns a PointI.
PointI floor () const
 Floors each coordinate and returns a PointI.
PointI ceil () const
 Ceils each coordinate and returns a PointI.

Detailed Description

Point is the logical coordinate value drawing uses: an X and a Y of type Float. It is not a pixel index. Image and view positions are integers; convert with round(), floor(), or ceil() when a pixel location is required. PointF is a typedef of this type.

The value is copyable. Arithmetic treats it as a vector: addition and subtraction with another point, scaling by a scalar, and move() by a delta. length() is the Euclidean length from the origin, and distanceTo() is the length to another point. isEqual() compares with a tolerance, because floating-point coordinates are not exact.

Construct from two floats, or widen a PointI with the explicit constructor. Widening does not round; the integer coordinates become floats.

The example builds a logical point and converts it to an integer pixel position by rounding.

Pt::Gfx::Point p(10.4, 20.6);
Pt::Gfx::PointI pixel = p.round();
Integer X and Y coordinates.
Definition Point.h:292
Floating-point X and Y coordinates.
Definition Point.h:73