mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add quaternion adapt (hash, tuple)
This commit is contained in:
parent
35bd69d5d3
commit
37eea2c53d
35 changed files with 1941 additions and 974 deletions
71
sprout/math/quaternion/abs.hpp
Normal file
71
sprout/math/quaternion/abs.hpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2016 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_QUATERNION_ABS_HPP
|
||||
#define SPROUT_MATH_QUATERNION_ABS_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/math/quaternion/quaternion.hpp>
|
||||
#include <sprout/math/quaternion/detail/abs_max.hpp>
|
||||
#include <sprout/math/quaternion/detail/sum.hpp>
|
||||
#include <sprout/math/quaternion/detail/mul.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
//
|
||||
// abs
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs_q_impl_3(sprout::array<T, 4> const& temp, T const& maxim) {
|
||||
return maxim * sprout::math::sqrt(sprout::math::detail::sum(sprout::math::detail::mul(temp, temp)));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs_q_impl_2(sprout::array<T, 4> const& temp, T const& maxim) {
|
||||
return sprout::math::detail::abs_q_impl_3(
|
||||
sprout::math::detail::mul(temp, maxim), maxim
|
||||
);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs_q_impl_1(sprout::array<T, 4> const& temp, T const& maxim) {
|
||||
return maxim == static_cast<T>(0) ? sprout::math::quaternion<T>(maxim)
|
||||
: sprout::math::detail::abs_q_impl_2(
|
||||
temp, static_cast<T>(1) / maxim
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs_q_impl(sprout::array<T, 4> const& temp) {
|
||||
return sprout::math::detail::abs_q_impl_1(
|
||||
temp, sprout::math::detail::abs_max(temp)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs(sprout::math::quaternion<T> const& q) {
|
||||
return sprout::math::detail::abs_q_impl(
|
||||
sprout::array<T, 4>{{
|
||||
q.R_component_1(),
|
||||
q.R_component_2(),
|
||||
q.R_component_3(),
|
||||
q.R_component_4()
|
||||
}}
|
||||
);
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::abs;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_QUATERNION_ABS_HPP
|
Loading…
Add table
Add a link
Reference in a new issue