33 static QBezier fromPoints(
const QPointF &p1,
const QPointF &p2,
34 const QPointF &p3,
const QPointF &p4)
35 {
return {p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y(), p4.x(), p4.y()}; }
37 static void coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal &d);
39 inline QPointF pointAt(qreal t)
const;
40 inline QPointF normalVector(qreal t)
const;
42 inline QPointF derivedAt(qreal t)
const;
43 inline QPointF secondDerivedAt(qreal t)
const;
45 QPolygonF toPolygon(qreal bezier_flattening_threshold = 0.5)
const;
46 void addToPolygon(QPolygonF *p, qreal bezier_flattening_threshold = 0.5)
const;
47 void addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattening_threshold)
const;
49 QRectF bounds()
const;
50 qreal length(qreal error = 0.01)
const;
51 void addIfClose(qreal *length, qreal error)
const;
53 qreal tAtLength(qreal len)
const;
55 int stationaryYPoints(qreal &t0, qreal &t1)
const;
56 qreal tForY(qreal t0, qreal t1, qreal y)
const;
58 QPointF pt1()
const {
return QPointF(x1, y1); }
59 QPointF pt2()
const {
return QPointF(x2, y2); }
60 QPointF pt3()
const {
return QPointF(x3, y3); }
61 QPointF pt4()
const {
return QPointF(x4, y4); }
63 QBezier mapBy(
const QTransform &transform)
const;
65 inline QPointF midPoint()
const;
66 inline QLineF midTangent()
const;
68 inline QLineF startTangent()
const;
69 inline QLineF endTangent()
const;
71 inline void parameterSplitLeft(qreal t, QBezier *left);
72 inline std::pair<QBezier, QBezier> split()
const;
74 int shifted(QBezier *curveSegments,
int maxSegmets,
75 qreal offset,
float threshold)
const;
77 QBezier bezierOnInterval(qreal t0, qreal t1)
const;
78 QBezier getSubRange(qreal t0, qreal t1)
const;
80 qreal x1, y1, x2, y2, x3, y3, x4, y4;
88inline QLineF QBezier::midTangent()
const
90 QPointF mid = midPoint();
91 QLineF dir(QLineF(x1, y1, x2, y2).pointAt(0.5), QLineF(x3, y3, x4, y4).pointAt(0.5));
92 return QLineF(mid.x() - dir.dx(), mid.y() - dir.dy(),
93 mid.x() + dir.dx(), mid.y() + dir.dy());
96inline QLineF QBezier::startTangent()
const
98 QLineF tangent(pt1(), pt2());
100 tangent = QLineF(pt1(), pt3());
101 if (tangent.isNull())
102 tangent = QLineF(pt1(), pt4());
106inline QLineF QBezier::endTangent()
const
108 QLineF tangent(pt4(), pt3());
109 if (tangent.isNull())
110 tangent = QLineF(pt4(), pt2());
111 if (tangent.isNull())
112 tangent = QLineF(pt4(), pt1());
162inline QPointF QBezier::derivedAt(qreal t)
const
169 qreal a = -m_t * m_t;
170 qreal b = 1 - 4 * t + 3 * d;
171 qreal c = 2 * t - 3 * d;
173 return 3 * QPointF(a * x1 + b * x2 + c * x3 + d * x4,
174 a * y1 + b * y2 + c * y3 + d * y4);
188std::pair<QBezier, QBezier> QBezier::split()
const
190 const auto mid = [](QPointF lhs, QPointF rhs) {
return (lhs + rhs) * .5; };
192 const QPointF mid_12 = mid(pt1(), pt2());
193 const QPointF mid_23 = mid(pt2(), pt3());
194 const QPointF mid_34 = mid(pt3(), pt4());
195 const QPointF mid_12_23 = mid(mid_12, mid_23);
196 const QPointF mid_23_34 = mid(mid_23, mid_34);
197 const QPointF mid_12_23__23_34 = mid(mid_12_23, mid_23_34);
200 fromPoints(pt1(), mid_12, mid_12_23, mid_12_23__23_34),
201 fromPoints(mid_12_23__23_34, mid_23_34, mid_34, pt4()),
205inline void QBezier::parameterSplitLeft(qreal t, QBezier *left)
210 left->x2 = x1 + t * ( x2 - x1 );
211 left->y2 = y1 + t * ( y2 - y1 );
213 left->x3 = x2 + t * ( x3 - x2 );
214 left->y3 = y2 + t * ( y3 - y2 );
216 x3 = x3 + t * ( x4 - x3 );
217 y3 = y3 + t * ( y4 - y3 );
219 x2 = left->x3 + t * ( x3 - left->x3);
220 y2 = left->y3 + t * ( y3 - left->y3);
222 left->x3 = left->x2 + t * ( left->x3 - left->x2 );
223 left->y3 = left->y2 + t * ( left->y3 - left->y2 );
225 left->x4 = x1 = left->x3 + t * (x2 - left->x3);
226 left->y4 = y1 = left->y3 + t * (y2 - left->y3);