Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qbezier.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qbezier_p.h"
5#include <qdebug.h>
6#include <qline.h>
7#include <qmath.h>
8#include <qpolygon.h>
9
10#include <private/qnumeric_p.h>
11
12#include <tuple> // for std::tie()
13
15
16//#define QDEBUG_BEZIER
17
21QPolygonF QBezier::toPolygon(qreal bezier_flattening_threshold) const
22{
23 // flattening is done by splitting the bezier until we can replace the segment by a straight
24 // line. We split further until the control points are close enough to the line connecting the
25 // boundary points.
26 //
27 // the Distance of a point p from a line given by the points (a,b) is given by:
28 //
29 // d = abs( (bx - ax)(ay - py) - (by - ay)(ax - px) ) / line_length
30 //
31 // We can stop splitting if both control points are close enough to the line.
32 // To make the algorithm faster we use the manhattan length of the line.
33
35 polygon.append(QPointF(x1, y1));
36 addToPolygon(&polygon, bezier_flattening_threshold);
37 return polygon;
38}
39
41{
42 return QBezier::fromPoints(transform.map(pt1()), transform.map(pt2()), transform.map(pt3()), transform.map(pt4()));
43}
44
46{
48 QBezier temp;
49
50 // cut at t1
51 if (qFuzzyIsNull(t1 - qreal(1.))) {
52 result = *this;
53 } else {
54 temp = *this;
56 }
57
58 // cut at t0
59 if (!qFuzzyIsNull(t0))
60 result.parameterSplitLeft(t0 / t1, &temp);
61
62 return result;
63}
64
65void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold) const
66{
67 QBezier beziers[10];
68 int levels[10];
69 beziers[0] = *this;
70 levels[0] = 9;
71 int top = 0;
72
73 while (top >= 0) {
74 QBezier *b = &beziers[top];
75 // check if we can pop the top bezier curve from the stack
76 qreal y4y1 = b->y4 - b->y1;
77 qreal x4x1 = b->x4 - b->x1;
78 qreal l = qAbs(x4x1) + qAbs(y4y1);
79 qreal d;
80 if (l > 1.) {
81 d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) )
82 + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) );
83 } else {
84 d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +
85 qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
86 l = 1.;
87 }
88 if (d < bezier_flattening_threshold * l || levels[top] == 0) {
89 // good enough, we pop it off and add the endpoint
90 polygon->append(QPointF(b->x4, b->y4));
91 --top;
92 } else {
93 // split, second half of the polygon goes lower into the stack
94 std::tie(b[1], b[0]) = b->split();
95 levels[top + 1] = --levels[top];
96 ++top;
97 }
98 }
99}
100
101void QBezier::addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattening_threshold) const
102{
103 QBezier beziers[10];
104 int levels[10];
105 beziers[0] = *this;
106 levels[0] = 9;
107 int top = 0;
108
109 while (top >= 0) {
110 QBezier *b = &beziers[top];
111 // check if we can pop the top bezier curve from the stack
112 qreal y4y1 = b->y4 - b->y1;
113 qreal x4x1 = b->x4 - b->x1;
114 qreal l = qAbs(x4x1) + qAbs(y4y1);
115 qreal d;
116 if (l > 1.) {
117 d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) )
118 + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) );
119 } else {
120 d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +
121 qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
122 l = 1.;
123 }
124 if (d < bezier_flattening_threshold * l || levels[top] == 0) {
125 // good enough, we pop it off and add the endpoint
126 polygon.add(QPointF(b->x4, b->y4));
127 --top;
128 } else {
129 // split, second half of the polygon goes lower into the stack
130 std::tie(b[1], b[0]) = b->split();
131 levels[top + 1] = --levels[top];
132 ++top;
133 }
134 }
135}
136
138{
139 qreal infPoints[2];
140 int numInfPoints = inflectionPoints(infPoints);
142 res.reserve((numInfPoints + 1) * 3 * 2);
143 res.append(pt1());
144 qreal t0 = 0;
145 for (int i = 0; i < numInfPoints + 1; i++) { // #segments == #inflectionpoints + 1
146 qreal t1 = (i < numInfPoints) ? infPoints[i] : 1;
148 segment.addToQuadratics(&res, t1 - t0, errorLimit);
149 t0 = t1;
150 }
151 return res;
152}
153
154static inline qreal scoreQuadratic(const QBezier &b, QPointF qcp)
155{
156 // Construct a cubic from the quadratic, and compare its control points to the originals'
157 const QRectF bounds = b.bounds();
158 qreal dim = QLineF(bounds.topLeft(), bounds.bottomRight()).length();
159 if (qFuzzyIsNull(dim))
160 return 1;
161 const qreal f = 2.0 / 3;
162 const QPointF cp1 = b.pt1() + f * (qcp - b.pt1());
163 const QPointF cp2 = b.pt4() + f * (qcp - b.pt4());
164 const QLineF d1(b.pt2(), cp1);
165 const QLineF d2(b.pt3(), cp2);
166 return qMax(d1.length(), d2.length()) / dim;
167}
168
169static inline QPointF quadraticForCubic(const QBezier &b)
170{
171 QPointF qcp;
172 const QLineF st = b.startTangent();
173 const QLineF et = b.endTangent();
174 if (st.intersects(et, &qcp) == QLineF::NoIntersection)
175 qcp = b.midPoint();
176 return qcp;
177}
178
179void QBezier::addToQuadratics(QPolygonF *p, qreal tspan, qreal errorLimit) const
180{
181 Q_ASSERT((tspan > 0) && !(tspan > 1));
182 static constexpr qreal MinimumTSpan = 0.1;
183
184 QPointF qcp = quadraticForCubic(*this);
185 if (tspan < MinimumTSpan || scoreQuadratic(*this, qcp) < errorLimit) {
186 p->append(qcp);
187 p->append(pt4());
188 } else {
189 std::pair<QBezier, QBezier> halves = split();
190 halves.first.addToQuadratics(p, tspan / 2, errorLimit);
191 halves.second.addToQuadratics(p, tspan / 2, errorLimit);
192 }
193}
194
196{
197 auto isValidRoot = [](qreal r) {
198 return qIsFinite(r) && (r > 0) && (!qFuzzyIsNull(float(r))) && (r < 1)
199 && (!qFuzzyIsNull(float(r - 1)));
200 };
201
202 // normalize so pt1.x,pt1.y,pt4.y == 0
203 QTransform xf;
204 const QLineF l(pt1(), pt4());
205 xf.rotate(l.angle());
206 xf.translate(-pt1().x(), -pt1().y());
207 const QBezier n = mapBy(xf);
208 Q_ASSERT(n.pt1() == QPoint() && qFuzzyIsNull(float(n.pt4().y())));
209
210 const qreal p = n.pt3().x() * n.pt2().y();
211 const qreal q = n.pt4().x() * n.pt2().y();
212 const qreal r = n.pt2().x() * n.pt3().y();
213 const qreal s = n.pt4().x() * n.pt3().y();
214
215 const qreal a = 36 * ((-3 * p) + (2 * q) + (3 * r) - s);
216 if (!a)
217 return 0;
218 const qreal b = -18 * (((3 * p) - q) - (3 * r));
219 const qreal c = 18 * (r - p);
220 const qreal rad = (b * b) - (2 * a * c);
221 if (rad < 0)
222 return 0;
223 const qreal sqr = qSqrt(rad);
224 const qreal root1 = (b + sqr) / a;
225 const qreal root2 = (b - sqr) / a;
226
227 int res = 0;
228 if (isValidRoot(root1))
229 tpoints[res++] = root1;
230 if (!qFuzzyCompare(root2, root1) && isValidRoot(root2))
231 tpoints[res++] = root2;
232
233 if (res == 2 && tpoints[0] > tpoints[1])
234 qSwap(tpoints[0], tpoints[1]);
235
236 return res;
237}
238
240{
241 qreal xmin = x1;
242 qreal xmax = x1;
243 if (x2 < xmin)
244 xmin = x2;
245 else if (x2 > xmax)
246 xmax = x2;
247 if (x3 < xmin)
248 xmin = x3;
249 else if (x3 > xmax)
250 xmax = x3;
251 if (x4 < xmin)
252 xmin = x4;
253 else if (x4 > xmax)
254 xmax = x4;
255
256 qreal ymin = y1;
257 qreal ymax = y1;
258 if (y2 < ymin)
259 ymin = y2;
260 else if (y2 > ymax)
261 ymax = y2;
262 if (y3 < ymin)
263 ymin = y3;
264 else if (y3 > ymax)
265 ymax = y3;
266 if (y4 < ymin)
267 ymin = y4;
268 else if (y4 > ymax)
269 ymax = y4;
270 return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
271}
272
273
278 Circle
280
281static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offset, qreal threshold)
282{
283 const qreal o2 = offset*offset;
284 const qreal max_dist_line = threshold*offset*offset;
285 const qreal max_dist_normal = threshold*offset;
286 const int divisions = 4;
287 const qreal spacing = qreal(1.0) / divisions;
288 qreal t = spacing;
289 for (int i = 1; i < divisions; ++i, t += spacing) {
290 QPointF p1 = b1->pointAt(t);
291 QPointF p2 = b2->pointAt(t);
292 qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y());
293 if (qAbs(d - o2) > max_dist_line)
294 return Split;
295
296 QPointF normalPoint = b1->normalVector(t);
297 qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y());
298 if (l != qreal(0.0)) {
299 d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l;
300 if (d > max_dist_normal)
301 return Split;
302 }
303 }
304 return Ok;
305}
306
308
309static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
310{
311 int map[4];
312 bool p1_p2_equal = qFuzzyCompare(orig->x1, orig->x2) && qFuzzyCompare(orig->y1, orig->y2);
313 bool p2_p3_equal = qFuzzyCompare(orig->x2, orig->x3) && qFuzzyCompare(orig->y2, orig->y3);
314 bool p3_p4_equal = qFuzzyCompare(orig->x3, orig->x4) && qFuzzyCompare(orig->y3, orig->y4);
315
316 QPointF points[4];
317 int np = 0;
318 points[np] = QPointF(orig->x1, orig->y1);
319 map[0] = 0;
320 ++np;
321 if (!p1_p2_equal) {
322 points[np] = QPointF(orig->x2, orig->y2);
323 ++np;
324 }
325 map[1] = np - 1;
326 if (!p2_p3_equal) {
327 points[np] = QPointF(orig->x3, orig->y3);
328 ++np;
329 }
330 map[2] = np - 1;
331 if (!p3_p4_equal) {
332 points[np] = QPointF(orig->x4, orig->y4);
333 ++np;
334 }
335 map[3] = np - 1;
336 if (np == 1)
337 return Discard;
338
339 QRectF b = orig->bounds();
340 if (np == 4 && b.width() < .1*offset && b.height() < .1*offset) {
341 qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) +
342 (orig->y1 - orig->y2)*(orig->y1 - orig->y2) *
343 (orig->x3 - orig->x4)*(orig->x3 - orig->x4) +
344 (orig->y3 - orig->y4)*(orig->y3 - orig->y4);
345 qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) +
346 (orig->y1 - orig->y2)*(orig->y3 - orig->y4);
347 if (dot < 0 && dot*dot < 0.8*l)
348 // the points are close and reverse dirction. Approximate the whole
349 // thing by a semi circle
350 return Circle;
351 }
352
353 QPointF points_shifted[4];
354
355 QLineF prev = QLineF(QPointF(), points[1] - points[0]);
356 if (!prev.length())
357 return Discard;
358 QPointF prev_normal = prev.normalVector().unitVector().p2();
359
360 points_shifted[0] = points[0] + offset * prev_normal;
361
362 for (int i = 1; i < np - 1; ++i) {
363 QLineF next = QLineF(QPointF(), points[i + 1] - points[i]);
364 QPointF next_normal = next.normalVector().unitVector().p2();
365
366 QPointF normal_sum = prev_normal + next_normal;
367
368 qreal r = qreal(1.0) + prev_normal.x() * next_normal.x()
369 + prev_normal.y() * next_normal.y();
370
371 if (qFuzzyIsNull(r)) {
372 points_shifted[i] = points[i] + offset * prev_normal;
373 } else {
374 qreal k = offset / r;
375 points_shifted[i] = points[i] + k * normal_sum;
376 }
377
378 prev_normal = next_normal;
379 }
380
381 points_shifted[np - 1] = points[np - 1] + offset * prev_normal;
382
383 *shifted = QBezier::fromPoints(points_shifted[map[0]], points_shifted[map[1]],
384 points_shifted[map[2]], points_shifted[map[3]]);
385
386 if (np > 2)
387 return good_offset(orig, shifted, offset, threshold);
388 return Ok;
389}
390
391// This value is used to determine the length of control point vectors
392// when approximating arc segments as curves. The factor is multiplied
393// with the radius of the circle.
394#define KAPPA qreal(0.5522847498)
395
396
397static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
398{
399 QPointF normals[3];
400
401 normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2);
402 qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());
403 if (qFuzzyIsNull(dist))
404 return false;
405 normals[0] /= dist;
406 normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4);
407 dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());
408 if (qFuzzyIsNull(dist))
409 return false;
410 normals[2] /= dist;
411
412 normals[1] = QPointF(b->x1 - b->x2 - b->x3 + b->x4, b->y1 - b->y2 - b->y3 + b->y4);
413 normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y());
414
415 qreal angles[2];
416 qreal sign = 1.;
417 for (int i = 0; i < 2; ++i) {
418 qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y();
419 if (cos_a > 1.)
420 cos_a = 1.;
421 if (cos_a < -1.)
422 cos_a = -1;
423 angles[i] = qAcos(cos_a) * qreal(M_1_PI);
424 }
425
426 if (angles[0] + angles[1] > 1.) {
427 // more than 180 degrees
428 normals[1] = -normals[1];
429 angles[0] = 1. - angles[0];
430 angles[1] = 1. - angles[1];
431 sign = -1.;
432
433 }
434
435 QPointF circle[3];
436 circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset;
437 circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset;
438 circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset;
439
440 for (int i = 0; i < 2; ++i) {
441 qreal kappa = qreal(2.0) * KAPPA * sign * offset * angles[i];
442
443 o->x1 = circle[i].x();
444 o->y1 = circle[i].y();
445 o->x2 = circle[i].x() - normals[i].y()*kappa;
446 o->y2 = circle[i].y() + normals[i].x()*kappa;
447 o->x3 = circle[i+1].x() + normals[i+1].y()*kappa;
448 o->y3 = circle[i+1].y() - normals[i+1].x()*kappa;
449 o->x4 = circle[i+1].x();
450 o->y4 = circle[i+1].y();
451
452 ++o;
453 }
454 return true;
455}
456
457int QBezier::shifted(QBezier *curveSegments, int maxSegments, qreal offset, float threshold) const
458{
459 Q_ASSERT(curveSegments);
460 Q_ASSERT(maxSegments > 0);
461
464 return 0;
465
466 --maxSegments;
467 QBezier beziers[10];
468redo:
469 beziers[0] = *this;
470 QBezier *b = beziers;
471 QBezier *o = curveSegments;
472
473 while (b >= beziers) {
474 int stack_segments = b - beziers + 1;
475 if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) {
476 threshold *= qreal(1.5);
477 if (threshold > qreal(2.0))
478 goto give_up;
479 goto redo;
480 }
481 ShiftResult res = shift(b, o, offset, threshold);
482 if (res == Discard) {
483 --b;
484 } else if (res == Ok) {
485 ++o;
486 --b;
487 } else if (res == Circle && maxSegments - (o - curveSegments) >= 2) {
488 // add semi circle
489 if (addCircle(b, offset, o))
490 o += 2;
491 --b;
492 } else {
493 std::tie(b[1], b[0]) = b->split();
494 ++b;
495 }
496 }
497
498give_up:
499 while (b >= beziers) {
500 ShiftResult res = shift(b, o, offset, threshold);
501
502 // if res isn't Ok or Split then *o is undefined
503 if (res == Ok || res == Split)
504 ++o;
505
506 --b;
507 }
508
509 Q_ASSERT(o - curveSegments <= maxSegments);
510 return o - curveSegments;
511}
512
513#ifdef QDEBUG_BEZIER
514static QDebug operator<<(QDebug dbg, const QBezier &bz)
515{
516 dbg << '[' << bz.x1<< ", " << bz.y1 << "], "
517 << '[' << bz.x2 <<", " << bz.y2 << "], "
518 << '[' << bz.x3 <<", " << bz.y3 << "], "
519 << '[' << bz.x4 <<", " << bz.y4 << ']';
520 return dbg;
521}
522#endif
523
525{
526 qreal length = qreal(0.0);
527
529
530 return length;
531}
532
534{
535 qreal len = qreal(0.0); /* arc length */
536 qreal chord; /* chord length */
537
541
542 chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length();
543
544 if ((len-chord) > error) {
545 const auto halves = split(); /* split in two */
546 halves.first.addIfClose(length, error); /* try left side */
547 halves.second.addIfClose(length, error); /* try right side */
548 return;
549 }
550
551 *length = *length + len;
552
553 return;
554}
555
557{
558 qreal py0 = pointAt(t0).y();
559 qreal py1 = pointAt(t1).y();
560
561 if (py0 > py1) {
562 qSwap(py0, py1);
563 qSwap(t0, t1);
564 }
565
566 Q_ASSERT(py0 <= py1);
567
568 if (py0 >= y)
569 return t0;
570 else if (py1 <= y)
571 return t1;
572
573 Q_ASSERT(py0 < y && y < py1);
574
575 qreal lt = t0;
576 qreal dt;
577 do {
578 qreal t = qreal(0.5) * (t0 + t1);
579
580 qreal a, b, c, d;
582 qreal yt = a * y1 + b * y2 + c * y3 + d * y4;
583
584 if (yt < y) {
585 t0 = t;
586 py0 = yt;
587 } else {
588 t1 = t;
589 py1 = yt;
590 }
591 dt = lt - t;
592 lt = t;
593 } while (qAbs(dt) > qreal(1e-7));
594
595 return t0;
596}
597
599{
600 // y(t) = (1 - t)^3 * y1 + 3 * (1 - t)^2 * t * y2 + 3 * (1 - t) * t^2 * y3 + t^3 * y4
601 // y'(t) = 3 * (-(1-2t+t^2) * y1 + (1 - 4 * t + 3 * t^2) * y2 + (2 * t - 3 * t^2) * y3 + t^2 * y4)
602 // y'(t) = 3 * ((-y1 + 3 * y2 - 3 * y3 + y4)t^2 + (2 * y1 - 4 * y2 + 2 * y3)t + (-y1 + y2))
603
604 const qreal a = -y1 + 3 * y2 - 3 * y3 + y4;
605 const qreal b = 2 * y1 - 4 * y2 + 2 * y3;
606 const qreal c = -y1 + y2;
607
608 if (qFuzzyIsNull(a)) {
609 if (qFuzzyIsNull(b))
610 return 0;
611
612 t0 = -c / b;
613 return t0 > 0 && t0 < 1;
614 }
615
616 qreal reciprocal = b * b - 4 * a * c;
617
618 if (qFuzzyIsNull(reciprocal)) {
619 t0 = -b / (2 * a);
620 return t0 > 0 && t0 < 1;
621 } else if (reciprocal > 0) {
622 qreal temp = qSqrt(reciprocal);
623
624 t0 = (-b - temp)/(2*a);
625 t1 = (-b + temp)/(2*a);
626
627 if (t1 < t0)
628 qSwap(t0, t1);
629
630 int count = 0;
631 qreal t[2] = { 0, 1 };
632
633 if (t0 > 0 && t0 < 1)
634 t[count++] = t0;
635 if (t1 > 0 && t1 < 1)
636 t[count++] = t1;
637
638 t0 = t[0];
639 t1 = t[1];
640
641 return count;
642 }
643
644 return 0;
645}
646
648{
649 qreal len = length();
650 qreal t = qreal(1.0);
651 const qreal error = qreal(0.01);
652 if (l > len || qFuzzyCompare(l, len))
653 return t;
654
655 t *= qreal(0.5);
656 //int iters = 0;
657 //qDebug()<<"LEN is "<<l<<len;
658 qreal lastBigger = qreal(1.0);
659 while (1) {
660 //qDebug()<<"\tt is "<<t;
661 QBezier right = *this;
663 right.parameterSplitLeft(t, &left);
664 qreal lLen = left.length();
665 if (qAbs(lLen - l) < error)
666 break;
667
668 if (lLen < l) {
669 t += (lastBigger - t) * qreal(0.5);
670 } else {
671 lastBigger = t;
672 t -= t * qreal(0.5);
673 }
674 //++iters;
675 }
676 //qDebug()<<"number of iters is "<<iters;
677 return t;
678}
679
681{
682 if (t0 == 0 && t1 == 1)
683 return *this;
684
685 QBezier bezier = *this;
686
688 bezier.parameterSplitLeft(t0, &result);
689 qreal trueT = (t1-t0)/(1-t0);
690 bezier.parameterSplitLeft(trueT, &result);
691
692 return result;
693}
694
qreal tForY(qreal t0, qreal t1, qreal y) const
Definition qbezier.cpp:556
QPointF pt1() const
Definition qbezier_p.h:63
QPointF pt3() const
Definition qbezier_p.h:65
qreal x4
Definition qbezier_p.h:85
QRectF bounds() const
Definition qbezier.cpp:239
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition qbezier_p.h:34
std::pair< QBezier, QBezier > split() const
Definition qbezier_p.h:193
QPointF pointAt(qreal t) const
Definition qbezier_p.h:132
void parameterSplitLeft(qreal t, QBezier *left)
Definition qbezier_p.h:210
qreal y1
Definition qbezier_p.h:85
qreal y4
Definition qbezier_p.h:85
qreal tAtLength(qreal len) const
Definition qbezier.cpp:647
QPolygonF toPolygon(qreal bezier_flattening_threshold=0.5) const
Definition qbezier.cpp:21
int shifted(QBezier *curveSegments, int maxSegmets, qreal offset, float threshold) const
Definition qbezier.cpp:457
int inflectionPoints(qreal *tpoints) const
Definition qbezier.cpp:195
QBezier bezierOnInterval(qreal t0, qreal t1) const
Definition qbezier.cpp:680
static void coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal &d)
Definition qbezier_p.h:121
qreal x1
Definition qbezier_p.h:85
int stationaryYPoints(qreal &t0, qreal &t1) const
Definition qbezier.cpp:598
QBezier mapBy(const QTransform &transform) const
Definition qbezier.cpp:40
qreal length(qreal error=0.01) const
Definition qbezier.cpp:524
QPointF pt4() const
Definition qbezier_p.h:66
qreal x3
Definition qbezier_p.h:85
qreal y3
Definition qbezier_p.h:85
void addToQuadratics(QPolygonF *p, qreal tspan=1.0, qreal errorLimit=0.2) const
Definition qbezier.cpp:179
QPointF normalVector(qreal t) const
Definition qbezier_p.h:157
void addIfClose(qreal *length, qreal error) const
Definition qbezier.cpp:533
qreal x2
Definition qbezier_p.h:85
void addToPolygon(QPolygonF *p, qreal bezier_flattening_threshold=0.5) const
Definition qbezier.cpp:65
QPolygonF toQuadratics(qreal errorLimit=0.2) const
Definition qbezier.cpp:137
qreal y2
Definition qbezier_p.h:85
QBezier getSubRange(qreal t0, qreal t1) const
Definition qbezier.cpp:45
QPointF pt2() const
Definition qbezier_p.h:64
\inmodule QtCore
\inmodule QtCore
Definition qline.h:182
qreal angle() const
Definition qline.cpp:558
QLineF unitVector() const
Returns the unit vector for this line, i.e a line starting at the same point as this line with a leng...
Definition qline.cpp:620
qreal length() const
Returns the length of the line.
Definition qline.cpp:542
@ NoIntersection
Definition qline.h:185
IntersectionType intersects(const QLineF &l, QPointF *intersectionPoint=nullptr) const
Definition qline.cpp:647
constexpr QLineF normalVector() const
Returns a line that is perpendicular to this line with the same starting point and length.
Definition qline.h:309
constexpr QPointF p2() const
Returns the line's end point.
Definition qline.h:294
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
\inmodule QtCore\reentrant
Definition qpoint.h:23
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:510
constexpr QPointF bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
Definition qrect.h:511
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis, qreal distanceToPlane=1024.0f)
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
QMap< QString, QString > map
[6]
QPixmap p2
QPixmap p1
[0]
qreal spacing
qSwap(pi, e)
double e
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
static QT_WARNING_DISABLE_FLOAT_COMPARE ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
Definition qbezier.cpp:309
static QPointF quadraticForCubic(const QBezier &b)
Definition qbezier.cpp:169
ShiftResult
Definition qbezier.cpp:274
@ Ok
Definition qbezier.cpp:275
@ Split
Definition qbezier.cpp:277
@ Circle
Definition qbezier.cpp:278
@ Discard
Definition qbezier.cpp:276
static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offset, qreal threshold)
Definition qbezier.cpp:281
static qreal scoreQuadratic(const QBezier &b, QPointF qcp)
Definition qbezier.cpp:154
static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
Definition qbezier.cpp:397
#define KAPPA
Definition qbezier.cpp:394
#define QT_WARNING_DISABLE_FLOAT_COMPARE
DBusConnection const char DBusError * error
bool qIsFinite(qfloat16 f) noexcept
Definition qfloat16.h:239
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:287
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:303
qfloat16 qSqrt(qfloat16 f)
Definition qfloat16.h:243
#define M_1_PI
Definition qmath.h:221
auto qAcos(T v)
Definition qmath.h:72
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLboolean r
[2]
GLuint GLfloat GLfloat GLfloat x1
GLenum GLuint GLenum GLsizei length
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLfloat GLfloat f
GLsizei levels
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLint left
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
GLenum GLuint GLintptr offset
GLfloat n
GLint y
GLuint GLenum GLenum transform
GLfixed GLfixed GLint GLint GLfixed points
GLbyte GLbyte bz
GLuint res
const GLubyte * c
GLfixed GLfixed GLfixed y2
GLuint segment
GLenum GLsizei len
GLfixed GLfixed x2
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
static qreal dot(const QPointF &a, const QPointF &b)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define t0
#define t1
double qreal
Definition qtypes.h:92
static int sign(int x)
std::uniform_real_distribution dist(1, 2.5)
[2]
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QDate d1(1995, 5, 17)
[0]
QDate d2(1995, 5, 20)