#include <base.h>
Inheritance diagram for fgl::FGPoint:

A point is specified by an x coordinate and a y coordinate.
The coordinate type is FGCOORD (a 32-bit integer). The minimum value of FGCOORD is FGCOORD_MIN (-2147483648) and the maximum value is FGCOORD_MAX (2147483647).
The coordinates are accessed by the functions x() and y(); they can be set by setX() and setY() or by the reference functions rx() and ry().
Given a point p, the following statements are all equivalent:
p.setX( p.x() + 1 );
p += FGPoint( 1, 0 );
p.rx()++;
A FGPoint can also be used as a vector. Addition and subtraction of FGPoints are defined as for vectors (each component is added separately). You can divide or multiply a FGPoint by an int or a double. The function manhattanLength() gives an inexpensive approximation of the length of the FGPoint interpreted as a vector.
Example:
//FGPoint oldPos is defined somewhere else MyWidget::mouseMoveEvent( QMouseEvent *e ) { FGPoint vector = e->pos() - oldPos; if ( vector.manhattanLength() > 3 ) ... //mouse has moved more than 3 pixels since oldPos }
FGPoints can be compared for equality or inequality, and they can be written to and read from a QStream.
Public Member Functions | |
| FGPoint () | |
| FGPoint (int xpos, int ypos) | |
| FGPoint (double xpos, double ypos) | |
| bool | isNull () const |
| FGPoint & | operator+= (const FGPoint &p) |
| FGPoint & | operator-= (const FGPoint &p) |
| FGPoint & | operator *= (int c) |
| FGPoint & | operator *= (double c) |
| FGPoint & | operator/= (int c) |
| FGPoint & | operator/= (double c) |
| int | ManhattanLength (void) const |
Public Attributes | |
| FGCOORD | x |
| FGCOORD | y |
Friends | |
| bool | operator== (const FGPoint &, const FGPoint &) |
| bool | operator!= (const FGPoint &, const FGPoint &) |
| const FGPoint | operator+ (const FGPoint &, const FGPoint &) |
| const FGPoint | operator- (const FGPoint &, const FGPoint &) |
| const FGPoint | operator * (const FGPoint &, int) |
| const FGPoint | operator * (int, const FGPoint &) |
| const FGPoint | operator * (const FGPoint &, double) |
| const FGPoint | operator * (double, const FGPoint &) |
| const FGPoint | operator- (const FGPoint &) |
| const FGPoint | operator/ (const FGPoint &, int) |
| const FGPoint | operator/ (const FGPoint &, double) |
|
|
Constructs a point with coordinates (0, 0) (isNull() returns TRUE). |
|
||||||||||||
|
Constructs a point with x value xpos and y value ypos. |
|
||||||||||||
|
Constructs a point with x value xpos and y value ypos. |
|
|
Returns TRUE if both the x value and the y value are 0; otherwise returns FALSE. Reimplemented in fgl::FGCircle, and fgl::FGRect. |
|
|
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. The tradition arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan. This is a useful, and quick to calculate, approximation to the true length: sqrt(pow(x(),2)+pow(y(),2)). |
|
|
Multiplies this point's x and y by c, and returns a reference to this point. Example: FGPoint p( -1, 4 ); p *= 2.5; // p becomes (-3,10) Note that the result is truncated because points are held as integers. |
|
|
Multiplies this point's x and y by c, and returns a reference to this point. Example: FGPoint p( -1, 4 ); p *= 2; // p becomes (-2,8) |
|
|
Adds point p to this point and returns a reference to this point. Example: |
|
|
Subtracts point p from this point and returns a reference to this point. Example: |
|
|
Divides both x and y by c, and returns a reference to this point. Example: FGPoint p( -3, 10 ); p /= 2.5; // p becomes (-1,4) Note that the result is truncated because points are held as integers. |
|
|
Divides both x and y by c, and returns a reference to this point. Example: FGPoint p( -2, 8 ); p /= 2; // p becomes (-1,4) |
|
||||||||||||
|
Returns the FGPoint formed by multiplying both components of p by c. Note that the result is truncated because points are held as integers. |
|
||||||||||||
|
Returns the FGPoint formed by multiplying both components of p by c. Note that the result is truncated because points are held as integers. |
|
||||||||||||
|
Returns the FGPoint formed by multiplying both components of p by c. |
|
||||||||||||
|
Returns the FGPoint formed by multiplying both components of p by c. |
|
||||||||||||
|
Returns TRUE if p1 and p2 are not equal; otherwise returns FALSE. |
|
||||||||||||
|
Returns the sum of p1 and p2; each component is added separately. |
|
|
Returns the FGPoint formed by changing the sign of both components of p, equivalent to |
|
||||||||||||
|
Returns p2 subtracted from p1; each component is subtracted separately. |
|
||||||||||||
|
Returns the FGPoint formed by dividing both components of p by c. Note that the result is truncated because points are held as integers. |
|
||||||||||||
|
Returns the FGPoint formed by dividing both components of p by c. |
|
||||||||||||
|
Returns TRUE if p1 and p2 are equal; otherwise returns FALSE. |
1.4.0