From 6caecac1c8ad88cec373f7f7ea14cab9931ed2a1 Mon Sep 17 00:00:00 2001 From: Juan Jose Casafranca Date: Sat, 28 Jul 2018 14:44:50 +0200 Subject: Enable ConstantInterpolation for fcurves Change-Id: If51c8377f5b29433feaa520a7586f0608b7510f1 Reviewed-by: Paul Lemire --- src/animation/backend/fcurve.cpp | 3 +-- 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("time"); + QTest::addColumn("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); } }; -- cgit v1.2.3