2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #import "KWQPointArray.h"
31 QPointArray::QPointArray(int nPoints, const int *points)
33 setPoints(nPoints, points);
36 QPointArray::QPointArray(const QRect &rect)
38 setPoints(4, rect.topLeft().x(), rect.topLeft().y(),
39 rect.topRight().x(), rect.topRight().y(),
40 rect.bottomRight().x(), rect.bottomRight().y(),
41 rect.bottomLeft().x(), rect.bottomLeft().y());
44 QPointArray QPointArray::copy() const
47 copy.duplicate(*this);
51 QRect QPointArray::boundingRect() const
53 int nPoints = count();
55 if (nPoints < 1) return QRect(0,0,0,0);
57 int minX = INT_MAX, maxX = 0;
58 int minY = INT_MAX, maxY = 0;
61 QPoint p = at(nPoints);
62 int x = p.x(), y = p.y();
64 if (x < minX) minX = x;
65 if (x > maxX) maxX = x;
66 if (y < minY) minY = y;
67 if (y > maxY) maxY = y;
72 return QRect(minX, minY, maxX - minX + 1, maxY - minY + 1);
75 void QPointArray::point(uint index, int *x, int *y)
82 void QPointArray::setPoint( uint index, int x, int y )
84 QMemArray<QPoint>::at( index ) = QPoint( x, y );
88 bool QPointArray::setPoints( int nPoints, const int *points )
90 if ( !resize(nPoints) )
93 while ( nPoints-- ) { // make array of points
94 setPoint( i++, *points, *(points+1) );
101 // FIXME: Workaround for Radar 2921061
104 bool QPointArray::setPoints( int nPoints, int firstx, int firsty, ... )
107 if ( !resize(nPoints) )
109 setPoint( 0, firstx, firsty ); // set first point
112 va_start( ap, firsty );
113 while ( nPoints-- ) {
114 x = va_arg( ap, int );
115 y = va_arg( ap, int );
116 setPoint( i++, x, y );
124 bool QPointArray::setPoints( int nPoints, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
126 if ( !resize(nPoints) )
128 setPoint( 0, x0, y0 );
129 setPoint( 1, x1, y1 );
130 setPoint( 2, x2, y2 );
131 setPoint( 3, x3, y3 );