Simplify QBezier::addPolygon() implementation

Makes the code a little cleaner, avoiding an issue caused
by UB and/or optimization bug in msvc2019.

Fixes: QTBUG-77119
Fixes: QTBUG-77230
Change-Id: I9bc8f427a90e6fe32b3c26301bbb703a3c4ad846
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Eirik Aavitsland 2019-07-30 10:27:41 +02:00
parent 5d7e9c9667
commit 70e7445dbe

View File

@ -122,10 +122,10 @@ void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold
int levels[10]; int levels[10];
beziers[0] = *this; beziers[0] = *this;
levels[0] = 9; levels[0] = 9;
QBezier *b = beziers; int top = 0;
int *lvl = levels;
while (b >= beziers) { while (top >= 0) {
QBezier *b = &beziers[top];
// check if we can pop the top bezier curve from the stack // check if we can pop the top bezier curve from the stack
qreal y4y1 = b->y4 - b->y1; qreal y4y1 = b->y4 - b->y1;
qreal x4x1 = b->x4 - b->x1; qreal x4x1 = b->x4 - b->x1;
@ -139,17 +139,15 @@ void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold
qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
l = 1.; l = 1.;
} }
if (d < bezier_flattening_threshold*l || *lvl == 0) { if (d < bezier_flattening_threshold * l || levels[top] == 0) {
// good enough, we pop it off and add the endpoint // good enough, we pop it off and add the endpoint
polygon->append(QPointF(b->x4, b->y4)); polygon->append(QPointF(b->x4, b->y4));
--b; --top;
--lvl;
} else { } else {
// split, second half of the polygon goes lower into the stack // split, second half of the polygon goes lower into the stack
b->split(b+1, b); b->split(b+1, b);
lvl[1] = --lvl[0]; levels[top + 1] = --levels[top];
++b; ++top;
++lvl;
} }
} }
} }
@ -160,10 +158,10 @@ void QBezier::addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattenin
int levels[10]; int levels[10];
beziers[0] = *this; beziers[0] = *this;
levels[0] = 9; levels[0] = 9;
QBezier *b = beziers; int top = 0;
int *lvl = levels;
while (b >= beziers) { while (top >= 0) {
QBezier *b = &beziers[top];
// check if we can pop the top bezier curve from the stack // check if we can pop the top bezier curve from the stack
qreal y4y1 = b->y4 - b->y1; qreal y4y1 = b->y4 - b->y1;
qreal x4x1 = b->x4 - b->x1; qreal x4x1 = b->x4 - b->x1;
@ -177,17 +175,15 @@ void QBezier::addToPolygon(QDataBuffer<QPointF> &polygon, qreal bezier_flattenin
qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
l = 1.; l = 1.;
} }
if (d < bezier_flattening_threshold*l || *lvl == 0) { if (d < bezier_flattening_threshold * l || levels[top] == 0) {
// good enough, we pop it off and add the endpoint // good enough, we pop it off and add the endpoint
polygon.add(QPointF(b->x4, b->y4)); polygon.add(QPointF(b->x4, b->y4));
--b; --top;
--lvl;
} else { } else {
// split, second half of the polygon goes lower into the stack // split, second half of the polygon goes lower into the stack
b->split(b+1, b); b->split(b+1, b);
lvl[1] = --lvl[0]; levels[top + 1] = --levels[top];
++b; ++top;
++lvl;
} }
} }
} }