From 7a0a5ba77e531f646a8878b452b921ec3c673a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 2 Aug 2018 23:27:21 +0200 Subject: [PATCH] Animation: make it possible to have integer keys. --- src/Magnum/Animation/Interpolation.h | 4 ++-- .../Animation/Test/InterpolationTest.cpp | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Animation/Interpolation.h b/src/Magnum/Animation/Interpolation.h index 1d946cb87..a7606f6a9 100644 --- a/src/Magnum/Animation/Interpolation.h +++ b/src/Magnum/Animation/Interpolation.h @@ -188,7 +188,7 @@ template R interpolate(const Containers::StridedArray } return interpolator(values[hint], values[hint + 1], - Math::lerpInverted(keys[hint], keys[hint + 1], frame)); + Math::lerpInverted(Float(keys[hint]), Float(keys[hint + 1]), Float(frame))); } template R interpolateStrict(const Containers::StridedArrayView& keys, const Containers::StridedArrayView& values, R(*const interpolator)(const V&, const V&, Float), const K frame, std::size_t& hint) { @@ -203,7 +203,7 @@ template R interpolateStrict(const Containers::Stride ++hint; return interpolator(values[hint], values[hint + 1], - Math::lerpInverted(keys[hint], keys[hint + 1], frame)); + Math::lerpInverted(Float(keys[hint]), Float(keys[hint + 1]), Float(frame))); } }} diff --git a/src/Magnum/Animation/Test/InterpolationTest.cpp b/src/Magnum/Animation/Test/InterpolationTest.cpp index 453627cda..9daca7ef2 100644 --- a/src/Magnum/Animation/Test/InterpolationTest.cpp +++ b/src/Magnum/Animation/Test/InterpolationTest.cpp @@ -48,6 +48,9 @@ struct InterpolationTest: TestSuite::Tester { void interpolateError(); void interpolateStrictError(); + void interpolateIntegerKey(); + void interpolateStrictIntegerKey(); + void debugExtrapolation(); }; @@ -141,6 +144,9 @@ InterpolationTest::InterpolationTest() { &InterpolationTest::interpolateError, &InterpolationTest::interpolateStrictError, + &InterpolationTest::interpolateIntegerKey, + &InterpolationTest::interpolateStrictIntegerKey, + &InterpolationTest::debugExtrapolation}); } @@ -236,6 +242,24 @@ void InterpolationTest::interpolateStrictDifferentResultType() { CORRADE_COMPARE(hint, 2); } +namespace { + constexpr Int IntegerKeys[]{0, 48, 96, 120}; +} + +void InterpolationTest::interpolateIntegerKey() { + std::size_t hint{}; + CORRADE_COMPARE((Animation::interpolate( + IntegerKeys, Values, Extrapolation::Extrapolated, Extrapolation::Extrapolated, Math::lerp, 114, hint)), 1.0f); + CORRADE_COMPARE(hint, 2); +} + +void InterpolationTest::interpolateStrictIntegerKey() { + std::size_t hint{}; + CORRADE_COMPARE((Animation::interpolateStrict( + IntegerKeys, Values, Math::lerp, 114, hint)), 1.0f); + CORRADE_COMPARE(hint, 2); +} + void InterpolationTest::interpolateError() { std::ostringstream out; Error redirectError{&out};