diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-07-08 07:56:00 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-07-08 09:30:17 (GMT) |
commit | 8b66982ec7b4b5d2071931c288973dce73dc9875 (patch) | |
tree | e59f98d20bf8f9dae0492caa866070b3f24c4d08 /tests | |
parent | 459dc4a3bf0dc0ac54fc558379fdf551949dd1c6 (diff) | |
download | Qt-8b66982ec7b4b5d2071931c288973dce73dc9875.zip Qt-8b66982ec7b4b5d2071931c288973dce73dc9875.tar.gz Qt-8b66982ec7b4b5d2071931c288973dce73dc9875.tar.bz2 |
Use more numerically robust algorithm to compute QBezier::pointAt().
QBezier::pointAt() could potentially return values outside the bezier's
bounds, even when the bezier was a straight horizontal line. For
example, with y = 0.5, it would produce y=0.5 or y=0.49999999999999 for
different values of t, which when rounded cause jittering in a QML
PathView.
Task-number: QTBUG-17007
Task-number: QTBUG-18133
Reviewed-by: Kim
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qpainterpath/tst_qpainterpath.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qpainterpath/tst_qpainterpath.cpp b/tests/auto/qpainterpath/tst_qpainterpath.cpp index 3941a11..33315ad 100644 --- a/tests/auto/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/qpainterpath/tst_qpainterpath.cpp @@ -114,6 +114,8 @@ private slots: void connectPathMoveTo(); void translate(); + + void lineWithinBounds(); }; // Testing get/set functions @@ -1306,6 +1308,25 @@ void tst_QPainterPath::translate() QCOMPARE(complexPath.translated(-offset), untranslatedComplexPath); } + +void tst_QPainterPath::lineWithinBounds() +{ + const int iteration_count = 3; + volatile const qreal yVal = 0.5; + QPointF a(0.0, yVal); + QPointF b(1000.0, yVal); + QPointF c(2000.0, yVal); + QPointF d(3000.0, yVal); + QPainterPath path; + path.moveTo(QPointF(0, yVal)); + path.cubicTo(QPointF(1000.0, yVal), QPointF(2000.0, yVal), QPointF(3000.0, yVal)); + for(int i=0; i<=iteration_count; i++) { + qreal actual = path.pointAtPercent(qreal(i) / iteration_count).y(); + QVERIFY(actual == yVal); // don't use QCOMPARE, don't want fuzzy comparison + } +} + + QTEST_APPLESS_MAIN(tst_QPainterPath) #include "tst_qpainterpath.moc" |