15 #include <qpainterpath.h>
26 inline double operator()(
const QPointF& p1,
const QPointF& p2 )
const
36 inline double operator()(
const QPointF& p1,
const QPointF& p2 )
const
44 inline double operator()(
const QPointF& p1,
const QPointF& p2 )
const
52 inline double operator()(
const QPointF& p1,
const QPointF& p2 )
const
60 inline double operator()(
const QPointF& p1,
const QPointF& p2 )
const
68 inline double operator()(
const QPointF& p1,
const QPointF& p2 )
const
82 inline void start(
double x1,
double y1 )
87 inline void addCubic(
double cx1,
double cy1,
88 double cx2,
double cy2,
double x2,
double y2 )
90 path.cubicTo( cx1, cy1, cx2, cy2, x2, y2 );
115 inline void start(
double x1,
double y1 )
121 inline void addCubic(
double cx1,
double cy1,
122 double cx2,
double cy2,
double x2,
double y2 )
128 l.setLine( cx1, cy1, cx2, cy2 );
141 double slopeBoundary(
int boundaryCondition,
double boundaryValue,
142 const QPointF& p1,
const QPointF& p2,
double slope1 )
144 const double dx = p2.x() - p1.x();
145 const double dy = p2.y() - p1.y();
149 switch( boundaryCondition )
158 const double c2 = 0.5 * boundaryValue;
159 const double c1 = slope1;
161 m = 0.5 * ( 3.0 * dy / dx - c1 - c2 * dx );
166 const double c3 = boundaryValue / 6.0;
167 m = c3 * dx * dx + 2 * dy / dx - slope1;
172 const double s = dy / dx;
173 const double r = qBound( 0.0, boundaryValue, 1.0 );
175 m =
s - r * (
s - slope1 );
188 template<
class SplineStore >
190 const QwtSplineC1* spline,
const QPolygonF& points )
192 const int n = points.size();
196 return SplineStore();
198 const QPointF* pd = points.constData();
199 const double* md = m.constData();
202 store.init( m.size() - 1 );
203 store.start( pd[0].
x(), pd[0].
y() );
205 for (
int i = 0; i < n - 1; i++ )
207 const double dx3 = ( pd[i + 1].x() - pd[i].x() ) / 3.0;
209 store.addCubic( pd[i].
x() + dx3, pd[i].y() + md[i] * dx3,
210 pd[i + 1].x() - dx3, pd[i + 1].y() - md[i + 1] * dx3,
211 pd[i + 1].x(), pd[i + 1].y() );
217 template<
class SplineStore >
219 const QwtSplineC1* spline,
const QPolygonF& points )
221 const int n = points.size();
223 QPolygonF pointsFlipped( n );
224 for (
int i = 0; i < n; i++ )
226 pointsFlipped[i].setX( points[i].
y() );
227 pointsFlipped[i].setY( points[i].
x() );
232 return SplineStore();
234 const QPointF* pd = pointsFlipped.constData();
235 const double* md = m.constData();
238 store.init( m.size() - 1 );
239 store.start( pd[0].
y(), pd[0].
x() );
242 for (
int i = 0; i < n - 1; i++ )
244 const double dx3 = ( pd[i + 1].x() - pd[i].x() ) / 3.0;
246 store.addCubic( pd[i].
y() + md[i] * dx3, pd[i].x() + dx3,
247 pd[i + 1].y() - md[i + 1] * dx3, pd[i + 1].x() - dx3,
248 pd[i + 1].y(), pd[i + 1].x() );
254 template<
class SplineStore,
class Param >
256 const QwtSplineC1* spline,
const QPolygonF& points, Param param )
259 const int n = points.size();
261 QPolygonF pointsX, pointsY;
262 pointsX.resize( isClosing ? n + 1 : n );
263 pointsY.resize( isClosing ? n + 1 : n );
265 QPointF* px = pointsX.data();
266 QPointF* py = pointsY.data();
267 const QPointF* p = points.constData();
271 px[0].rx() = py[0].rx() = t;
272 px[0].ry() = p[0].x();
273 py[0].ry() = p[0].y();
275 int numParamPoints = 1;
276 for (
int i = 1; i < n; i++ )
278 const double td =
param( points[i - 1], points[i] );
283 px[numParamPoints].rx() = py[numParamPoints].rx() = t;
285 px[numParamPoints].ry() = p[i].x();
286 py[numParamPoints].ry() = p[i].y();
294 const double td =
param( points[n - 1], points[0] );
300 px[numParamPoints].rx() = py[numParamPoints].rx() = t;
302 px[numParamPoints].ry() = p[0].x();
303 py[numParamPoints].ry() = p[0].y();
309 if ( pointsX.size() != numParamPoints )
311 pointsX.resize( numParamPoints );
312 pointsY.resize( numParamPoints );
318 const double* mx = slopesX.constData();
319 const double* my = slopesY.constData();
326 store.init( isClosing ? n : n - 1 );
327 store.start( points[0].
x(), points[0].
y() );
331 for (
int i = 0; i < n - 1; i++ )
333 const QPointF& p1 = p[i];
334 const QPointF& p2 = p[i + 1];
336 const double td =
param( p1, p2 );
340 const double t3 = td / 3.0;
342 const double cx1 = p1.x() + mx[j] * t3;
343 const double cy1 = p1.y() + my[j] * t3;
345 const double cx2 = p2.x() - mx[j + 1] * t3;
346 const double cy2 = p2.y() - my[j + 1] * t3;
348 store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() );
355 store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() );
361 const QPointF& p1 = p[n - 1];
362 const QPointF& p2 = p[0];
364 const double td =
param( p1, p2 );
368 const double t3 = td / 3.0;
370 const double cx1 = p1.x() + mx[j] * t3;
371 const double cy1 = p1.y() + my[j] * t3;
373 const double cx2 = p2.x() - mx[0] * t3;
374 const double cy2 = p2.y() - my[0] * t3;
376 store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() );
380 store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() );
389 template< QwtSplinePolynomial toPolynomial( const QPo
intF&,
double, const QPo
intF&,
double ) >
393 QPolygonF fittedPoints;
395 const QPointF* p = points.constData();
396 const double* v = values.constData();
398 fittedPoints += p[0];
401 const int n = points.size();
403 for (
int i = 0; i < n - 1; i++ )
405 const QPointF& p1 = p[i];
406 const QPointF& p2 = p[i + 1];
410 const double l = p2.x() - p1.x();
414 fittedPoints += QPointF( p1.x() + t, p1.y() + polynomial.
valueAt( t ) );
420 if ( qFuzzyCompare( fittedPoints.last().x(), p2.x() ) )
421 fittedPoints.last() = p2;
498 if ( tolerance <= 0.0 )
502 const int n = path.elementCount();
506 const QPainterPath::Element el = path.elementAt( 0 );
507 if ( el.type != QPainterPath::MoveToElement )
510 QPointF p1( el.x, el.y );
515 for (
int i = 1; i < n; i += 3 )
517 const QPainterPath::Element el1 = path.elementAt( i );
518 const QPainterPath::Element el2 = path.elementAt( i + 1 );
519 const QPainterPath::Element el3 = path.elementAt( i + 2 );
521 const QPointF cp1( el1.x, el1.y );
522 const QPointF cp2( el2.x, el2.y );
523 const QPointF p2( el3.x, el3.y );
701 int condition,
double valueBegin,
double valueEnd )
750 const int n = points.size();
758 path.moveTo( points[0] );
764 path.addPolygon( points );
769 if ( controlLines.size() < n - 1 )
772 const QPointF* p = points.constData();
773 const QLineF* l = controlLines.constData();
776 for (
int i = 0; i < n - 1; i++ )
777 path.cubicTo( l[i].p1(), l[i].p2(), p[i + 1] );
780 && ( controlLines.size() >= n ) )
782 path.cubicTo( l[n - 1].p1(), l[n - 1].p2(), p[0] );
806 const QPolygonF& points,
double tolerance )
const
808 if ( tolerance <= 0.0 )
812 if ( controlLines.isEmpty() )
819 const QPointF* p = points.constData();
820 const QLineF* cl = controlLines.constData();
822 const int n = controlLines.size();
826 for (
int i = 0; i < n - 1; i++ )
828 const QLineF& l = cl[i];
832 const QPointF& pn = isClosed ? p[0] : p[n];
833 const QLineF& l = cl[n - 1];
864 double distance,
bool withNodes )
const
866 if ( distance <= 0.0 )
869 const int n = points.size();
883 if ( controlLines.size() < n - 1 )
886 path += points.first();
889 const QPointF* p = points.constData();
890 const QLineF* cl = controlLines.constData();
894 for (
int i = 0; i < n - 1; i++ )
896 const double l =
param->valueIncrement( p[i], p[i + 1] );
901 cl[i].p2(), p[i + 1], t / l );
908 if ( qFuzzyCompare( path.last().x(), p[i + 1].x() ) )
909 path.last() = p[i + 1];
922 && ( controlLines.size() >= n ) )
924 const double l =
param->valueIncrement( p[n - 1], p[0] );
929 cl[n - 1].p2(), p[0], t / l );
934 if ( qFuzzyCompare( path.last().x(), p[0].x() ) )
981 if ( points.size() < 2 )
987 points[0], points[1], slopeNext );
999 const int n = points.size();
1001 const QPointF p1( points[n - 1].
x(), -points[n - 1].
y() );
1002 const QPointF p2( points[n - 2].
x(), -points[n - 2].
y() );
1045 const int n = points.size();
1056 store = qwtSplineC1PathParamX< PathStore >(
this, points );
1061 store = qwtSplineC1PathParamY< PathStore >(
this, points );
1066 store = qwtSplineC1PathParametric< PathStore >(
1072 store = qwtSplineC1PathParametric< PathStore >(
1078 store = qwtSplineC1PathParametric< PathStore >(
1084 store = qwtSplineC1PathParametric< PathStore >(
1105 const int n = points.size();
1114 store = qwtSplineC1PathParamX< ControlPointsStore >(
this, points );
1119 store = qwtSplineC1PathParamY< ControlPointsStore >(
this, points );
1124 store = qwtSplineC1PathParametric< ControlPointsStore >(
1130 store = qwtSplineC1PathParametric< ControlPointsStore >(
1136 store = qwtSplineC1PathParametric< ControlPointsStore >(
1142 store = qwtSplineC1PathParametric< ControlPointsStore >(
1147 return store.controlPoints;
1168 double distance,
bool withNodes )
const
1172 if ( points.size() > 2 )
1175 if ( m.size() != points.size() )
1178 return qwtPolygonParametric< QwtSplinePolynomial::fromSlopes >(
1179 distance, points, m, withNodes );
1202 const QPolygonF& points )
const
1211 for (
int i = 1; i < m.size(); i++ )
1214 points[i - 1], m[i - 1], points[i], m[i] );
1296 double distance,
bool withNodes )
const
1300 if ( points.size() > 2 )
1303 if ( cv.size() != points.size() )
1306 return qwtPolygonParametric< QwtSplinePolynomial::fromCurvatures >(
1307 distance, points, cv, withNodes );
1342 if ( curvatures.size() < 2 )
1347 const double* cv = curvatures.constData();
1348 double* m =
slopes.data();
1350 const int n = points.size();
1351 const QPointF* p = points.constData();
1355 for (
int i = 0; i < n - 1; i++ )
1358 m[i] = polynomial.
c1;
1361 m[n - 1] = polynomial.
slopeAt( p[n - 1].
x() - p[n - 2].
x() );
1386 if ( curvatures.size() < 2 )
1389 const QPointF* p = points.constData();
1390 const double* cv = curvatures.constData();
1391 const int n = curvatures.size();
1394 for (
int i = 1; i < n; i++ )
1397 p[i - 1], cv[i - 1], p[i], cv[i] );