C

Point Class

class Qul::PlatformInterface::Point

The Point class defines a point in the plane using integer precision. More...

Header: #include <platforminterface/point.h>
Since: Qt Quick Ultralite (Platform) 1.5

Public Functions

Point(Qul::PlatformInterface::coord_t xpos, Qul::PlatformInterface::coord_t ypos)
Point()
bool isNull() const
Qul::PlatformInterface::coord_t manhattanLength() const
Qul::PlatformInterface::coord_t &rx()
Qul::PlatformInterface::coord_t &ry()
void setX(Qul::PlatformInterface::coord_t x)
void setY(Qul::PlatformInterface::coord_t y)
Qul::PlatformInterface::coord_t x() const
Qul::PlatformInterface::coord_t y() const
Qul::PlatformInterface::Point &operator*=(float factor)
Qul::PlatformInterface::Point &operator*=(Qul::PlatformInterface::coord_t factor)
Qul::PlatformInterface::Point &operator+=(const Qul::PlatformInterface::Point &point)
Qul::PlatformInterface::Point &operator-=(const Qul::PlatformInterface::Point &point)
Qul::PlatformInterface::Point &operator/=(float divisor)

Static Public Members

Qul::PlatformInterface::coord_t dotProduct(const Qul::PlatformInterface::Point &p1, const Qul::PlatformInterface::Point &p2)

Detailed Description

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).

A Point object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). A Point object can also be divided or multiplied by an coord_t or a float.

In addition, the Point class provides the manhattanLength() function which gives an inexpensive approximation of the length of the Point object interpreted as a vector. Point objects can be compared.

See also Qul::PlatformInterface::PointF.

Member Function Documentation

Point::Point(Qul::PlatformInterface::coord_t xpos, Qul::PlatformInterface::coord_t ypos)

Constructs a point with the given coordinates (xpos, ypos).

See also setX() and setY().

Point::Point()

Constructs a null point, i.e. with coordinates (0, 0)

See also isNull().

[static] Qul::PlatformInterface::coord_t Point::dotProduct(const Qul::PlatformInterface::Point &p1, const Qul::PlatformInterface::Point &p2)

Returns the dot product of p1 and p2.

bool Point::isNull() const

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

Qul::PlatformInterface::coord_t Point::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. 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.

Qul::PlatformInterface::coord_t &Point::rx()

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

See also x() and setX().

Qul::PlatformInterface::coord_t &Point::ry()

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

See also y() and setY().

void Point::setX(Qul::PlatformInterface::coord_t x)

Sets the x coordinate of this point to the given x coordinate.

See also x() and setY().

void Point::setY(Qul::PlatformInterface::coord_t y)

Sets the y coordinate of this point to the given y coordinate.

See also y() and setX().

Qul::PlatformInterface::coord_t Point::x() const

Returns the x coordinate of this point.

See also setX() and rx().

Qul::PlatformInterface::coord_t Point::y() const

Returns the y coordinate of this point.

See also setY() and ry().

Qul::PlatformInterface::Point &Point::operator*=(float factor)

This is an overloaded function.

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 PointF for floating point accuracy.

See also operator/=().

Qul::PlatformInterface::Point &Point::operator*=(Qul::PlatformInterface::coord_t factor)

This is an overloaded function.

Multiplies this point's coordinates by the given factor, and returns a reference to this point.

See also operator/=().

Qul::PlatformInterface::Point &Point::operator+=(const Qul::PlatformInterface::Point &point)

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

See also operator-=().

Qul::PlatformInterface::Point &Point::operator-=(const Qul::PlatformInterface::Point &point)

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

See also operator+=().

Qul::PlatformInterface::Point &Point::operator/=(float divisor)

This is an overloaded function.

Divides both x and y by the given divisor, and returns a reference to this point. Note that the result is rounded to the nearest integer as points are held as integers. Use PointF for floating point accuracy.

See also operator*=().

Available under certain Qt licenses.
Find out more.