Browse Source

Animation: make it possible to have integer keys.

pull/191/head
Vladimír Vondruš 8 years ago
parent
commit
7a0a5ba77e
  1. 4
      src/Magnum/Animation/Interpolation.h
  2. 24
      src/Magnum/Animation/Test/InterpolationTest.cpp

4
src/Magnum/Animation/Interpolation.h

@ -188,7 +188,7 @@ template<class K, class V, class R> 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<class K, class V, class R> R interpolateStrict(const Containers::StridedArrayView<const K>& keys, const Containers::StridedArrayView<const V>& values, R(*const interpolator)(const V&, const V&, Float), const K frame, std::size_t& hint) {
@ -203,7 +203,7 @@ template<class K, class V, class R> 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)));
}
}}

24
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<Int, Float>(
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<Int, Float>(
IntegerKeys, Values, Math::lerp, 114, hint)), 1.0f);
CORRADE_COMPARE(hint, 2);
}
void InterpolationTest::interpolateError() {
std::ostringstream out;
Error redirectError{&out};

Loading…
Cancel
Save