/* This file is part of the Tweeny library. Copyright (c) 2016-2021 Leonardo Guilherme Lucena de Freitas Copyright (c) 2016 Guilherme R. Costa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * This file implements the tweenpoint class */ #ifndef TWEENY_TWEENPOINT_TCC #define TWEENY_TWEENPOINT_TCC #include #include #include "tweenpoint.h" #include "tweentraits.h" #include "easing.h" #include "easingresolve.h" #include "int2type.h" namespace tweeny { namespace detail { template void easingfill(EasingCollectionT & f, EasingT easing, int2type) { easingresolve::impl(f, easing); easingfill(f, easing, int2type{ }); } template void easingfill(EasingCollectionT & f, EasingT easing, int2type<0>) { easingresolve<0, TypeTupleT, EasingCollectionT, EasingT>::impl(f, easing); } template struct are_same; template struct are_same { static const bool value = std::is_same::value && are_same::value; }; template struct are_same { static const bool value = true; }; template inline tweenpoint::tweenpoint(Ts... vs) : values{vs...} { during(static_cast(0)); via(easing::def); } template template inline void tweenpoint::during(D milis) { for (uint16_t & t : durations) { t = static_cast(milis); } } template template inline void tweenpoint::during(Ds... milis) { static_assert(sizeof...(Ds) == sizeof...(Ts), "Amount of durations should be equal to the amount of values in a point"); std::array list = {{ milis... }}; std::copy(list.begin(), list.end(), durations.begin()); } template template inline void tweenpoint::via(Fs... fs) { static_assert(sizeof...(Fs) == sizeof...(Ts), "Number of functions passed to via() must be equal the number of values."); detail::easingresolve<0, std::tuple, typename traits::easingCollection, Fs...>::impl(easings, fs...); } template template inline void tweenpoint::via(F f) { easingfill(easings, f, int2type{ }); } template inline uint16_t tweenpoint::duration() const { return *std::max_element(durations.begin(), durations.end()); } template inline uint16_t tweenpoint::duration(size_t i) const { return durations.at(i); } } } #endif //TWEENY_TWEENPOINT_TCC