| 1 | /******************************************************************************
|
|---|
| 2 | * Qwt Widget Library
|
|---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
|---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
|---|
| 5 | *
|
|---|
| 6 | * This library is free software; you can redistribute it and/or
|
|---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
|---|
| 8 | *****************************************************************************/
|
|---|
| 9 |
|
|---|
| 10 | #ifndef QWT_BEZIER_H
|
|---|
| 11 | #define QWT_BEZIER_H
|
|---|
| 12 |
|
|---|
| 13 | #include "qwt_global.h"
|
|---|
| 14 |
|
|---|
| 15 | class QPointF;
|
|---|
| 16 | class QPolygonF;
|
|---|
| 17 |
|
|---|
| 18 | /*!
|
|---|
| 19 | \brief An implementation of the de Casteljau’s Algorithm for interpolating
|
|---|
| 20 | Bézier curves
|
|---|
| 21 |
|
|---|
| 22 | The flatness criterion for terminating the subdivision is based on
|
|---|
| 23 | "Piecewise Linear Approximation of Bézier Curves" by
|
|---|
| 24 | Roger Willcocks ( http://www.rops.org )
|
|---|
| 25 |
|
|---|
| 26 | This article explains the maths behind in a very nice way:
|
|---|
| 27 | https://jeremykun.com/2013/05/11/bezier-curves-and-picasso
|
|---|
| 28 | */
|
|---|
| 29 | class QWT_EXPORT QwtBezier
|
|---|
| 30 | {
|
|---|
| 31 | public:
|
|---|
| 32 | QwtBezier( double tolerance = 0.5 );
|
|---|
| 33 | ~QwtBezier();
|
|---|
| 34 |
|
|---|
| 35 | void setTolerance( double tolerance );
|
|---|
| 36 | double tolerance() const;
|
|---|
| 37 |
|
|---|
| 38 | QPolygonF toPolygon( const QPointF& p1, const QPointF& cp1,
|
|---|
| 39 | const QPointF& cp2, const QPointF& p2 ) const;
|
|---|
| 40 |
|
|---|
| 41 | void appendToPolygon( const QPointF& p1, const QPointF& cp1,
|
|---|
| 42 | const QPointF& cp2, const QPointF& p2, QPolygonF& polygon ) const;
|
|---|
| 43 |
|
|---|
| 44 | static QPointF pointAt( const QPointF& p1, const QPointF& cp1,
|
|---|
| 45 | const QPointF& cp2, const QPointF& p2, double t );
|
|---|
| 46 |
|
|---|
| 47 | private:
|
|---|
| 48 | double m_tolerance;
|
|---|
| 49 | double m_flatness;
|
|---|
| 50 | };
|
|---|
| 51 |
|
|---|
| 52 | /*!
|
|---|
| 53 | \return Tolerance, that is used as criterion for the subdivision
|
|---|
| 54 | \sa setTolerance()
|
|---|
| 55 | */
|
|---|
| 56 | inline double QwtBezier::tolerance() const
|
|---|
| 57 | {
|
|---|
| 58 | return m_tolerance;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | #endif
|
|---|