Source Code (Use browser search to find items of interest.)

Class Index

qt'QPointArray (./qt-2.1.0/src/kernel/qpointarray.h:39)

class Q_EXPORT QPointArray : public QArray<QPoint>
{
public:
    QPointArray() {}
    QPointArray( int size ) : QArray<QPoint>( size ) {}
    QPointArray( const QPointArray &a ) : QArray<QPoint>( a ) {}
    QPointArray( const QRect &r, bool closed=FALSE );
    QPointArray( int nPoints, const QCOORD *points );

    QPointArray	 &operator=( const QPointArray &a )
	{ return (QPointArray&)assign( a ); }

    QPointArray copy() const
	{ QPointArray tmp; return *((QPointArray*)&tmp.duplicate(*this)); }

    void    translate( int dx, int dy );
    QRect   boundingRect() const;

    void    point( uint i, int *x, int *y ) const;
    QPoint  point( uint i ) const;
    void    setPoint( uint i, int x, int y );
    void    setPoint( uint i, const QPoint &p );
    bool    setPoints( int nPoints, const QCOORD *points );
    bool    setPoints( int nPoints, int firstx, int firsty, ... );
    bool    putPoints( int index, int nPoints, const QCOORD *points );
    bool    putPoints( int index, int nPoints, int firstx, int firsty, ... );

    void    makeArc( int x, int y, int w, int h, int a1, int a2 );
    void    makeEllipse( int x, int y, int w, int h );
    void    makeArc( int x, int y, int w, int h, int a1, int a2,
		     const QWMatrix& );
    QPointArray quadBezier() const;

    void*  shortPoints( int index = 0, int nPoints = -1 ) const;
    static void cleanBuffers();

protected:
    static uint splen;
    static void* sp;
};


/*****************************************************************************
  QPointArray stream functions
 *****************************************************************************/


qt'QPointArray::setPoint() (./qt-2.1.0/include/qpointarray.h:93)

inline void QPointArray::setPoint( uint i, const QPoint &p )
{
    setPoint( i, p.x(), p.y() );
}


qt'QPointArray::QPointArray() (./qt-2.1.0/src/kernel/qpointarray.cpp:110)

QPointArray::QPointArray( const QRect &r, bool closed )
{
    setPoints( 4, r.left(),  r.top(),
		  r.right(), r.top(),
		  r.right(), r.bottom(),
		  r.left(),  r.bottom() );
    if ( closed ) {
	resize( 5 );
	setPoint( 4, r.left(), r.top() );
    }
}

/*!
  Constructs a point array with \e nPoints points, taken from the
  \e points array.

  Equivalent to setPoints(nPoints,points).
*/


qt'QPointArray::QPointArray() (./qt-2.1.0/src/kernel/qpointarray.cpp:129)

QPointArray::QPointArray( int nPoints, const QCOORD *points )
{
    setPoints( nPoints, points );
}


/*!
  \fn QPointArray &QPointArray::operator=( const QPointArray &a )
  Assigns a
  \link shclass.html shallow copy\endlink of \e a to this point array
  and returns a reference to this point array.

  Equivalent to assign( a ).

  \sa copy()
*/

/*!
  \fn QPointArray QPointArray::copy() const

  Creates a
  \link shclass.html deep copy\endlink of the array.
*/



/*!
  Translates all points in the array \e (dx,dy).
*/


qt'QPointArray::translate() (./qt-2.1.0/src/kernel/qpointarray.cpp:159)

void QPointArray::translate( int dx, int dy )
{
    register QPoint *p = data();
    register int i = size();
    QPoint pt( dx, dy );
    while ( i-- ) {
	*p += pt;
	p++;
    }
}


/*!
  Returns the point at position \e index in the array in \e *x and \e *y.
*/


qt'QPointArray::point() (./qt-2.1.0/src/kernel/qpointarray.cpp:175)

void QPointArray::point( uint index, int *x, int *y ) const
{
    QPoint p = QArray<QPoint>::at( index );
    *x = (int)p.x();
    *y = (int)p.y();
}

/*!
  Returns the point at position \e index in the array.
*/


qt'QPointArray::point() (./qt-2.1.0/src/kernel/qpointarray.cpp:186)

QPoint QPointArray::point( uint index ) const
{
    return QArray<QPoint>::at( index );
}

/*!
  Sets the point at position \e index in the array to \e (x,y).
*/


