Tweeny 4.1.0
A Tweening library for modern C++
Loading...
Searching...
No Matches
interpolate.h
1/*
2This file is part of the Tweeny library.
3
4Copyright (c) 2016-2026 Leonardo Guilherme Lucena de Freitas
5Copyright (c) 2016 Guilherme R. Costa
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software and associated documentation files (the "Software"), to deal in
9the Software without restriction, including without limitation the rights to
10use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11the Software, and to permit persons to whom the Software is furnished to do so,
12subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#ifndef TWEENY_INTERPOLATE_H
26#define TWEENY_INTERPOLATE_H
27#include <cstddef>
28#include <tuple>
29#include <utility>
30
31#include "key-frame.h"
32#include "../easing.h"
33
34namespace tweeny::detail {
35 template <std::size_t I, typename... ValueTypes>
36 static auto interpolate_one(
37 float t,
38 const key_frame<ValueTypes...> & base,
39 const key_frame<ValueTypes...> & next
40 ) -> std::remove_reference_t<decltype(std::get<I>(base.values))> {
41 const auto & start = std::get<I>(base.values);
42 const auto & end = std::get<I>(next.values);
43 const auto & func = std::get<I>(base.easing_functions);
44 if (func) return func(t, start, end);
45 return easing::def(t, start, end);
46 }
47
48 template <typename... ValueTypes, std::size_t... I>
49 static auto interpolate_values(
50 float t,
51 const key_frame<ValueTypes...> & base,
52 const key_frame<ValueTypes...> & next,
53 std::index_sequence<I...>
54 ) -> typename key_frame<ValueTypes...>::values_t {
55 using values_t = typename key_frame<ValueTypes...>::values_t;
56 values_t out{};
57 ((std::get<I>(out) = interpolate_one<I>(t, base, next)), ...);
58 return out;
59 }
60}
61
62#endif //TWEENY_INTERPOLATE_H
constexpr detail::defaultEasing def
Default easing function, alias for linear easing.
Definition easing.h:569
Represents a key frame in a tween.
Definition key-frame.h:48