diff options
author | Juan Jose Casafranca <juan.casafranca@kdab.com> | 2018-07-28 14:44:50 +0200 |
---|---|---|
committer | Juan José Casafranca <juan.casafranca@kdab.com> | 2018-07-31 16:44:52 +0000 |
commit | 6caecac1c8ad88cec373f7f7ea14cab9931ed2a1 (patch) | |
tree | c88d1870c97ff3dd1491ba25085a9d639d510f7c | |
parent | ed1ca081f0b0ae765c469bae5fe8849477c7b144 (diff) |
Enable ConstantInterpolation for fcurves
Change-Id: If51c8377f5b29433feaa520a7586f0608b7510f1
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/animation/backend/fcurve.cpp | 3 | ||||
-rw-r--r-- | tests/auto/animation/fcurve/tst_fcurve.cpp | 22 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/animation/backend/fcurve.cpp b/src/animation/backend/fcurve.cpp index edb2b6df8..c4361a37a 100644 --- a/src/animation/backend/fcurve.cpp +++ b/src/animation/backend/fcurve.cpp @@ -71,8 +71,7 @@ float FCurve::evaluateAtTime(float localTime) const switch (keyframe0.interpolation) { case QKeyFrame::ConstantInterpolation: - qWarning("Constant interpolation not implemented yet"); - break; + return keyframe0.value; case QKeyFrame::LinearInterpolation: if (localTime >= t0 && localTime <= t1 && t1 > t0) { float t = (localTime - t0) / (t1 - t0); diff --git a/tests/auto/animation/fcurve/tst_fcurve.cpp b/tests/auto/animation/fcurve/tst_fcurve.cpp index e3e8db50d..c2dbe33aa 100644 --- a/tests/auto/animation/fcurve/tst_fcurve.cpp +++ b/tests/auto/animation/fcurve/tst_fcurve.cpp @@ -90,9 +90,31 @@ private Q_SLOTS: QCOMPARE(fcurve.endTime(), 0.0f); } + void checkEvaluateAtTime_data() + { + + QTest::addColumn<float>("time"); + QTest::addColumn<float>("expectedValue"); + + QTest::addRow("Constant_before_time") << 0.0f << 1.0f; + QTest::addRow("Constant_1.5") << 1.5f << 1.0f; + QTest::addRow("Constant_2.5") << 2.5f << 2.0f; + QTest::addRow("Constant_after_time") << 3.5f << 4.0f; + } + void checkEvaluateAtTime() { + QFETCH(float, time); + QFETCH(float, expectedValue); + + FCurve curve; + curve.appendKeyframe(1.0, Keyframe{1.0, {0.0, 0.0}, {0.0,0.0}, QKeyFrame::ConstantInterpolation}); + curve.appendKeyframe(2.0, Keyframe{2.0, {0.0, 0.0}, {0.0,0.0}, QKeyFrame::ConstantInterpolation}); + curve.appendKeyframe(3.0, Keyframe{4.0, {0.0, 0.0}, {0.0,0.0}, QKeyFrame::ConstantInterpolation}); + + float actualValue = curve.evaluateAtTime(time); + QCOMPARE(expectedValue, actualValue); } }; |