qt'QPointArray::setPoint() (./qt-2.1.0/src/kernel/qpointarray.cpp:195)

void QPointArray::setPoint( uint index, int x, int y )
{
    QArray<QPoint>::at( index ) = QPoint( x, y );
}

/*!
  Resizes the array to \e nPoints and sets the points in the array to
  the values taken from \e points.

  Returns TRUE if successful, or FALSE if the array could not be resized.

  Example:
  \code
    static QCOORD points[] = { 1,2, 3,4 };
    QPointArray a;
    a.setPoints( 2, points );
  \endcode

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

  \sa resize(), putPoints()
*/


qt'QPointArray::setPoints() (./qt-2.1.0/src/kernel/qpointarray.cpp:218)

bool QPointArray::setPoints( int nPoints, const QCOORD *points )
{
    if ( !resize(nPoints) )
	return FALSE;
    int i = 0;
    while ( nPoints-- ) {			// make array of points
	setPoint( i++, *points, *(points+1) );
	points++;
	points++;
    }
    return TRUE;
}

/*!
  \fn void QPointArray::setPoint( uint i, const QPoint &p )

  Equivalent to setPoint( i, p.x(), p.y() ).
*/

/*!
  Resizes the array to \e 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.

  Example:
  \code
    QPointArray a;
    a.setPoints( 2, 1,2, 3,4 );
  \endcode

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

  \sa resize(), putPoints()
*/


qt'QPointArray::setPoints() (./qt-2.1.0/src/kernel/qpointarray.cpp:254)

bool QPointArray::setPoints( int nPoints, int firstx, int firsty,
			     ... )
{
    va_list ap;
    if ( !resize(nPoints) )
	return FALSE;
    setPoint( 0, firstx, firsty );		// set first point
    int i = 1, x, y;
    nPoints--;
    va_start( ap, firsty );
    while ( nPoints-- ) {
	x = va_arg( ap, int );
	y = va_arg( ap, int );
	setPoint( i++, x, y );
    }
    va_end( ap );
    return TRUE;
}

/*!
  Copies \e nPoints points from the \e points array into this point array.
  Will resize this point array if <code>index+nPoints</code> exceeds
  the size of the array.

  Returns TRUE if successful, or FALSE if the array could not be resized.

  Example:
  \code
    QPointArray a( 1 );
    a[0] = QPoint( 1, 2 );
    static QCOORD points[] = { 3,4, 5,6 };
    a.putPoints( 1, 2, points );
  \endcode

  The example code creates an array with three points: (1,2), (3,4)
  and (5,6).

  This function differs from setPoints() in that it does not resize the
  array unless the array size is exceeded.

  \sa resize(), setPoints()
*/


qt'QPointArray::putPoints() (./qt-2.1.0/src/kernel/qpointarray.cpp:297)

bool QPointArray::putPoints( int index, int nPoints, const QCOORD *points )
{
    if ( index + nPoints > (int)size() ) {	// extend array
	if ( !resize( index + nPoints ) )
	    return FALSE;
    }
    int i = index;
    while ( nPoints-- ) {			// make array of points
	setPoint( i++, *points, *(points+1) );
	points++;
	points++;
    }
    return TRUE;
}

/*!
  Copies \e nPoints points from the variable argument list into this point
  array. Will resize this point array if <code>index+nPoints</code> exceeds
  the size of the array.

  Returns TRUE if successful, or FALSE if the array could not be resized.

  Example:
  \code
    QPointArray a( 1 );
    a[0] = QPoint( 1, 2 );
    a.putPoints( 1, 2, 3,4, 5,6 );
  \endcode

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

  This function differs from setPoints() because it does not resize the
  array unless the array size is exceeded.

  \sa resize(), setPoints()
*/


qt'QPointArray::putPoints() (./qt-2.1.0/src/kernel/qpointarray.cpp:334)

bool QPointArray::putPoints( int index, int nPoints, int firstx, int firsty,
			     ... )
{
    va_list ap;
    if ( index + nPoints > (int)size() ) {	// extend array
	if ( !resize(index + nPoints) )
	    return FALSE;
    }
    if ( nPoints <= 0 )
	return TRUE;
    setPoint( index, firstx, firsty );		// set first point
    int i = index + 1, x, y;
    nPoints--;
    va_start( ap, firsty );
    while ( nPoints-- ) {
	x = va_arg( ap, int );
	y = va_arg( ap, int );
	setPoint( i++, x, y );
    }
    va_end( ap );
    return TRUE;
}


