26 inline BezierData(
const QPointF &p1,
const QPointF &cp1,
27 const QPointF &cp2,
const QPointF &p2 ):
39 static inline double minFlatness(
double tolerance )
45 return 16 * ( tolerance * tolerance );
48 inline double flatness()
const 52 const double ux = 3.0 * d_cx1 - 2.0 * d_x1 - d_x2;
53 const double uy = 3.0 * d_cy1 - 2.0 * d_y1 - d_y2;
54 const double vx = 3.0 * d_cx2 - 2.0 * d_x2 - d_x1;
55 const double vy = 3.0 * d_cy2 - 2.0 * d_y2 - d_y1;
57 const double ux2 = ux * ux;
58 const double uy2 = uy * uy;
60 const double vx2 = vx * vx;
61 const double vy2 = vy * vy;
66 inline BezierData subdivided()
70 const double c1 = midValue( d_cx1, d_cx2 );
72 bz.d_cx1 = midValue( d_x1, d_cx1 );
73 d_cx2 = midValue( d_cx2, d_x2 );
75 bz.d_cx2 = midValue( bz.d_cx1, c1 );
76 d_cx1 = midValue( c1, d_cx2 );
77 bz.d_x2 = d_x1 = midValue( bz.d_cx2, d_cx1 );
79 const double c2 = midValue( d_cy1, d_cy2 );
81 bz.d_cy1 = midValue( d_y1, d_cy1 );
82 d_cy2 = midValue( d_cy2, d_y2 );
84 bz.d_cy2 = midValue( bz.d_cy1, c2 );
85 d_cy1 = midValue( d_cy2, c2 );
86 bz.d_y2 = d_y1 = midValue( bz.d_cy2, d_cy1 );
91 inline QPointF p2()
const 93 return QPointF( d_x2, d_y2 );
97 inline double midValue(
double v1,
double v2 )
99 return 0.5 * ( v1 + v2 );
117 m_tolerance(
qwtMaxF( tolerance, 0.0 ) ),
118 m_flatness( BezierData::minFlatness( m_tolerance ) )
158 const QPointF &cp1,
const QPointF &cp2,
const QPointF &p2 )
const 187 const QPointF &cp2,
const QPointF &p2, QPolygonF &polygon )
const 195 if ( polygon.isEmpty() || polygon.last() != p1 )
203 stack.push( BezierData( p1, cp1, cp2, p2 ) );
207 BezierData &bz = stack.top();
211 if ( stack.size() == 1 )
222 stack.push( bz.subdivided() );
240 const QPointF &cp1,
const QPointF &cp2,
const QPointF &p2,
double t )
242 const double d1 = 3.0 * t;
243 const double d2 = 3.0 * t * t;
244 const double d3 = t * t * t;
245 const double s = 1.0 - t;
247 const double x = (( s * p1.x() + d1 * cp1.x() ) * s + d2 * cp2.x() ) * s + d3 * p2.x();
248 const double y = (( s * p1.y() + d1 * cp1.y() ) * s + d2 * cp2.y() ) * s + d3 * p2.y();
250 return QPointF( x, y );
static QPointF pointAt(const QPointF &p1, const QPointF &cp1, const QPointF &cp2, const QPointF &p2, double t)
void appendToPolygon(const QPointF &p1, const QPointF &cp1, const QPointF &cp2, const QPointF &p2, QPolygonF &polygon) const
Interpolate a Bézier curve by a polygon.
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void setTolerance(double tolerance)
QwtBezier(double tolerance=0.5)
Constructor.
QPolygonF toPolygon(const QPointF &p1, const QPointF &cp1, const QPointF &cp2, const QPointF &p2) const
Interpolate a Bézier curve by a polygon.