diff options
author | Svenn-Arne Dragly <s@dragly.com> | 2018-04-18 09:48:27 +0200 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2018-04-24 17:59:07 +0000 |
commit | f3c36a720abefad17d7cf0cb84a9f5a8ab9c2984 (patch) | |
tree | fe71c313008e0736f0a3d403de80b2bb35d7265b /tests | |
parent | 3e82b9bf123f8e2da962b13121391ae2202424c9 (diff) |
Animation: Make a fuzzy comparison when verifying cubic roots
Accept cubic roots that are close enough to 0 or 1 that the difference
is likely a numerical error. Also add a regression test to catch one of
these corner cases.
Task-number: QTBUG-67886
Change-Id: Ia05650699638e4bb7d13fa18b31d71071909bd51
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp b/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp index b2449ea1d..c61ce2d7e 100644 --- a/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp +++ b/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp @@ -221,42 +221,60 @@ private Q_SLOTS: QTest::addColumn<QVector<float>>("times"); QTest::addColumn<QVector<float>>("bezierParamters"); - float t0 = 0.0f; - Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation}; - float t1 = 50.0f; - Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation}; - const int count = 21; - QVector<float> times = (QVector<float>() - << 0.0f - << 1.00375f - << 2.48f - << 4.37625f - << 6.64f - << 9.21875f - << 12.06f - << 15.11125f - << 18.32f - << 21.63375f - << 25.0f - << 28.36625f - << 31.68f - << 34.88875f - << 37.94f - << 40.78125f - << 43.36f - << 45.62375f - << 47.52f - << 48.99625f - << 50.0f); - - QVector<float> bezierParameters; - float deltaU = 1.0f / float(count - 1); - for (int i = 0; i < count; ++i) - bezierParameters.push_back(float(i) * deltaU); - - QTest::newRow("t=0 to t=50, default easing") << t0 << kf0 + { + float t0 = 0.0f; + Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation}; + float t1 = 50.0f; + Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation}; + const int count = 21; + QVector<float> times = (QVector<float>() + << 0.0f + << 1.00375f + << 2.48f + << 4.37625f + << 6.64f + << 9.21875f + << 12.06f + << 15.11125f + << 18.32f + << 21.63375f + << 25.0f + << 28.36625f + << 31.68f + << 34.88875f + << 37.94f + << 40.78125f + << 43.36f + << 45.62375f + << 47.52f + << 48.99625f + << 50.0f); + + QVector<float> bezierParameters; + float deltaU = 1.0f / float(count - 1); + for (int i = 0; i < count; ++i) + bezierParameters.push_back(float(i) * deltaU); + + QTest::newRow("t=0 to t=50, default easing") << t0 << kf0 + << t1 << kf1 + << times << bezierParameters; + } + { + // This test creates a case where the coefficients for finding + // the cubic roots will be a = 0, b = 0, c ~= 6.28557 d ~= -6.28557 + // Because c ~= d, the answer should be one root = 1, but + // because of numerical imprecision, it will be slightly larger. + // We have a fuzzy check in parameterForTime that takes care of this. + float t0 = 3.71443009f; + Keyframe kf0{150.0f, {0.0f, 0.0f}, {5.80961999f, 150.0f}, QKeyFrame::BezierInterpolation}; + float t1 = 10.0f; + Keyframe kf1{-150.0f, {7.904809959f, 150.0f}, {0.f, 0.f}, QKeyFrame::BezierInterpolation}; + QVector<float> times = {10.f}; + QVector<float> results = {1.0f}; + QTest::newRow("t=0 to t=10, regression") << t0 << kf0 << t1 << kf1 - << times << bezierParameters; + << times << results; + } } void checkParameterForTime() |