/*!
  Returns the bounding rectangle of the points in the array, or
  QRect(0,0,0,0) if the array is empty.
*/


qt'QPointArray::boundingRect() (./qt-2.1.0/src/kernel/qpointarray.cpp:363)

QRect QPointArray::boundingRect() const
{
    if ( isEmpty() )
	return QRect( 0, 0, 0, 0 );		// null rectangle
    register QPoint *pd = data();
    int minx, maxx, miny, maxy;
    minx = maxx = pd->x();
    miny = maxy = pd->y();
    pd++;
    for ( int i=1; i<(int)size(); i++ ) {	// find min+max x and y
	if ( pd->x() < minx )
	    minx = pd->x();
	else if ( pd->x() > maxx )
	    maxx = pd->x();
	if ( pd->y() < miny )
	    miny = pd->y();
	else if ( pd->y() > maxy )
	    maxy = pd->y();
	pd++;
    }
    return QRect( QPoint(minx,miny), QPoint(maxx,maxy) );
}



qt'QPointArray::makeArc() (./qt-2.1.0/src/kernel/qpointarray.cpp:409)

void QPointArray::makeArc( int x, int y, int w, int h, int a1, int a2 )
{
    QWMatrix unit;
    makeArc(x,y,w,h,a1,a2,unit);
#if QT_OLD_MAKEELLIPSE // ### WWA says discard this.
    a1 = fix_angle( a1 );
    if ( a1 < 0 )
	a1 += 16*360;
    a2 = fix_angle( a2 );
    int a3 = a2 > 0 ? a2 : -a2;			// abs angle
    makeEllipse( x, y, w, h );
    int npts = a3*size()/(16*360);		// # points in arc array
    QPointArray a(npts);
    int i = a1*size()/(16*360);
    int j = 0;
    if ( a2 > 0 ) {
	while ( npts-- ) {
	    if ( i >= (int)size() )			// wrap index
		i = 0;
	    a.QArray<QPoint>::at( j++ ) = QArray<QPoint>::at( i++ );
	}
    } else {
	while ( npts-- ) {
	    if ( i < 0 )				// wrap index
		i = (int)size()-1;
	    a.QArray<QPoint>::at( j++ ) = QArray<QPoint>::at( i-- );
	}
    }
    *this = a;
    return;
#endif
}


// Based upon:
//   parelarc.c from Graphics Gems III
//   VanAken / Simar, "A Parametric Elliptical Arc Algorithm"
//
static void

qt'QPointArray::makeArc() (./qt-2.1.0/src/kernel/qpointarray.cpp:506)

void QPointArray::makeArc( int x, int y, int w, int h,
			       int a1, int a2,
			       const QWMatrix& xf )
{
    if ( --w < 0 || --h < 0 ) {
	resize( 0 );
	return;
    }

    bool rev = a2 < 0;
    if ( rev ) {
	a1 += a2;
	a2 = -a2;
    }
    a1 = fix_angle( a1 );
    if ( a1 < 0 )
	a1 += 16*360;
    a2 = fix_angle( a2 );

    bool arc = a1 != 0 || a2 != 360*16 || rev;

    double xP, yP, xQ, yQ, xK, yK;

    xf.map(x+w, y+h/2.0, &xP, &yP);
    xf.map(x+w/2.0, y, &xQ, &yQ);
    xf.map(x+w, y, &xK, &yK);

    int m = 2;
    int max;
    int q = int(QMAX(QABS(xP-xQ),QABS(yP-yQ)));
    if ( arc )
	q *= 2;
    do {
	m++;
	max = 4*(1 + int((Q_PI/2)*(1<<m)));
    } while (max < q && m < 16); // 16 limits memory usage on HUGE arcs
    resize(max);

    int n = 0;

    double inc = 1.0/(1<<m);

    int nquad[4];
    nquad[0]=0;

    qtr_elips(*this, n, xP, yP, xQ, yQ, xK, yK, m);
    nquad[1] = n;

    xP = xQ; yP = yQ;
    xf.map(x, y+h/2.0, &xQ, &yQ);
    xf.map(x, y, &xK, &yK);
    qtr_elips(*this, n, xP, yP, xQ, yQ, xK, yK, m);
    nquad[2] = n;

    xP = xQ; yP = yQ;
    xf.map(x+w/2.0, y+h, &xQ, &yQ);
    xf.map(x, y+h, &xK, &yK);
    qtr_elips(*this, n, xP, yP, xQ, yQ, xK, yK, m);
    nquad[3] = n;

    xP = xQ; yP = yQ;
    xf.map(x+w, y+h/2.0, &xQ, &yQ);
    xf.map(x+w, y+h, &xK, &yK);
    qtr_elips(*this, n, xP, yP, xQ, yQ, xK, yK, m);

    if ( arc ) {
	// We could merge the sub-ellipse extraction into the above so
	// that we didn't generate points we don't need, but this is
	// clearer, and optimizes for the common case.
	double da1 = double(a1)*Q_PI / (360*8);
	double da2 = double(a2)*Q_PI / (360*8);
	int t = 0;
	while ( da1 > Q_PI/2 ) {
	    da1 -= Q_PI/2;
	    t++;
	}

	int i = nquad[t]+int(da1/inc+0.5);
	int k = int(da2/inc+0.5);
	QPointArray r(k);
	int j = 0;

	if ( rev ) {
	    while ( k-- )
		r[j++] = at((i+k)%n);
	} else {
	    while ( j < k )
		r[j++] = at((i+j)%n);
	}
	*this = r;
    } else {
	resize(n);
    }
}

