Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

fgl::FGPoint Struct Reference

#include <base.h>

Inheritance diagram for fgl::FGPoint:

Inheritance graph
[legend]
List of all members.

Detailed Description

The FGPoint class defines a point in the plane.

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.

See also:
FGPointArray FGRect
Examples:

gradient.cpp.


Public Member Functions

 FGPoint ()
 FGPoint (int xpos, int ypos)
 FGPoint (double xpos, double ypos)
bool isNull () const
FGPointoperator+= (const FGPoint &p)
FGPointoperator-= (const FGPoint &p)
FGPointoperator *= (int c)
FGPointoperator *= (double c)
FGPointoperator/= (int c)
FGPointoperator/= (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)


Constructor & Destructor Documentation

fgl::FGPoint::FGPoint  )  [inline]
 

Constructs a point with coordinates (0, 0) (isNull() returns TRUE).

fgl::FGPoint::FGPoint int  xpos,
int  ypos
[inline]
 

Constructs a point with x value xpos and y value ypos.

fgl::FGPoint::FGPoint double  xpos,
double  ypos
[inline]
 

Constructs a point with x value xpos and y value ypos.


Member Function Documentation

bool fgl::FGPoint::isNull void   )  const [inline]
 

Returns TRUE if both the x value and the y value are 0; otherwise returns FALSE.

Reimplemented in fgl::FGCircle, and fgl::FGRect.

int fgl::FGPoint::ManhattanLength void   )  const [inline]
 

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

FGPoint& fgl::FGPoint::operator *= double  c  )  [inline]
 

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.

FGPoint& fgl::FGPoint::operator *= int  c  )  [inline]
 

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)

FGPoint& fgl::FGPoint::operator+= const FGPoint p  )  [inline]
 

Adds point p to this point and returns a reference to this point.

Example:

        FGPoint p(  3, 7 );
        FGPoint q( -1, 4 );
        p += q;            // p becomes (2,11)

FGPoint& fgl::FGPoint::operator-= const FGPoint p  )  [inline]
 

Subtracts point p from this point and returns a reference to this point.

Example:

        FGPoint p(  3, 7 );
        FGPoint q( -1, 4 );
        p -= q;            // p becomes (4,3)

FGPoint& fgl::FGPoint::operator/= double  c  )  [inline]
 

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.

FGPoint& fgl::FGPoint::operator/= int  c  )  [inline]
 

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)


Friends And Related Function Documentation

const FGPoint operator * double  c,
const FGPoint p
[friend]
 

Returns the FGPoint formed by multiplying both components of p by c.

Note that the result is truncated because points are held as integers.

const FGPoint operator * const FGPoint p,
double  c
[friend]
 

Returns the FGPoint formed by multiplying both components of p by c.

Note that the result is truncated because points are held as integers.

const FGPoint operator * int  c,
const FGPoint p
[friend]
 

Returns the FGPoint formed by multiplying both components of p by c.

const FGPoint operator * const FGPoint p,
int  c
[friend]
 

Returns the FGPoint formed by multiplying both components of p by c.

bool operator!= const FGPoint p1,
const FGPoint p2
[friend]
 

Returns TRUE if p1 and p2 are not equal; otherwise returns FALSE.

const FGPoint operator+ const FGPoint p1,
const FGPoint p2
[friend]
 

Returns the sum of p1 and p2; each component is added separately.

const FGPoint operator- const FGPoint p  )  [friend]
 

Returns the FGPoint formed by changing the sign of both components of p, equivalent to {FGPoint(0,0) - p}.

const FGPoint operator- const FGPoint p1,
const FGPoint p2
[friend]
 

Returns p2 subtracted from p1; each component is subtracted separately.

const FGPoint operator/ const FGPoint p,
double  c
[friend]
 

Returns the FGPoint formed by dividing both components of p by c.

Note that the result is truncated because points are held as integers.

const FGPoint operator/ const FGPoint p,
int  c
[friend]
 

Returns the FGPoint formed by dividing both components of p by c.

bool operator== const FGPoint p1,
const FGPoint p2
[friend]
 

Returns TRUE if p1 and p2 are equal; otherwise returns FALSE.


Generated on Wed Feb 9 11:31:37 2005 for OpenGUI by  doxygen 1.4.0