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

fgl::FGPointArray Struct Reference

#include <base.h>

Collaboration diagram for fgl::FGPointArray:

Collaboration graph
[legend]
List of all members.

Detailed Description

The FGPointArray class provides an array of points.

A FGPointArray is an array of FGPoint objects. In addition to the functions provided by QMemArray, FGPointArray provides some point-specific functions.

For convenient reading and writing of the point data use setPoints(), putPoints(), point(), and setPoint().

For geometry operations use boundingRect() and translate(). There is also the FGMatrix::map() function for more general transformations of FGPointArrays. You can also create arcs and ellipses with makeArc() and makeEllipse().

Among others, FGPointArray is used by QPainter::drawLineSegments(), QPainter::drawPolyline(), QPainter::drawPolygon() and QPainter::drawCubicBezier().

Note that because this class is a QMemArray, copying an array and modifying the copy modifies the original as well, i.e. a shallow copy. If you need a deep copy use copy() or detach(), for example:

    void drawGiraffe( const FGPointArray & r, QPainter * p )
    {
        FGPointArray tmp = r;
        tmp.detach();
        // some code that modifies tmp
        p->drawPoints( tmp );
    }

If you forget the tmp.detach(), the const array will be modified.

See also:
FGMatrix


Public Member Functions

void resize (unsigned new_size)
bool isEmpty (void) const
 FGPointArray ()
 ~FGPointArray ()
 FGPointArray (unsigned int nPoints)
 FGPointArray (const FGPointArray &old)
 FGPointArray (unsigned int nPoints, FGPoint *points)
 FGPointArray (unsigned int nPoints, FGCOORD points[][2])
 FGPointArray (const FGRect &r, bool closed=false)
 FGPointArray (unsigned int nPoints, const FGCOORD *points)
void SetPoints (unsigned int nPoints, const FGCOORD *points)
void SetPoints (unsigned nPoints, int firstx, int firsty,...)
void SetPoints (unsigned int nPoints, const double *points)
void translate (int dx, int dy)
FGRect BoundingRect () const
bool contains (const FGPoint &p) const
bool contains (int x, int y) const

Public Attributes

unsigned int vertices
FGPointarray
bool allocated


Constructor & Destructor Documentation

fgl::FGPointArray::FGPointArray  )  [inline]
 

Constructs a null point array.

See also:
isNull()

fgl::FGPointArray::~FGPointArray  )  [inline]
 

Destroys the point array.

fgl::FGPointArray::FGPointArray unsigned int  nPoints  )  [inline]
 

Constructs a point array with room for size points. Makes a null array if size == 0.

See also:
resize(), isNull()

fgl::FGPointArray::FGPointArray const FGPointArray old  )  [inline]
 

Constructs a deep copy of the point array a.

fgl::FGPointArray::FGPointArray unsigned int  nPoints,
FGPoint points
[inline]
 

Constructs a point array with nPoints points, taken from the FGPoint array.

Equivalent to setPoints(nPoints, points).

fgl::FGPointArray::FGPointArray unsigned int  nPoints,
FGCOORD  points[][2]
[inline]
 

Constructs a point array with nPoints points, taken from the points array.

Equivalent to SetPoints(nPoints, points).

fgl::FGPointArray::FGPointArray const FGRect r,
bool  closed = false
[inline]
 

Constructs a point array from the rectangle r.

If closed is FALSE, then the point array just contains the following four points in the listed order: r.topLeft(), r.topRight(), r.bottomRight() and r.bottomLeft().

If closed is TRUE, then a fifth point is set to r.topLeft().

fgl::FGPointArray::FGPointArray unsigned int  nPoints,
const FGCOORD points
[inline]
 

Constructs a point array with nPoints points, taken from the points array.

Equivalent to SetPoints(nPoints, points).


Member Function Documentation

FGRect fgl::FGPointArray::BoundingRect  )  const
 

Compute the bounding rect of polygon vertices.

bool fgl::FGPointArray::contains int  x,
int  y
const
 

Returns TRUE if the point x, y is inside this rectangle; otherwise returns FALSE.

bool fgl::FGPointArray::contains const FGPoint p  )  const
 

Returns:
TRUE if the point p is inside this object; otherwise returns FALSE.

bool fgl::FGPointArray::isEmpty void   )  const [inline]
 

Returns TRUE if the array is empty; otherwise returns FALSE.

An empty rectangle has a zero number of vertices.

void fgl::FGPointArray::resize unsigned  new_size  )  [inline]
 

Resizes the array of the FGPoints.

void fgl::FGPointArray::SetPoints unsigned int  nPoints,
const double *  points
[inline]
 

void fgl::FGPointArray::SetPoints unsigned  nPoints,
int  firstx,
int  firsty,
  ...
[inline]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Resizes the array to nPoints and sets the points in the array to the values taken from the variable argument list.

Returns TRUE if successful, or FALSE if the array could not be resized (typically due to lack of memory).

The example code creates an array with two points (1,2) and (3,4):

        FGPointArray a;
        a.SetPoints( 2, 1,2, 3,4 );

The points are given as a sequence of integers, starting with firstx then firsty, and so on.

See also:
resize(), putPoints()

void fgl::FGPointArray::SetPoints unsigned int  nPoints,
const FGCOORD points
[inline]
 

void fgl::FGPointArray::translate int  dx,
int  dy
[inline]
 

Translates all points in the array by (dx, dy).


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