/*!
  Sets the points of the array to those describing an ellipse with
  size \a w by \a h and position (\a x, \a y ).

  The returned array has sufficient
  resolution for use as pixels (see the overloaded function which
  takes an additional QWMatrix parameter).
*/

qt'QPointArray::makeEllipse() (./qt-2.1.0/src/kernel/qpointarray.cpp:609)

void QPointArray::makeEllipse( int xx, int yy, int w, int h )
{						// midpoint, 1/4 ellipse
    QWMatrix unit;
    makeArc(xx,yy,w,h,0,360*16,unit);
    return;

#if QT_OLD_MAKEELLIPSE // ### WWA says discard this.
    if ( w <= 0 || h <= 0 ) {
	if ( w == 0 || h == 0 ) {
	    resize( 0 );
	    return;
	}
	if ( w < 0 ) {				// negative width
	    w = -w;
	    xx -= w;
	}
	if ( h < 0 ) {				// negative height
	    h = -h;
	    yy -= h;
	}
    }
    int s = (w+h+2)/2;				// max size of x,y array
    int *px = new int[s];			// 1/4th of ellipse
    int *py = new int[s];
    int x, y, i=0;
    double d1, d2;
    double a2=(w/2)*(w/2),  b2=(h/2)*(h/2);
    x = 0;
    y = int(h/2);
    d1 = b2 - a2*(h/2) + 0.25*a2;
    px[i] = x;
    py[i] = y;
    i++;
    while ( a2*(y-0.5) > b2*(x+0.5) ) {		// region 1
	if ( d1 < 0 ) {
	    d1 = d1 + b2*(3.0+2*x);
	    x++;
	} else {
	    d1 = d1 + b2*(3.0+2*x) + 2.0*a2*(1-y);
	    x++;
	    y--;
	}
	px[i] = x;
	py[i] = y;
	i++;
    }
    d2 = b2*(x+0.5)*(x+0.5) + a2*(y-1)*(y-1) - a2*b2;
    while ( y > 0 ) {				// region 2
	if ( d2 < 0 ) {
	    d2 = d2 + 2.0*b2*(x+1) + a2*(3-2*y);
	    x++;
	    y--;
	} else {
	    d2 = d2 + a2*(3-2*y);
	    y--;
	}
	px[i] = x;
	py[i] = y;
	i++;
    }
    s = i;
    resize( 4*s );				// make full point array
    xx += w/2;
    yy += h/2;
    for ( i=0; i<s; i++ ) {			// mirror
	x = px[i];
	y = py[i];
	setPoint( s-i-1, xx+x, yy-y );
	setPoint( s+i, xx-x, yy-y );
	setPoint( 3*s-i-1, xx-x, yy+y );
	setPoint( 3*s+i, xx+x, yy+y );
    }
    delete[] px;
    delete[] py;
#endif
}


// Work functions for QPointArray::quadBezier()
static

qt'QPointArray::quadBezier() (./qt-2.1.0/src/kernel/qpointarray.cpp:838)

