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
38
sprout/math/quaternion/detail/abs_max.hpp
Normal file
38
sprout/math/quaternion/detail/abs_max.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*=============================================================================
|
||||
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_DETAIL_ABS_MAX_HPP
|
||||
#define SPROUT_MATH_QUATERNION_DETAIL_ABS_MAX_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/math/abs.hpp>
|
||||
#include <sprout/range/algorithm/max_element.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
class abs_less {
|
||||
public:
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& lhs, T const& rhs) const {
|
||||
return sprout::math::abs(lhs) < sprout::math::abs(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR T
|
||||
abs_max(sprout::array<T, N> const& c) {
|
||||
return sprout::math::abs(*sprout::range::max_element(c, sprout::math::detail::abs_less<T>()));
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace math
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_QUATERNION_DETAIL_ABS_MAX_HPP
|
57
sprout/math/quaternion/detail/mul.hpp
Normal file
57
sprout/math/quaternion/detail/mul.hpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*=============================================================================
|
||||
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_DETAIL_MUL_HPP
|
||||
#define SPROUT_MATH_QUATERNION_DETAIL_MUL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::array<T, 2>
|
||||
mul(sprout::array<T, 2> const& l, T const& r) {
|
||||
return sprout::array<T, 2>{{
|
||||
l[0] * r,
|
||||
l[1] * r,
|
||||
}};
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::array<T, 2>
|
||||
mul(sprout::array<T, 2> const& l, sprout::array<T, 2> const& r) {
|
||||
return sprout::array<T, 2>{{
|
||||
l[0] * r[0],
|
||||
l[1] * r[1],
|
||||
}};
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::array<T, 4>
|
||||
mul(sprout::array<T, 4> const& l, T const& r) {
|
||||
return sprout::array<T, 4>{{
|
||||
l[0] * r,
|
||||
l[1] * r,
|
||||
l[2] * r,
|
||||
l[3] * r
|
||||
}};
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::array<T, 4>
|
||||
mul(sprout::array<T, 4> const& l, sprout::array<T, 4> const& r) {
|
||||
return sprout::array<T, 4>{{
|
||||
l[0] * r[0],
|
||||
l[1] * r[1],
|
||||
l[2] * r[2],
|
||||
l[3] * r[3]
|
||||
}};
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace math
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_QUATERNION_DETAIL_MUL_HPP
|
43
sprout/math/quaternion/detail/sum.hpp
Normal file
43
sprout/math/quaternion/detail/sum.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*=============================================================================
|
||||
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_DETAIL_SUM_HPP
|
||||
#define SPROUT_MATH_QUATERNION_DETAIL_SUM_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/math/abs.hpp>
|
||||
#include <sprout/range/numeric/accumulate.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
class abs_plus {
|
||||
public:
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& lhs, T const& rhs) const {
|
||||
return sprout::math::abs(lhs) + sprout::math::abs(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR T
|
||||
sum(sprout::array<T, N> const& c) {
|
||||
return sprout::range::accumulate(c, static_cast<T>(0));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR T
|
||||
abs_sum(sprout::array<T, N> const& c) {
|
||||
return sprout::range::accumulate(c, static_cast<T>(0), sprout::math::detail::abs_plus<T>());
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace math
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_QUATERNION_DETAIL_SUM_HPP
|
Loading…
Add table
Add a link
Reference in a new issue