23 template<
class Po
int,
typename T >
class LeftEdge;
24 template<
class Po
int,
typename T >
class RightEdge;
25 template<
class Po
int,
typename T >
class TopEdge;
29 template<
class Po
int,
typename Value >
43 inline Point
intersection(
const Point& p1,
const Point& p2 )
const 45 double dy = ( p1.y() - p2.y() ) /
double( p1.x() - p2.x() );
46 return Point(
m_x1, static_cast< Value >( p2.y() + (
m_x1 - p2.x() ) * dy ) );
52 template<
class Po
int,
typename Value >
66 inline Point
intersection(
const Point& p1,
const Point& p2 )
const 68 double dy = ( p1.y() - p2.y() ) /
double( p1.x() - p2.x() );
69 return Point( m_x2, static_cast< Value >( p2.y() + ( m_x2 - p2.x() ) * dy ) );
76 template<
class Po
int,
typename Value >
90 inline Point
intersection(
const Point& p1,
const Point& p2 )
const 92 double dx = ( p1.x() - p2.x() ) /
double( p1.y() - p2.y() );
93 return Point( static_cast< Value >( p2.x() + ( m_y1 - p2.y() ) * dx ), m_y1 );
100 template<
class Po
int,
typename Value >
111 return p.y() <= m_y2;
116 double dx = ( p1.x() - p2.x() ) /
double( p1.y() - p2.y() );
117 return Point( static_cast< Value >( p2.x() + ( m_y2 - p2.y() ) * dx ), m_y2 );
126 template<
class Polygon,
class Rect,
typename T >
132 m_clipRect( clipRect )
139 if ( m_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( m_clipRect.x(), m_clipRect.x() + m_clipRect.width(),
168 m_clipRect.y(), m_clipRect.y() + m_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 );
238 Edge,
const QPointF& pos,
double radius )
const;
240 double toAngle(
const QPointF&,
const QPointF& )
const;
252 const QPointF& pos,
double radius )
const 257 for (
int edge = 0; edge <
NEdges; edge++ )
258 points +=
cuttingPoints( static_cast< Edge >( edge ), pos, radius );
261 if ( points.size() <= 0 )
263 QRectF cRect( 0, 0, 2 * radius, 2 * radius );
264 cRect.moveCenter( pos );
265 if (
m_rect.contains( cRect ) )
271 angles.reserve( points.size() );
273 for (
int i = 0; i < points.size(); i++ )
274 angles +=
toAngle( pos, points[i] );
276 std::sort( angles.begin(), angles.end() );
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() ) );
307 double angle = std::atan( m );
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 332 if ( qAbs( pos.x() -
x ) < radius )
334 const double off = std::sqrt(
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 = std::sqrt(
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 );
438 const QRect& clipRect,
const QPolygon& polygon,
bool closePolygon )
440 QPolygon points( polygon );
456 const QRectF& clipRect,
const QPolygonF& polygon,
bool closePolygon )
458 QPolygonF points( polygon );
478 const QPointF&
center,
double radius )
bool isInside(const Point &p) const
Polygon::value_type Point
QVector< QwtInterval > clipCircle(const QPointF &, double radius) const
double toAngle(const QPointF &, const QPointF &) const
Point intersection(const Point &p1, const Point &p2) const
bool isInside(const Point &p) const
QwtCircleClipper(const QRectF &r)
A class representing an interval.
QPoint qwtPolar2Pos(const QPoint &pole, double radius, double angle)
void clipPolygon(Polygon &points1, bool closePolygon) const
QVector< QPointF > cuttingPoints(Edge, const QPointF &pos, double radius) const
BottomEdge(Value, Value, Value, Value y2)
TopEdge(Value, Value, Value y1, Value)
bool isInside(const Point &p) const
static int sort(lua_State *L)
RightEdge(Value, Value x2, Value, Value)
void clipEdge(bool closePolygon, const Polygon &points, Polygon &clippedPoints) const
QwtPolygonClipper(const Rect &clipRect)
Point intersection(const Point &p1, const Point &p2) const
QWT_EXPORT void clipPolygon(const QRect &, QPolygon &, bool closePolygon=false)
Point intersection(const Point &p1, const Point &p2) const
remove_cvref_t< decltype(*detail::range_begin(std::declval< Range >()))> value_type
QWT_EXPORT QPolygon clippedPolygon(const QRect &, const QPolygon &, bool closePolygon=false)
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)
bool isInside(const Point &p) const
double qwtSqr(double x)
Return the square of a number.
QWT_EXPORT QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
QWT_EXPORT QVector< QwtInterval > clipCircle(const QRectF &, const QPointF &, double radius)
Point intersection(const Point &p1, const Point &p2) const
LeftEdge(Value x1, Value, Value, Value)