QPointArray QPointArray::quadBezier() const
{
#ifdef USE_SIMPLE_QBEZIER_CODE
    if ( size() != 4 ) {
#if defined(CHECK_RANGE)
	qWarning( "QPointArray::bezier: The array must have 4 control points" );
#endif
	QPointArray p;
	return p;
    }

    int v;
    float xvec[4];
    float yvec[4];
    for ( v=0; v<4; v++ ) {			// store all x,y in xvec,yvec
	int x, y;
	point( v, &x, &y );
	xvec[v] = (float)x;
	yvec[v] = (float)y;
    }

    QRect r = boundingRect();
    int m = QMAX(r.width(),r.height())/2;
    m = QMIN(m,30);				// m = number of result points
    if ( m < 2 )				// at least two points
	m = 2;
    QPointArray p( m );				// p = Bezier point array
    register QPointData *pd = p.data();

    float x0 = xvec[0],	 y0 = yvec[0];
    float dt = 1.0F/m;
    float cx = 3.0F * (xvec[1] - x0);
    float bx = 3.0F * (xvec[2] - xvec[1]) - cx;
    float ax = xvec[3] - (x0 + cx + bx);
    float cy = 3.0F * (yvec[1] - y0);
    float by = 3.0F * (yvec[2] - yvec[1]) - cy;
    float ay = yvec[3] - (y0 + cy + by);
    float t = dt;

    pd->rx() = (QCOORD)xvec[0];
    pd->ry() = (QCOORD)yvec[0];
    pd++;
    m -= 2;

    while ( m-- ) {
	pd->rx() = (QCOORD)qRound( ((ax * t + bx) * t + cx) * t + x0 );
	pd->ry() = (QCOORD)qRound( ((ay * t + by) * t + cy) * t + y0 );
	pd++;
	t += dt;
    }

    pd->rx() = (QCOORD)xvec[3];
    pd->ry() = (QCOORD)yvec[3];

    return p;
#else

    if ( size() != 4 ) {
#if defined(CHECK_RANGE)
	qWarning( "QPointArray::bezier: The array must have 4 control points" );
#endif
	QPointArray pa;
	return pa;
    } else {
	QRect r = boundingRect();
	int m = 4+2*QMAX(r.width(),r.height());
	double *p = new double[m];
	double ctrl[8];
	int i;
	for (i=0; i<4; i++) {
	    ctrl[i*2] = at(i).x();
	    ctrl[i*2+1] = at(i).y();
	}
	int len=0;
	polygonizeQBezier( p, len, ctrl, m );
	QPointArray pa((len/2)+1); // one extra point for last point on line
	int j=0;
	for (i=0; j<len; i++) {
	    // Don't round - it looks terrible
	    int x = int(p[j++]);
	    int y = int(p[j++]);
	    pa[i] = QPoint(x,y);
	}
	// add last pt on the line, which will be at the last control pt
	pa[(int)pa.size()-1] = at(3);
	delete[] p;

	return pa;
    }

#endif
}


/*****************************************************************************
  QPointArray stream functions
 *****************************************************************************/

/*!
  \relates QPointArray
  Writes a point array to the stream and returns a reference to the stream.

  The serialization format is:
  <ol>
  <li> The array size (Q_UINT32)
  <li> The array points (QPoint)
  </ol>
*/


qt'QPointArray::shortPoints() (./qt-2.1.0/src/kernel/qpointarray.cpp:996)

void* QPointArray::shortPoints( int index, int nPoints ) const
{

    if ( isNull() || !nPoints )
	return 0;
    QPoint* p = data();
    p += index;
    uint i = nPoints < 0 ? size() : nPoints;
    if ( splen < i ) {
	if ( sp )
	    delete[] ((QShortPoint*)sp);
	sp = new QShortPoint[i];
	splen = i;
    }
    QShortPoint* ps = (QShortPoint*)sp;
    while ( i-- ) {
	ps->x = (short)p->x();
	ps->y = (short)p->y();
	p++;
	ps++;
    }
    return sp;
}


/*!
  \internal

  Deallocates the internal buffer used by shortPoints().
*/


qt'QPointArray::cleanBuffers() (./qt-2.1.0/src/kernel/qpointarray.cpp:1027)

void QPointArray::cleanBuffers()
{
    if ( sp )
	delete[] ((QShortPoint*)sp);
    sp = 0;
    splen = 0;
}

qt'QPointArray::setPoint() (./qt-2.1.0/src/kernel/qpointarray.h:93)

inline void QPointArray::setPoint( uint i, const QPoint &p )
{
    setPoint( i, p.x(), p.y() );
}