/*============================================================================= Copyright (c) 2011-2015 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_MATH_CURVE_CATMULL_ROM_SPRINE_HPP #define SPROUT_MATH_CURVE_CATMULL_ROM_SPRINE_HPP #include #include #include #include #include namespace sprout { namespace math { namespace detail { template class catmull_rom_sprine_impl { public: static SPROUT_CONSTEXPR typename sprout::math::curve_point_result::type call(Points const& p, T const& t) { using sprout::tuples::nested_get; using sprout::detail::pow2; using sprout::detail::pow3; return sprout::math::curve_point_traits::make( (-nested_get<0, 0>(p) + 3 * nested_get<1, 0>(p) - 3 * nested_get<2, 0>(p) + nested_get<3, 0>(p)) / 2 * pow3(t) + (2 * nested_get<0, 0>(p) - 5 * nested_get<1, 0>(p) + 4 * nested_get<2, 0>(p) - nested_get<3, 0>(p)) / 2 * pow2(t) + (-nested_get<0, 0>(p) + nested_get<2, 0>(p)) / 2 * t + nested_get<1, 0>(p) , (-nested_get<0, 1>(p) + 3 * nested_get<1, 1>(p) - 3 * nested_get<2, 1>(p) + nested_get<3, 1>(p)) / 2 * pow3(t) + (2 * nested_get<0, 1>(p) - 5 * nested_get<1, 1>(p) + 4 * nested_get<2, 1>(p) - nested_get<3, 1>(p)) / 2 * pow2(t) + (-nested_get<0, 1>(p) + nested_get<2, 1>(p)) / 2 * t + nested_get<1, 1>(p) ); } }; template class catmull_rom_sprine_start_impl { public: static SPROUT_CONSTEXPR typename sprout::math::curve_point_result::type call(Points const& p, T const& t) { using sprout::tuples::nested_get; using sprout::detail::pow2; return sprout::math::curve_point_traits::make( (nested_get<0, 0>(p) - 2 * nested_get<1, 0>(p) + nested_get<2, 0>(p)) / 2 * pow2(t) + (-3 * nested_get<0, 0>(p) + 4 * nested_get<1, 0>(p) - nested_get<2, 0>(p)) / 2 * t + nested_get<0, 0>(p) , (nested_get<0, 1>(p) - 2 * nested_get<1, 1>(p) + nested_get<2, 1>(p)) / 2 * pow2(t) + (-3 * nested_get<0, 1>(p) + 4 * nested_get<1, 1>(p) - nested_get<2, 1>(p)) / 2 * t + nested_get<0, 1>(p) ); } }; template class catmull_rom_sprine_end_impl { public: static SPROUT_CONSTEXPR typename sprout::math::curve_point_result::type call(Points const& p, T const& t) { using sprout::tuples::nested_get; using sprout::detail::pow2; return sprout::math::curve_point_traits::make( (nested_get<0, 0>(p) - 2 * nested_get<1, 0>(p) + nested_get<2, 0>(p)) / 2 * pow2(t) + (-nested_get<0, 0>(p) + nested_get<2, 0>(p)) / 2 * t + nested_get<1, 0>(p) , (nested_get<0, 1>(p) - 2 * nested_get<1, 1>(p) + nested_get<2, 1>(p)) / 2 * pow2(t) + (-nested_get<0, 1>(p) + nested_get<2, 1>(p)) / 2 * t + nested_get<1, 1>(p) ); } }; } // namespace detail // // catmull_rom_sprine // catmull_rom_sprine_start // catmull_rom_sprine_end // template inline SPROUT_CONSTEXPR typename sprout::math::curve_point_result::type catmull_rom_sprine(T const& t, Points const& p) { return sprout::math::detail::catmull_rom_sprine_impl::call(p, t); } template inline SPROUT_CONSTEXPR typename sprout::math::curve_point_result::type catmull_rom_sprine_start(T const& t, Points const& p) { return sprout::math::detail::catmull_rom_sprine_start_impl::call(p, t); } template inline SPROUT_CONSTEXPR typename sprout::math::curve_point_result::type catmull_rom_sprine_end(T const& t, Points const& p) { return sprout::math::detail::catmull_rom_sprine_end_impl::call(p, t); } template inline SPROUT_CONSTEXPR typename sprout::math::curve_point_result >::type catmull_rom_sprine(T const& t, P0 const& p0, P1 const& p1, P2 const& p2, P3 const& p3) { return sprout::math::catmull_rom_sprine(t, sprout::tuples::forward_as_tuple(p0, p1, p2, p3)); } template inline SPROUT_CONSTEXPR typename sprout::math::curve_point_result >::type catmull_rom_sprine_start(T const& t, P0 const& p0, P1 const& p1, P2 const& p2) { return sprout::math::catmull_rom_sprine_start(t, sprout::tuples::forward_as_tuple(p0, p1, p2)); } template inline SPROUT_CONSTEXPR typename sprout::math::curve_point_result >::type catmull_rom_sprine_end(T const& t, P0 const& p0, P1 const& p1, P2 const& p2) { return sprout::math::catmull_rom_sprine_end(t, sprout::tuples::forward_as_tuple(p0, p1, p2)); } } // namespace math using sprout::math::catmull_rom_sprine; using sprout::math::catmull_rom_sprine_start; using sprout::math::catmull_rom_sprine_end; } // namespace sprout #endif // #ifndef SPROUT_MATH_CURVE_CATMULL_ROM_SPRINE_HPP