12 #include <qpainterpath.h>
15 static QPolygonF qwtBasisUniformKnots(
const QPolygonF& points )
17 const int n = points.size();
27 kx[n - 3] = 6.0 * points[n - 2].x() - points[n - 1].x();
28 ky[n - 3] = 6.0 * points[n - 2].y() - points[n - 1].y();
30 for (
int i = n - 4; i >= 0; i-- )
32 u[i] = 4.0 - 1.0 / u[i + 1];
33 kx[i] = 6.0 * points[i + 1].x() - kx[i + 1] / u[i + 1];
34 ky[i] = 6.0 * points[i + 1].y() - ky[i + 1] / u[i + 1];
41 for (
int i = 1; i < n - 1; i++ )
43 knots[i].rx() = ( kx[i - 1] - knots[i - 1].x() ) / u[i - 1];
44 knots[i].ry() = ( ky[i - 1] - knots[i - 1].y() ) / u[i - 1];
47 knots[n - 1] = points[n - 1];
55 const QPointF& p1,
const QPointF& p2,
const QPointF& p3,
const QPointF& p4,
56 QPointF& cp1, QPointF& cp2 )
58 const double t1 =
param->valueIncrement( p1, p2 );
59 const double t2 =
param->valueIncrement( p2, p3 );
60 const double t3 =
param->valueIncrement( p3, p4 );
62 const double t123 = t1 + t2 + t3;
64 cp1 = ( t2 + t3 ) / t123 * p2 + t1 / t123 * p3;
65 cp2 = ( t3 * p2 + ( t1 + t2 ) * p3 ) / t123;
72 const int n = points.size();
73 const QPointF* pd = points.constData();
77 QPointF cp1 = ( 2.0 * pd[0] + pd[1] ) / 3.0;;
85 const QPointF cpN = ( pd[n - 1] + 2.0 * pd[0] ) / 3.0;
86 path.moveTo( 0.5 * ( cpN + cp1 ) );
89 for (
int i = 1; i < n - 1; i++ )
91 const QPointF cp2 = ( pd[i - 1] + 2.0 * pd[i] ) / 3.0;
92 const QPointF cp3 = ( 2.0 * pd[i] + pd[i + 1] ) / 3.0;
94 path.cubicTo( cp1, cp2, 0.5 * ( cp2 + cp3 ) );
101 const QPointF cp2 = ( pd[n - 2] + 2.0 * pd[n - 1] ) / 3.0;
102 path.cubicTo( cp1, cp2, pd[n - 1] );
106 const QPointF cp2 = ( pd[n - 2] + 2.0 * pd[n - 1] ) / 3.0;
107 const QPointF cp3 = ( 2.0 * pd[n - 1] + pd[0] ) / 3.0;
109 path.cubicTo( cp1, cp2, 0.5 * ( cp2 + cp3 ) );
113 const QPointF cp4 = ( pd[n - 1] + 2.0 * pd[0] ) / 3.0;
114 const QPointF cp5 = ( 2.0 * pd[0] + pd[1] ) / 3.0;
116 path.cubicTo( cp3, cp4, 0.5 * ( cp4 + cp5 ) );
127 const int n = points.size();
128 const QPointF* pd = points.constData();
132 double t1 =
param->valueIncrement( pd[0], pd[1] );
133 double t2 =
param->valueIncrement( pd[1], pd[2] );
139 t0 =
param->valueIncrement( pd[n - 1], pd[0] );
141 double t012 = t0 + t1 + t2;
142 QPointF cp1 = ( ( t1 + t2 ) * pd[0] + t0 * pd[1] ) / t012;
150 const double tN =
param->valueIncrement( pd[n - 2], pd[n - 1] );
151 const QPointF cpN = ( t1 * pd[n - 1] + ( tN + t0 ) * pd[0] ) / ( tN + t0 + t1 );
153 p0 = ( t1 * cpN + t0 * cp1 ) / ( t0 + t1 );
159 for (
int i = 1; i < n - 2; i++ )
161 const double t3 =
param->valueIncrement( pd[i + 1], pd[i + 2] );
162 const double t123 = t1 + t2 + t3;
164 const QPointF cp2 = ( t2 * pd[i - 1] + ( t0 + t1 ) * pd[i] ) / t012;
165 const QPointF cp3 = ( ( t2 + t3 ) * pd[i] + t1 * pd[i + 1] ) / t123;
167 const QPointF p2 = ( t2 * cp2 + t1 * cp3 ) / ( t1 + t2 );
169 path.cubicTo( cp1, cp2, p2 );
184 t3 =
param->valueIncrement( pd[n - 1], pd[0] );
186 const double t123 = t1 + t2 + t3;
188 const QPointF cp2 = ( t2 * pd[n - 3] + ( t0 + t1 ) * pd[n - 2] ) / t012;
189 const QPointF cp3 = ( ( t2 + t3 ) * pd[n - 2] + t1 * pd[n - 1] ) / t123;
191 const QPointF p2 = ( t2 * cp2 + t1 * cp3 ) / ( t1 + t2 );
193 path.cubicTo( cp1, cp2, p2 );
203 const QPointF cp2 = ( t2 * pd[n - 2] + ( t0 + t1 ) * pd[n - 1] ) / t012;
207 path.cubicTo( cp1, cp2, pd[n - 1] );
211 const double t3 =
param->valueIncrement( pd[0], pd[1] );
212 const double t123 = t1 + t2 + t3;
214 const QPointF cp3 = ( t2 + t3 ) / t123 * pd[n - 1] + t1 / t123 * pd[0];
215 const QPointF cp4 = ( t3 * pd[n - 1] + ( t1 + t2 ) * pd[0] ) / t123;
217 const QPointF pN = ( t2 * cp2 + t1 * cp3 ) / ( t1 + t2 );
219 path.cubicTo( cp1, cp2, pN );
220 path.cubicTo( cp3, cp4, p0 );
251 if ( points.size() < 4 )
252 return QPainterPath();