50 #include <private/qnumeric_p.h> 51 #include <private/qmath_p.h> 58 #define INV_EPS (1L<<23) 61 #define INV_EPS (1L<<14) 65 #define M_SQRT2 1.41421356237309504880 139 *x1 = *x2 = (-c / b);
142 const qreal det = b * b - 4 * a *
c;
144 *x1 = *x2 = -b / (2 *
a);
153 const qreal stableA = b / (2 *
a);
154 const qreal stableB = c / (a * stableA * stableA);
155 const qreal stableC = -1 -
qSqrt(1 - stableB);
156 *x2 = stableA * stableC;
157 *x1 = (stableA * stableB) / stableC;
167 qreal r1 = 0, r2 = 0;
171 if (rootsCount >= 1) {
180 *tCups =
qreal(0.5) * (-b /
a);
197 while (b >= beziers) {
204 d =
qAbs( (x4x1)*(b->
y1 - b->
y2) - (y4y1)*(b->
x1 - b->
x2) )
205 +
qAbs( (x4x1)*(b->
y1 - b->
y3) - (y4y1)*(b->
x1 - b->
x3) );
211 if (d < bezier_flattening_threshold*l || b == beziers + 31) {
254 return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
268 const qreal max_dist_line = threshold*offset*
offset;
271 for (
qreal i = spacing; i <
qreal(0.99); i += spacing) {
274 qreal
d = (p1.
x() - p2.
x())*(p1.
x() - p2.
x()) + (p1.
y() - p2.
y())*(p1.
y() - p2.
y());
275 if (
qAbs(d - o2) > max_dist_line)
279 qreal
l =
qAbs(normalPoint.
x()) +
qAbs(normalPoint.
y());
280 if (l !=
qreal(0.0)) {
281 d =
qAbs( normalPoint.
x()*(p1.
y() - p2.
y()) - normalPoint.
y()*(p1.
x() - p2.
x()) ) /
l;
282 if (d > max_dist_normal)
292 bool p1_p2_equal = (orig->
x1 == orig->
x2 && orig->
y1 == orig->
y2);
293 bool p2_p3_equal = (orig->
x2 == orig->
x3 && orig->
y2 == orig->
y3);
294 bool p3_p4_equal = (orig->
x3 == orig->
x4 && orig->
y3 == orig->
y4);
322 (orig->
y1 - orig->
y2)*(orig->
y1 - orig->
y1) *
323 (orig->
x3 - orig->
x4)*(orig->
x3 - orig->
x4) +
324 (orig->
y3 - orig->
y4)*(orig->
y3 - orig->
y4);
326 (orig->
y1 - orig->
y2)*(orig->
y3 - orig->
y4);
327 if (dot < 0 && dot*dot < 0.8*l)
338 points_shifted[0] = points[0] + offset * prev_normal;
340 for (
int i = 1; i < np - 1; ++i) {
344 QPointF normal_sum = prev_normal + next_normal;
346 qreal r =
qreal(1.0) + prev_normal.x() * next_normal.x()
347 + prev_normal.y() * next_normal.y();
350 points_shifted[i] = points[i] + offset * prev_normal;
352 qreal k = offset / r;
353 points_shifted[i] = points[i] + k * normal_sum;
356 prev_normal = next_normal;
359 points_shifted[np - 1] = points[np - 1] + offset * prev_normal;
362 points_shifted[map[2]], points_shifted[map[3]]);
364 return good_offset(orig, shifted, offset, threshold);
370 #define KAPPA qreal(0.5522847498) 378 qreal dist =
qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());
383 dist =
qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());
389 normals[1] /= -1*
qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y());
393 for (
int i = 0; i < 2; ++i) {
394 qreal cos_a = normals[i].
x()*normals[i+1].
x() + normals[i].
y()*normals[i+1].
y();
402 if (angles[0] + angles[1] > 1.) {
404 normals[1] = -normals[1];
405 angles[0] = 1. - angles[0];
406 angles[1] = 1. - angles[1];
416 for (
int i = 0; i < 2; ++i) {
419 o->
x1 = circle[i].
x();
420 o->
y1 = circle[i].
y();
421 o->
x2 = circle[i].
x() - normals[i].
y()*kappa;
422 o->
y2 = circle[i].
y() + normals[i].
x()*kappa;
423 o->
x3 = circle[i+1].
x() + normals[i+1].
y()*kappa;
424 o->
y3 = circle[i+1].
y() - normals[i+1].
x()*kappa;
425 o->
x4 = circle[i+1].
x();
426 o->
y4 = circle[i+1].
y();
449 while (b >= beziers) {
450 int stack_segments = b - beziers + 1;
451 if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) {
452 threshold *=
qreal(1.5);
453 if (threshold >
qreal(2.0))
460 }
else if (res ==
Ok) {
464 }
else if (res ==
Circle && maxSegments - (o - curveSegments) >= 2) {
476 while (b >= beziers) {
486 Q_ASSERT(o - curveSegments <= maxSegments);
487 return o - curveSegments;
493 dbg <<
'[' << bz.
x1<<
", " << bz.
y1 <<
"], " 494 <<
'[' << bz.
x2 <<
", " << bz.
y2 <<
"], " 495 <<
'[' << bz.
x3 <<
", " << bz.
y3 <<
"], " 496 <<
'[' << bz.
x4 <<
", " << bz.
y4 <<
']';
507 left->
x2 = bez.
x1 + t * ( bez.
x2 - bez.
x1 );
508 left->
y2 = bez.
y1 + t * ( bez.
y2 - bez.
y1 );
510 left->
x3 = bez.
x2 + t * ( bez.
x3 - bez.
x2 );
511 left->
y3 = bez.
y2 + t * ( bez.
y3 - bez.
y2 );
513 right->
x3 = bez.
x3 + t * ( bez.
x4 - bez.
x3 );
514 right->
y3 = bez.
y3 + t * ( bez.
y4 - bez.
y3 );
516 right->
x2 = left->
x3 + t * ( right->
x3 - left->
x3);
517 right->
y2 = left->
y3 + t * ( right->
y3 - left->
y3);
519 left->
x3 = left->
x2 + t * ( left->
x3 - left->
x2 );
520 left->
y3 = left->
y2 + t * ( left->
y3 - left->
y2 );
522 left->
x4 = right->
x1 = left->
x3 + t * (right->
x2 - left->
x3);
523 left->
y4 = right->
y1 = left->
y3 + t * (right->
y2 - left->
y3);
551 if((len-chord) > error) {
552 split(&left, &right);
558 *length = *length + len;
620 return t0 > 0 && t0 < 1;
623 qreal reciprocal = b * b - 4 * a *
c;
627 return t0 > 0 && t0 < 1;
628 }
else if (reciprocal > 0) {
631 t0 = (-b - temp)/(2*a);
632 t1 = (-b + temp)/(2*a);
638 qreal t[2] = { 0, 1 };
640 if (t0 > 0 && t0 < 1)
642 if (t1 > 0 && t1 < 1)
672 if (
qAbs(lLen - l) < error)
676 t += (lastBigger - t) *
qreal(0.5);
689 if (t0 == 0 && t1 == 1)
696 qreal trueT = (t1-t0)/(1-t0);
The QDebug class provides an output stream for debugging information.
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
#define QT_END_NAMESPACE
This macro expands to.
qreal length() const
Returns the length of the line.
void parameterSplitLeft(qreal t, QBezier *left)
The QPointF class defines a point in the plane using floating point precision.
void addToPolygon(QPolygonF *p, qreal bezier_flattening_threshold=0.5) const
static void coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal &d)
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
long ASN1_INTEGER_get ASN1_INTEGER * a
QPointF pointAt(qreal t) const
int stationaryYPoints(qreal &t0, qreal &t1) const
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...
Q_DECL_CONSTEXPR T qAbs(const T &t)
qreal length(qreal error=0.01) const
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void addIfClose(qreal *length, qreal error) const
qreal x() const
Returns the x-coordinate of this point.
int shifted(QBezier *curveSegments, int maxSegmets, qreal offset, float threshold) const
The QLineF class provides a two-dimensional vector using floating point precision.
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
qreal tForY(qreal t0, qreal t1, qreal y) const
QBezier bezierOnInterval(qreal t0, qreal t1) const
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
QPointF normalVector(qreal t) const
qreal height() const
Returns the height of the rectangle.
The QPolygonF class provides a vector of points using floating point precision.
void append(const T &t)
Inserts value at the end of the vector.
qreal width() const
Returns the width of the rectangle.
static void splitBezierAt(const QBezier &bez, qreal t, QBezier *left, QBezier *right)
qreal tAtLength(qreal len) const
QBezier mapBy(const QTransform &transform) const
static int quadraticRoots(qreal a, qreal b, qreal c, qreal *x1, qreal *x2)
void qSwap(T &value1, T &value2)
QPolygonF toPolygon(qreal bezier_flattening_threshold=0.5) const
QPointF p2() const
Returns the line's end point.
void split(QBezier *firstHalf, QBezier *secondHalf) const
qreal y() const
Returns the y-coordinate of this point.
QDataStream & operator<<(QDataStream &s, const QAxBase &c)
static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offset, qreal threshold)
QBezier getSubRange(qreal t0, qreal t1) const
QLineF normalVector() const
Returns a line that is perpendicular to this line with the same starting point and length...
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
static bool findInflections(qreal a, qreal b, qreal c, qreal *t1, qreal *t2, qreal *tCups)
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
static qreal dot(const QPointF &a, const QPointF &b)
static bool addCircle(const QBezier *b, qreal offset, QBezier *o)