16 #if QT_VERSION < 0x040601 17 #define qAtan(x) ::atan(x) 23 template <
class Po
int,
typename T>
class LeftEdge;
25 template <
class Po
int,
typename T>
class TopEdge;
29 template <
class Po
int,
typename Value>
33 inline LeftEdge( Value x1, Value, Value, Value ):
45 double dy = ( p1.
y() - p2.
y() ) /
double( p1.
x() - p2.
x() );
46 return Point(
d_x1, static_cast< Value >( p2.
y() + (
d_x1 - p2.
x() ) * dy ) );
52 template <
class Po
int,
typename Value>
68 double dy = ( p1.
y() - p2.
y() ) /
double( p1.
x() - p2.
x() );
69 return Point( d_x2, static_cast<Value>( p2.
y() + ( d_x2 - p2.
x() ) * dy ) );
76 template <
class Po
int,
typename Value>
80 inline TopEdge( Value, Value, Value y1, Value ):
92 double dx = ( p1.
x() - p2.
x() ) /
double( p1.
y() - p2.
y() );
93 return Point( static_cast<Value>( p2.
x() + ( d_y1 - p2.
y() ) * dx ), d_y1 );
100 template <
class Po
int,
typename Value>
111 return p.
y() <= d_y2;
116 double dx = ( p1.
x() - p2.
x() ) /
double( p1.
y() - p2.
y() );
117 return Point( static_cast<Value>( p2.
x() + ( d_y2 - p2.
y() ) * dx ), d_y2 );
126 template <
class Polygon,
class Rect,
typename T>
129 typedef typename Polygon::value_type
Point;
132 d_clipRect( clipRect )
139 if ( d_clipRect.contains( points1.boundingRect() ) )
144 points2.reserve( qMin( 256, points1.size() ) );
146 clipEdge< LeftEdge<Point, T> >( closePolygon, points1, points2 );
147 clipEdge< RightEdge<Point, T> >( closePolygon, points2, points1 );
148 clipEdge< TopEdge<Point, T> >( closePolygon, points1, points2 );
149 clipEdge< BottomEdge<Point, T> >( closePolygon, points2, points1 );
153 template <
class Edge>
155 const Polygon &points, Polygon &clippedPoints )
const 157 clippedPoints.clear();
159 if ( points.size() < 2 )
161 if ( points.size() == 1 )
162 clippedPoints += points[0];
167 const Edge edge( d_clipRect.x(), d_clipRect.x() + d_clipRect.width(),
168 d_clipRect.y(), d_clipRect.y() + d_clipRect.height() );
172 const Point &p1 = points.first();
174 if ( edge.isInside( p1 ) )
179 const Point &p1 = points.first();
180 const Point &p2 = points.last();
182 if ( edge.isInside( p1 ) )
184 if ( !edge.isInside( p2 ) )
185 clippedPoints += edge.intersection( p1, p2 );
189 else if ( edge.isInside( p2 ) )
191 clippedPoints += edge.intersection( p1, p2 );
195 const uint nPoints = points.size();
196 const Point* p = points.constData();
198 for ( uint
i = 1;
i < nPoints;
i++ )
200 const Point &p1 = p[
i];
201 const Point &p2 = p[
i - 1];
203 if ( edge.isInside( p1 ) )
205 if ( !edge.isInside( p2 ) )
206 clippedPoints += edge.intersection( p1, p2 );
210 else if ( edge.isInside( p2 ) )
212 clippedPoints += edge.intersection( p1, p2 );
224 QVector<QwtInterval> clipCircle(
const QPointF &,
double radius )
const;
237 QVector<QPointF> cuttingPoints(
238 Edge,
const QPointF &pos,
double radius )
const;
240 double toAngle(
const QPointF &,
const QPointF & )
const;
252 const QPointF &pos,
double radius )
const 254 QVector<QPointF> points;
255 for (
int edge = 0; edge <
NEdges; edge++ )
256 points +=
cuttingPoints( static_cast<Edge>(edge), pos, radius );
258 QVector<QwtInterval> intv;
259 if ( points.size() <= 0 )
261 QRectF cRect( 0, 0, 2 * radius, 2 * radius );
262 cRect.moveCenter( pos );
263 if (
d_rect.contains( cRect ) )
269 #if QT_VERSION >= 0x040700 270 angles.reserve( points.size() );
273 for (
int i = 0;
i < points.size();
i++ )
274 angles +=
toAngle( pos, points[
i] );
279 angles[0] + ( angles[1] - angles[0] ) / 2 ) );
281 intv.reserve( angles.size() / 2 );
284 for (
int i = 0; i < angles.size() - 1; i += 2 )
289 for (
int i = 1; i < angles.size() - 1; i += 2 )
292 intv +=
QwtInterval( angles.last(), angles.first() );
300 const QPointF &from,
const QPointF &to )
const 302 if ( from.x() == to.x() )
303 return from.y() <= to.y() ? M_PI / 2.0 : 3 * M_PI / 2.0;
305 const double m = qAbs( ( to.y() - from.y() ) / ( to.x() - from.x() ) );
308 if ( to.x() > from.x() )
310 if ( to.y() > from.y() )
311 angle = 2 * M_PI - angle;
315 if ( to.y() > from.y() )
316 angle = M_PI + angle;
318 angle = M_PI - angle;
325 Edge edge,
const QPointF &pos,
double radius )
const 327 QVector<QPointF> points;
332 if ( qAbs( pos.x() - x ) < radius )
334 const double off = qSqrt(
qwtSqr( radius ) -
qwtSqr( pos.x() - x ) );
335 const double m_y1 = pos.y() + off;
337 points += QPointF( x, m_y1 );
339 const double m_y2 = pos.y() - off;
341 points += QPointF( x, m_y2 );
347 if ( qAbs( pos.y() - y ) < radius )
349 const double off = qSqrt(
qwtSqr( radius ) -
qwtSqr( pos.y() - y ) );
350 const double x1 = pos.x() + off;
352 points += QPointF( x1, y );
354 const double m_x2 = pos.x() - off;
356 points += QPointF( m_x2, y );
370 const QRectF &clipRect, QPolygon &polygon,
bool closePolygon )
372 const int minX = qCeil( clipRect.left() );
373 const int maxX = qFloor( clipRect.right() );
374 const int minY = qCeil( clipRect.top() );
375 const int maxY = qFloor( clipRect.bottom() );
377 const QRect r( minX, minY, maxX - minX, maxY - minY );
391 const QRect &clipRect, QPolygon &polygon,
bool closePolygon )
405 const QRectF &clipRect, QPolygonF &polygon,
bool closePolygon )
421 const QRectF &clipRect,
const QPolygon &polygon,
bool closePolygon )
423 QPolygon points( polygon );
424 clipPolygon( clipRect, points, closePolygon );
438 const QRect &clipRect,
const QPolygon &polygon,
bool closePolygon )
440 QPolygon points( polygon );
441 clipPolygon( clipRect, points, closePolygon );
456 const QRectF &clipRect,
const QPolygonF &polygon,
bool closePolygon )
458 QPolygonF points( polygon );
459 clipPolygonF( clipRect, points, closePolygon );
478 const QPointF ¢er,
double radius )
Polygon::value_type Point
QwtCircleClipper(const QRectF &r)
A class representing an interval.
Point intersection(const Point &p1, const Point &p2) const
QPoint qwtPolar2Pos(const QPoint &pole, double radius, double angle)
bool isInside(const Point &p) const
bool isInside(const Point &p) const
bool isInside(const Point &p) const
bool isInside(const Point &p) const
TFSIMD_FORCE_INLINE const tfScalar & y() const
static QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
void clipEdge(bool closePolygon, const Polygon &points, Polygon &clippedPoints) const
Point intersection(const Point &p1, const Point &p2) const
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
static QPolygon clippedPolygon(const QRect &, const QPolygon &, bool closePolygon=false)
TFSIMD_FORCE_INLINE const tfScalar & x() const
QVector< QwtInterval > clipCircle(const QPointF &, double radius) const
BottomEdge(Value, Value, Value, Value y2)
Point intersection(const Point &p1, const Point &p2) const
static void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)
TopEdge(Value, Value, Value y1, Value)
TFSIMD_FORCE_INLINE const tfScalar & y() const
RightEdge(Value, Value x2, Value, Value)
TFSIMD_FORCE_INLINE const tfScalar & x() const
QwtPolygonClipper(const Rect &clipRect)
void clipPolygon(Polygon &points1, bool closePolygon) const
double toAngle(const QPointF &, const QPointF &) const
static QVector< QwtInterval > clipCircle(const QRectF &, const QPointF &, double radius)
double qwtSqr(double x)
Return the square of a number.
QVector< QPointF > cuttingPoints(Edge, const QPointF &pos, double radius) const
Point intersection(const Point &p1, const Point &p2) const
static void clipPolygon(const QRect &, QPolygon &, bool closePolygon=false)
LeftEdge(Value x1, Value, Value, Value)