From 37eea2c53d7a98fb5747001a4585bfba1de0437b Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 27 Feb 2016 01:21:46 +0900 Subject: [PATCH] add quaternion adapt (hash, tuple) --- sprout/complex/container.hpp | 2 +- sprout/math/quaternion.hpp | 8 + sprout/math/quaternion/abs.hpp | 71 ++ sprout/math/quaternion/conj.hpp | 34 + sprout/math/quaternion/container.hpp | 8 +- sprout/math/quaternion/cos.hpp | 60 ++ sprout/math/quaternion/cosh.hpp | 31 + sprout/math/quaternion/creations.hpp | 18 + sprout/math/quaternion/cylindrical.hpp | 36 + sprout/math/quaternion/cylindrospherical.hpp | 36 + sprout/math/quaternion/detail/abs_max.hpp | 38 + sprout/math/quaternion/detail/mul.hpp | 57 ++ sprout/math/quaternion/detail/sum.hpp | 43 + sprout/math/quaternion/exp.hpp | 58 ++ sprout/math/quaternion/hash.hpp | 45 + sprout/math/quaternion/l1.hpp | 38 + sprout/math/quaternion/multipolar.hpp | 36 + sprout/math/quaternion/norm.hpp | 32 + sprout/math/quaternion/operators.hpp | 562 +++++++++++ sprout/math/quaternion/pow.hpp | 44 + sprout/math/quaternion/quaternion.hpp | 973 +------------------ sprout/math/quaternion/real.hpp | 29 + sprout/math/quaternion/semipolar.hpp | 36 + sprout/math/quaternion/sin.hpp | 60 ++ sprout/math/quaternion/sinh.hpp | 31 + sprout/math/quaternion/spherical.hpp | 46 + sprout/math/quaternion/sup.hpp | 38 + sprout/math/quaternion/tan.hpp | 32 + sprout/math/quaternion/tanh.hpp | 32 + sprout/math/quaternion/transcendentals.hpp | 21 + sprout/math/quaternion/tuple.hpp | 139 +++ sprout/math/quaternion/type_traits.hpp | 49 + sprout/math/quaternion/udl.hpp | 123 +++ sprout/math/quaternion/unreal.hpp | 29 + sprout/math/quaternion/values.hpp | 20 + 35 files changed, 1941 insertions(+), 974 deletions(-) create mode 100644 sprout/math/quaternion/abs.hpp create mode 100644 sprout/math/quaternion/conj.hpp create mode 100644 sprout/math/quaternion/cos.hpp create mode 100644 sprout/math/quaternion/cosh.hpp create mode 100644 sprout/math/quaternion/creations.hpp create mode 100644 sprout/math/quaternion/cylindrical.hpp create mode 100644 sprout/math/quaternion/cylindrospherical.hpp create mode 100644 sprout/math/quaternion/detail/abs_max.hpp create mode 100644 sprout/math/quaternion/detail/mul.hpp create mode 100644 sprout/math/quaternion/detail/sum.hpp create mode 100644 sprout/math/quaternion/exp.hpp create mode 100644 sprout/math/quaternion/hash.hpp create mode 100644 sprout/math/quaternion/l1.hpp create mode 100644 sprout/math/quaternion/multipolar.hpp create mode 100644 sprout/math/quaternion/norm.hpp create mode 100644 sprout/math/quaternion/operators.hpp create mode 100644 sprout/math/quaternion/pow.hpp create mode 100644 sprout/math/quaternion/real.hpp create mode 100644 sprout/math/quaternion/semipolar.hpp create mode 100644 sprout/math/quaternion/sin.hpp create mode 100644 sprout/math/quaternion/sinh.hpp create mode 100644 sprout/math/quaternion/spherical.hpp create mode 100644 sprout/math/quaternion/sup.hpp create mode 100644 sprout/math/quaternion/tan.hpp create mode 100644 sprout/math/quaternion/tanh.hpp create mode 100644 sprout/math/quaternion/transcendentals.hpp create mode 100644 sprout/math/quaternion/tuple.hpp create mode 100644 sprout/math/quaternion/type_traits.hpp create mode 100644 sprout/math/quaternion/udl.hpp create mode 100644 sprout/math/quaternion/unreal.hpp create mode 100644 sprout/math/quaternion/values.hpp diff --git a/sprout/complex/container.hpp b/sprout/complex/container.hpp index 2c30d501..284fb356 100644 --- a/sprout/complex/container.hpp +++ b/sprout/complex/container.hpp @@ -8,7 +8,7 @@ #ifndef SPROUT_COMPLEX_CONTAINER_HPP #define SPROUT_COMPLEX_CONTAINER_HPP -#include +#include #include #include #include diff --git a/sprout/math/quaternion.hpp b/sprout/math/quaternion.hpp index b4b682c5..499ad207 100644 --- a/sprout/math/quaternion.hpp +++ b/sprout/math/quaternion.hpp @@ -10,6 +10,14 @@ #include #include +#include +#include +#include +#include +#include +#include #include +#include +#include #endif // #ifndef SPROUT_MATH_QUATERNION_HPP diff --git a/sprout/math/quaternion/abs.hpp b/sprout/math/quaternion/abs.hpp new file mode 100644 index 00000000..32ca6974 --- /dev/null +++ b/sprout/math/quaternion/abs.hpp @@ -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 +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // abs + // + namespace detail { + template + inline SPROUT_CONSTEXPR T + abs_q_impl_3(sprout::array const& temp, T const& maxim) { + return maxim * sprout::math::sqrt(sprout::math::detail::sum(sprout::math::detail::mul(temp, temp))); + } + template + inline SPROUT_CONSTEXPR T + abs_q_impl_2(sprout::array const& temp, T const& maxim) { + return sprout::math::detail::abs_q_impl_3( + sprout::math::detail::mul(temp, maxim), maxim + ); + } + template + inline SPROUT_CONSTEXPR T + abs_q_impl_1(sprout::array const& temp, T const& maxim) { + return maxim == static_cast(0) ? sprout::math::quaternion(maxim) + : sprout::math::detail::abs_q_impl_2( + temp, static_cast(1) / maxim + ) + ; + } + template + inline SPROUT_CONSTEXPR T + abs_q_impl(sprout::array const& temp) { + return sprout::math::detail::abs_q_impl_1( + temp, sprout::math::detail::abs_max(temp) + ); + } + } // namespace detail + template + inline SPROUT_CONSTEXPR T + abs(sprout::math::quaternion const& q) { + return sprout::math::detail::abs_q_impl( + sprout::array{{ + 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 diff --git a/sprout/math/quaternion/conj.hpp b/sprout/math/quaternion/conj.hpp new file mode 100644 index 00000000..856c6ab9 --- /dev/null +++ b/sprout/math/quaternion/conj.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + 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_CONJ_HPP +#define SPROUT_MATH_QUATERNION_CONJ_HPP + +#include +#include + +namespace sprout { + namespace math { + // + // conj + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + conj(sprout::math::quaternion const& q) { + return sprout::math::quaternion( + +q.R_component_1(), + -q.R_component_2(), + -q.R_component_3(), + -q.R_component_4() + ); + } + } // namespace math + + using sprout::math::conj; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_CONJ_HPP diff --git a/sprout/math/quaternion/container.hpp b/sprout/math/quaternion/container.hpp index 9f66d093..adad4dcf 100644 --- a/sprout/math/quaternion/container.hpp +++ b/sprout/math/quaternion/container.hpp @@ -5,10 +5,10 @@ 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_QUATERNION_CONTAINER_HPP -#define SPROUT_QUATERNION_CONTAINER_HPP +#ifndef SPROUT_MATH_QUATERNION_CONTAINER_HPP +#define SPROUT_MATH_QUATERNION_CONTAINER_HPP -#include +#include #include #include #include @@ -40,4 +40,4 @@ namespace sprout { }; } // namespace sprout -#endif // #ifndef SPROUT_QUATERNION_CONTAINER_HPP +#endif // #ifndef SPROUT_MATH_QUATERNION_CONTAINER_HPP diff --git a/sprout/math/quaternion/cos.hpp b/sprout/math/quaternion/cos.hpp new file mode 100644 index 00000000..6db17e78 --- /dev/null +++ b/sprout/math/quaternion/cos.hpp @@ -0,0 +1,60 @@ +/*============================================================================= + 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_COS_HPP +#define SPROUT_MATH_QUATERNION_COS_HPP + +#include +#include +#include +#include +//#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // cos + // + // !!! +// namespace detail { +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// cos_impl_1(sprout::math::quaternion const& q, T const& z, T const& w) { +// return sprout::math::quaternion( +// sprout::math::cos(sprout::math::real(q)) * sprout::math::cosh(z), +// w * q.R_component_2(), +// w * q.R_component_3(), +// w * q.R_component_4() +// ); +// } +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// cos_impl(sprout::math::quaternion const& q, T const& z) { +// return sprout::math::detail::cos_impl_1( +// q, z, +// -sprout::math::sin(sprout::math::real(q)) * sprout::math::sinhc_pi(z) +// ); +// } +// } // namespace detail +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// cos(sprout::math::quaternion const& q) { +// return sprout::math::detail::cos_impl( +// q, +// sprout::math::abs(sprout::math::unreal(q)) +// ); +// } + } // namespace math + +// using sprout::math::cos; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_COS_HPP diff --git a/sprout/math/quaternion/cosh.hpp b/sprout/math/quaternion/cosh.hpp new file mode 100644 index 00000000..b033a6be --- /dev/null +++ b/sprout/math/quaternion/cosh.hpp @@ -0,0 +1,31 @@ +/*============================================================================= + 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_COSH_HPP +#define SPROUT_MATH_QUATERNION_COSH_HPP + +#include +#include +#include + +namespace sprout { + namespace math { + // + // cosh + // + // !!! +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// cosh(sprout::math::quaternion const& q) { +// return (sprout::math::exp(+q) + sprout::math::exp(-q)) / static_cast(2); +// } + } // namespace math + +// using sprout::math::cosh; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_COSH_HPP diff --git a/sprout/math/quaternion/creations.hpp b/sprout/math/quaternion/creations.hpp new file mode 100644 index 00000000..4220383d --- /dev/null +++ b/sprout/math/quaternion/creations.hpp @@ -0,0 +1,18 @@ +/*============================================================================= + 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_CREATIONS_HPP +#define SPROUT_MATH_QUATERNION_CREATIONS_HPP + +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_MATH_QUATERNION_CREATIONS_HPP diff --git a/sprout/math/quaternion/cylindrical.hpp b/sprout/math/quaternion/cylindrical.hpp new file mode 100644 index 00000000..f5715047 --- /dev/null +++ b/sprout/math/quaternion/cylindrical.hpp @@ -0,0 +1,36 @@ +/*============================================================================= + 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_CYLINDRICAL_HPP +#define SPROUT_MATH_QUATERNION_CYLINDRICAL_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // cylindrical + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + cylindrical(T const& r, T const& angle, T const& h1, T const& h2) { + return sprout::math::quaternion( + r * sprout::math::cos(angle), + r * sprout::math::sin(angle), + h1, + h2 + ); + } + } // namespace math + + using sprout::math::cylindrical; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_CYLINDRICAL_HPP diff --git a/sprout/math/quaternion/cylindrospherical.hpp b/sprout/math/quaternion/cylindrospherical.hpp new file mode 100644 index 00000000..70937b92 --- /dev/null +++ b/sprout/math/quaternion/cylindrospherical.hpp @@ -0,0 +1,36 @@ +/*============================================================================= + 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_CYLINDROSPERICAL_HPP +#define SPROUT_MATH_QUATERNION_CYLINDROSPERICAL_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // cylindrospherical + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + cylindrospherical(T const& t, T const& radius, T const& longitude, T const& latitude) { + return sprout::math::quaternion( + t, + radius * sprout::math::cos(longitude) * sprout::math::cos(latitude), + radius * sprout::math::sin(longitude) * sprout::math::cos(latitude), + radius * sprout::math::sin(latitude) + ); + } + } // namespace math + + using sprout::math::cylindrospherical; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_CYLINDROSPERICAL_HPP diff --git a/sprout/math/quaternion/detail/abs_max.hpp b/sprout/math/quaternion/detail/abs_max.hpp new file mode 100644 index 00000000..c6c7a8bf --- /dev/null +++ b/sprout/math/quaternion/detail/abs_max.hpp @@ -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 +#include +#include +#include +#include + +namespace sprout { + namespace math { + namespace detail { + template + 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 + SPROUT_CONSTEXPR T + abs_max(sprout::array const& c) { + return sprout::math::abs(*sprout::range::max_element(c, sprout::math::detail::abs_less())); + } + } // namespace detail + } // namespace math +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_DETAIL_ABS_MAX_HPP diff --git a/sprout/math/quaternion/detail/mul.hpp b/sprout/math/quaternion/detail/mul.hpp new file mode 100644 index 00000000..ae50236a --- /dev/null +++ b/sprout/math/quaternion/detail/mul.hpp @@ -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 +#include + +namespace sprout { + namespace math { + namespace detail { + template + SPROUT_CONSTEXPR sprout::array + mul(sprout::array const& l, T const& r) { + return sprout::array{{ + l[0] * r, + l[1] * r, + }}; + } + template + SPROUT_CONSTEXPR sprout::array + mul(sprout::array const& l, sprout::array const& r) { + return sprout::array{{ + l[0] * r[0], + l[1] * r[1], + }}; + } + template + SPROUT_CONSTEXPR sprout::array + mul(sprout::array const& l, T const& r) { + return sprout::array{{ + l[0] * r, + l[1] * r, + l[2] * r, + l[3] * r + }}; + } + template + SPROUT_CONSTEXPR sprout::array + mul(sprout::array const& l, sprout::array const& r) { + return sprout::array{{ + 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 diff --git a/sprout/math/quaternion/detail/sum.hpp b/sprout/math/quaternion/detail/sum.hpp new file mode 100644 index 00000000..fdc29d19 --- /dev/null +++ b/sprout/math/quaternion/detail/sum.hpp @@ -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 +#include +#include +#include +#include + +namespace sprout { + namespace math { + namespace detail { + template + 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 + SPROUT_CONSTEXPR T + sum(sprout::array const& c) { + return sprout::range::accumulate(c, static_cast(0)); + } + template + SPROUT_CONSTEXPR T + abs_sum(sprout::array const& c) { + return sprout::range::accumulate(c, static_cast(0), sprout::math::detail::abs_plus()); + } + } // namespace detail + } // namespace math +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_DETAIL_SUM_HPP diff --git a/sprout/math/quaternion/exp.hpp b/sprout/math/quaternion/exp.hpp new file mode 100644 index 00000000..cd097e85 --- /dev/null +++ b/sprout/math/quaternion/exp.hpp @@ -0,0 +1,58 @@ +/*============================================================================= + 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_EXP_HPP +#define SPROUT_MATH_QUATERNION_EXP_HPP + +#include +#include +#include +//#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // exp + // + // !!! +// namespace detail { +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// exp_impl_1(sprout::math::quaternion const& q, T const& z, T const& w) { +// return sprout::math::exp(sprout::math::real(q)) * sprout::math::quaternion( +// sprout::math::cos(z), +// w * q.R_component_2(), +// w * q.R_component_3(), +// w * q.R_component_4() +// ); +// } +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// exp_impl(sprout::math::quaternion const& q, T const& z) { +// return sprout::math::detail::exp_impl_1( +// q, z, +// sprout::math::sinc_pi(z) +// ); +// } +// } // namespace detail +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// exp(sprout::math::quaternion const& q) { +// return sprout::math::detail::exp_impl( +// q, +// sprout::math::abs(sprout::math::unreal(q)) +// ); +// } + } // namespace math + +// using sprout::math::exp; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_EXP_HPP diff --git a/sprout/math/quaternion/hash.hpp b/sprout/math/quaternion/hash.hpp new file mode 100644 index 00000000..ae1efea7 --- /dev/null +++ b/sprout/math/quaternion/hash.hpp @@ -0,0 +1,45 @@ +/*============================================================================= + 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_HASH_HPP +#define SPROUT_MATH_QUATERNION_HASH_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // hash_value + // + template + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::math::quaternion const& v) { + return sprout::hash_values(v[0], v[1], v[2], v[3]); + } +} // namespace sprout + +namespace std { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmismatched-tags" +#endif + // + // hash + // + template + struct hash > + : public sprout::hash > + {}; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +} // namespace std + +#endif // #ifndef SPROUT_MATH_QUATERNION_HASH_HPP diff --git a/sprout/math/quaternion/l1.hpp b/sprout/math/quaternion/l1.hpp new file mode 100644 index 00000000..5ad2591a --- /dev/null +++ b/sprout/math/quaternion/l1.hpp @@ -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_SUP_HPP +#define SPROUT_MATH_QUATERNION_SUP_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // l1 + // + template + inline SPROUT_CONSTEXPR T + l1(sprout::math::quaternion const& q) { + return sprout::math::detail::abs_sum( + sprout::array{{ + q.R_component_1(), + q.R_component_2(), + q.R_component_3(), + q.R_component_4() + }} + ); + } + } // namespace math + + using sprout::math::l1; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_SUP_HPP diff --git a/sprout/math/quaternion/multipolar.hpp b/sprout/math/quaternion/multipolar.hpp new file mode 100644 index 00000000..be51d3db --- /dev/null +++ b/sprout/math/quaternion/multipolar.hpp @@ -0,0 +1,36 @@ +/*============================================================================= + 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_MULTIPOLAR_HPP +#define SPROUT_MATH_QUATERNION_MULTIPOLAR_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // multipolar + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + multipolar(T const& rho1, T const& theta1, T const& rho2, T const& theta2) { + return sprout::math::quaternion( + rho1 * sprout::math::cos(theta1), + rho1 * sprout::math::sin(theta1), + rho2 * sprout::math::cos(theta2), + rho2 * sprout::math::sin(theta2) + ); + } + } // namespace math + + using sprout::math::multipolar; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_MULTIPOLAR_HPP diff --git a/sprout/math/quaternion/norm.hpp b/sprout/math/quaternion/norm.hpp new file mode 100644 index 00000000..391dbbb7 --- /dev/null +++ b/sprout/math/quaternion/norm.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + 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_NORM_HPP +#define SPROUT_MATH_QUATERNION_NORM_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // norm + // + template + inline SPROUT_CONSTEXPR T + norm(sprout::math::quaternion const& q) { + return sprout::math::real(q * sprout::math::conj(q)); + } + } // namespace math + + using sprout::math::norm; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_NORM_HPP diff --git a/sprout/math/quaternion/operators.hpp b/sprout/math/quaternion/operators.hpp new file mode 100644 index 00000000..5f20baaf --- /dev/null +++ b/sprout/math/quaternion/operators.hpp @@ -0,0 +1,562 @@ +/*============================================================================= + 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_OPERATORS_HPP +#define SPROUT_MATH_QUATERNION_OPERATORS_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // operator+ + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator+(T const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs + rhs.R_component_1(), + rhs.R_component_2(), + rhs.R_component_3(), + rhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator+(sprout::math::quaternion const& lhs, T const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() + rhs, + lhs.R_component_2(), + lhs.R_component_3(), + lhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator+(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs.real() + rhs.R_component_1(), + lhs.imag() + rhs.R_component_2(), + rhs.R_component_3(), + rhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator+(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() + rhs.real(), + lhs.R_component_2() + rhs.imag(), + lhs.R_component_3(), + lhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator+(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() + rhs.R_component_1(), + lhs.R_component_2() + rhs.R_component_2(), + lhs.R_component_3() + rhs.R_component_3(), + lhs.R_component_4() + rhs.R_component_4() + ); + } + // + // operator- + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator-(T const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs - rhs.R_component_1(), + rhs.R_component_2(), + rhs.R_component_3(), + rhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator-(sprout::math::quaternion const& lhs, T const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() - rhs, + lhs.R_component_2(), + lhs.R_component_3(), + lhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator-(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs.real() - rhs.R_component_1(), + lhs.imag() - rhs.R_component_2(), + rhs.R_component_3(), + rhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator-(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() - rhs.real(), + lhs.R_component_2() - rhs.imag(), + lhs.R_component_3(), + lhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator-(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() - rhs.R_component_1(), + lhs.R_component_2() - rhs.R_component_2(), + lhs.R_component_3() - rhs.R_component_3(), + lhs.R_component_4() - rhs.R_component_4() + ); + } + // + // operator* + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator*(T const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs * rhs.R_component_1(), + lhs * rhs.R_component_2(), + lhs * rhs.R_component_3(), + lhs * rhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator*(sprout::math::quaternion const& lhs, T const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() * rhs, + lhs.R_component_2() * rhs, + lhs.R_component_3() * rhs, + lhs.R_component_4() * rhs + ); + } + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + mul_qc_impl(T const& a, T const& b, T const& c, T const& d, T const& ar, T const& br) { + return sprout::math::quaternion( + +a * ar - b * br, + +a * br + b * ar, + +c * ar + d * br, + -c * br + d * ar + ); + } + } // namespace detail + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator*(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::detail::mul_qc_impl( + lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), + rhs.real(), rhs.imag() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator*(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { + return sprout::math::detail::mul_qc_impl( + rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4(), + lhs.real(), lhs.imag() + ); + } + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + mul_qq_impl(T const& a, T const& b, T const& c, T const& d, T const& ar, T const& br, T const& cr, T const& dr) { + return sprout::math::quaternion( + +a * ar - b * br - c * cr - d * dr, + +a * br + b * ar + c * dr - d * cr, + +a * cr - b * dr + c * ar + d * br, + +a * dr + b * cr - c * br + d * ar + ); + } + } // namespace detail + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator*(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::detail::mul_qq_impl( + lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), + rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4() + ); + } + // + // operator/ + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator/(T const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::quaternion( + lhs / rhs.R_component_1(), + lhs / rhs.R_component_2(), + lhs / rhs.R_component_3(), + lhs / rhs.R_component_4() + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator/(sprout::math::quaternion const& lhs, T const& rhs) { + return sprout::math::quaternion( + lhs.R_component_1() / rhs, + lhs.R_component_2() / rhs, + lhs.R_component_3() / rhs, + lhs.R_component_4() / rhs + ); + } + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + div_qq_impl_4(sprout::array const& tt) { + return sprout::math::quaternion( + tt[0], tt[1], tt[2], tt[3] + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + div_qq_impl_3(sprout::array const& tr, T const& mixam, sprout::array const& tt) { + return sprout::math::detail::div_qq_impl_3( + sprout::math::detail::mul(tt, mixam / sprout::math::detail::sum(tr)) + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + div_qq_impl_2(T const& a, T const& b, T const& c, T const& d, sprout::array const& tr, T const& mixam) { + return sprout::math::detail::div_qq_impl_3( + sprout::math::detail::mul(tr, tr), mixam, + sprout::array{{ + +a * tr[0] + b * tr[1] + c * tr[2] + d * tr[3], + -a * tr[1] + b * tr[0] - c * tr[3] + d * tr[2], + -a * tr[2] + b * tr[3] + c * tr[0] - d * tr[1], + -a * tr[3] - b * tr[2] + c * tr[1] + d * tr[0] + }} + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + div_qq_impl_1(T const& a, T const& b, T const& c, T const& d, sprout::array const& tr, T const& mixam) { + return sprout::math::detail::div_qq_impl_2( + a, b, c, d, sprout::math::detail::mul(tr, mixam), mixam + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + div_qq_impl(T const& a, T const& b, T const& c, T const& d, sprout::array const& tr) { + return sprout::math::detail::div_qq_impl_1( + a, b, c, d, tr, + static_cast(1) / sprout::math::detail::abs_max(tr) + ); + } + } // namespace detail + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator/(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::detail::div_qq_impl( + lhs.real(), lhs.imag(), static_cast(0), static_cast(0), + sprout::array{{rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4()}} + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator/(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { + return sprout::math::detail::div_qq_impl( + lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), + sprout::array{{rhs.real(), rhs.imag(), static_cast(0), static_cast(0)}} + ); + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator/(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { + return sprout::math::detail::div_qq_impl( + lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), + sprout::array{{rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4()}} + ); + } + + // + // operator+ + // operator- + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator+(sprout::math::quaternion const& q) { + return q; + } + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator-(sprout::math::quaternion const& q) { + return sprout::math::quaternion(-q.R_component_1(), -q.R_component_2(), -q.R_component_3(), -q.R_component_4()); + } + + // + // operator== + // operator!= + // + template + inline SPROUT_CONSTEXPR bool + operator==(T const& lhs, sprout::math::quaternion const& rhs) { + return rhs.R_component_1() == lhs + && rhs.R_component_2() == static_cast(0) + && rhs.R_component_3() == static_cast(0) + && rhs.R_component_4() == static_cast(0) + ; + } + template + inline SPROUT_CONSTEXPR bool + operator==(sprout::math::quaternion const& lhs, T const& rhs) { + return lhs.R_component_1() == rhs + && lhs.R_component_2() == static_cast(0) + && lhs.R_component_3() == static_cast(0) + && lhs.R_component_4() == static_cast(0) + ; + } + template + inline SPROUT_CONSTEXPR bool + operator==(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { + return rhs.R_component_1() == lhs.real() + && rhs.R_component_2() == lhs.imag() + && rhs.R_component_3() == static_cast(0) + && rhs.R_component_4() == static_cast(0) + ; + } + template + inline SPROUT_CONSTEXPR bool + operator==(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { + return lhs.R_component_1() == rhs.real() + && lhs.R_component_2() == rhs.imag() + && lhs.R_component_3() == static_cast(0) + && lhs.R_component_4() == static_cast(0) + ; + } + template + inline SPROUT_CONSTEXPR bool + operator==(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { + return rhs.R_component_1() == lhs.R_component_1() + && rhs.R_component_2() == lhs.R_component_2() + && rhs.R_component_3() == lhs.R_component_3() + && rhs.R_component_4() == lhs.R_component_4() + ; + } + +#define SPROUT_QUATERNION_NOT_EQUAL_GENERATOR \ + { \ + return !(lhs == rhs); \ + } + + template + inline SPROUT_CONSTEXPR bool + operator!=(T const& lhs, sprout::math::quaternion const& rhs) + SPROUT_QUATERNION_NOT_EQUAL_GENERATOR + template + inline SPROUT_CONSTEXPR bool + operator!=(sprout::math::quaternion const& lhs, T const& rhs) + SPROUT_QUATERNION_NOT_EQUAL_GENERATOR + template + inline SPROUT_CONSTEXPR bool + operator!=(sprout::complex const& lhs, sprout::math::quaternion const& rhs) + SPROUT_QUATERNION_NOT_EQUAL_GENERATOR + template + inline SPROUT_CONSTEXPR bool + operator!=(sprout::math::quaternion const& lhs, sprout::complex const& rhs) + SPROUT_QUATERNION_NOT_EQUAL_GENERATOR + template + inline SPROUT_CONSTEXPR bool + operator!=(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) + SPROUT_QUATERNION_NOT_EQUAL_GENERATOR + +#undef SPROUT_QUATERNION_NOT_EQUAL_GENERATOR + + // + // operator<< + // operator>> + // + template + inline SPROUT_NON_CONSTEXPR std::basic_ostream& + operator<<( std::basic_ostream& lhs, sprout::math::quaternion const& rhs) { + std::basic_ostringstream s; + s.flags(lhs.flags()); + s.imbue(lhs.getloc()); + s.precision(lhs.precision()); + s + << '(' + << rhs.R_component_1() << ',' + << rhs.R_component_2() << ',' + << rhs.R_component_3() << ',' + << rhs.R_component_4() + << ')' + ; + return lhs << s.str(); + } + template + inline SPROUT_NON_CONSTEXPR std::basic_istream& + operator>>(std::basic_istream& lhs, sprout::math::quaternion& rhs) { + std::ctype const& ct = std::use_facet >(lhs.getloc()); + T a = T(); + T b = T(); + T c = T(); + T d = T(); + sprout::complex u = sprout::complex(); + sprout::complex v = sprout::complex(); + Elem ch = Elem(); + char cc; + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == '(') { + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == '(') { + lhs.putback(ch); + lhs >> u; + a = u.real(); + b = u.imag(); + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a, b); + } else if (cc == ',') { + lhs >> v; + c = v.real(); + d = v.imag(); + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a, b, c, d); + } else { + lhs.setstate(std::ios_base::failbit); + } + } else { + lhs.setstate(std::ios_base::failbit); + } + } else { + lhs.putback(ch); + lhs >> a; + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a); + } else if (cc == ',') { + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == '(') { + lhs.putback(ch); + lhs >> v; + c = v.real(); + d = v.imag(); + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a, b, c, d); + } else { + lhs.setstate(std::ios_base::failbit); + } + } else { + lhs.putback(ch); + lhs >> b; + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a, b); + } else if (cc == ',') { + lhs >> c; + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a, b, c); + } else if (cc == ',') { + lhs >> d; + if (!lhs.good()) { + goto finish; + } + lhs >> ch; + if (!lhs.good()) { + goto finish; + } + cc = ct.narrow(ch, char()); + if (cc == ')') { + rhs = sprout::math::quaternion(a, b, c, d); + } else { + lhs.setstate(std::ios_base::failbit); + } + } else { + lhs.setstate(std::ios_base::failbit); + } + } else { + lhs.setstate(std::ios_base::failbit); + } + } + } else { + lhs.setstate(std::ios_base::failbit); + } + } + } else { + lhs.putback(ch); + lhs >> a; + if (!lhs.good()) { + goto finish; + } + rhs = sprout::math::quaternion(a); + } + finish: + return lhs; + } + } // namespace math +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_OPERATORS_HPP diff --git a/sprout/math/quaternion/pow.hpp b/sprout/math/quaternion/pow.hpp new file mode 100644 index 00000000..a40f0cf1 --- /dev/null +++ b/sprout/math/quaternion/pow.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + 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_POW_HPP +#define SPROUT_MATH_QUATERNION_POW_HPP + +#include +#include + +namespace sprout { + namespace math { + // + // pow + // + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + pow_q_impl(sprout::math::quaternion const& q, int n, int m, sprout::math::quaternion const& result) { + return n != m << 1 ? result * result * q + : result * result + ; + } + } // namespace detail + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + pow(sprout::math::quaternion const& q, int n) { + return n > 1 ? sprout::math::detail::pow_q_impl( + q, n, n >> 1, sprout::math::pow(q, n >> 1) + ) + : n == 1 ? q + : n == 0 ? sprout::math::quaternion(static_cast(1)) + : sprout::math::pow(sprout::math::quaternion(static_cast(1)) / q, -n) + ; + } + } // namespace math + + using sprout::math::pow; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_POW_HPP diff --git a/sprout/math/quaternion/quaternion.hpp b/sprout/math/quaternion/quaternion.hpp index 6cd10073..5da2363e 100644 --- a/sprout/math/quaternion/quaternion.hpp +++ b/sprout/math/quaternion/quaternion.hpp @@ -8,94 +8,16 @@ #ifndef SPROUT_MATH_QUATERNION_QUATERNION_HPP #define SPROUT_MATH_QUATERNION_QUATERNION_HPP -#include -#include -#include #include +#include #include -#include -#include -#include -#include -#include -#include -//#include -//#include #include -#include -#include +#include +#include +#include namespace sprout { namespace math { - namespace detail { - template - 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 - 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 - SPROUT_CONSTEXPR T - abs_max(sprout::array const& c) { - return sprout::math::abs(*sprout::range::max_element(c, sprout::math::detail::abs_less())); - } - template - SPROUT_CONSTEXPR T - sum(sprout::array const& c) { - return sprout::range::accumulate(c, static_cast(0)); - } - template - SPROUT_CONSTEXPR T - abs_sum(sprout::array const& c) { - return sprout::range::accumulate(c, static_cast(0), sprout::math::detail::abs_plus()); - } - template - SPROUT_CONSTEXPR sprout::array - mul(sprout::array const& l, T const& r) { - return sprout::array{{ - l[0] * r, - l[1] * r, - }}; - } - template - SPROUT_CONSTEXPR sprout::array - mul(sprout::array const& l, sprout::array const& r) { - return sprout::array{{ - l[0] * r[0], - l[1] * r[1], - }}; - } - template - SPROUT_CONSTEXPR sprout::array - mul(sprout::array const& l, T const& r) { - return sprout::array{{ - l[0] * r, - l[1] * r, - l[2] * r, - l[3] * r - }}; - } - template - SPROUT_CONSTEXPR sprout::array - mul(sprout::array const& l, sprout::array const& r) { - return sprout::array{{ - l[0] * r[0], - l[1] * r[1], - l[2] * r[2], - l[3] * r[3] - }}; - } - } // namespace detail #define SPROUT_QUATERNION_ACCESSOR_GENERATOR(type) \ SPROUT_CONSTEXPR type real() const { \ @@ -839,896 +761,9 @@ namespace sprout { #undef SPROUT_QUATERNION_MEMBER_TYPE_DATA_GENERATOR #undef SPROUT_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR #undef SPROUT_QUATERNION_ACCESSOR_GENERATOR - - // - // operator+ - // - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator+(T const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs + rhs.R_component_1(), - rhs.R_component_2(), - rhs.R_component_3(), - rhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator+(sprout::math::quaternion const& lhs, T const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() + rhs, - lhs.R_component_2(), - lhs.R_component_3(), - lhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator+(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs.real() + rhs.R_component_1(), - lhs.imag() + rhs.R_component_2(), - rhs.R_component_3(), - rhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator+(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() + rhs.real(), - lhs.R_component_2() + rhs.imag(), - lhs.R_component_3(), - lhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator+(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() + rhs.R_component_1(), - lhs.R_component_2() + rhs.R_component_2(), - lhs.R_component_3() + rhs.R_component_3(), - lhs.R_component_4() + rhs.R_component_4() - ); - } - // - // operator- - // - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator-(T const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs - rhs.R_component_1(), - rhs.R_component_2(), - rhs.R_component_3(), - rhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator-(sprout::math::quaternion const& lhs, T const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() - rhs, - lhs.R_component_2(), - lhs.R_component_3(), - lhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator-(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs.real() - rhs.R_component_1(), - lhs.imag() - rhs.R_component_2(), - rhs.R_component_3(), - rhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator-(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() - rhs.real(), - lhs.R_component_2() - rhs.imag(), - lhs.R_component_3(), - lhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator-(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() - rhs.R_component_1(), - lhs.R_component_2() - rhs.R_component_2(), - lhs.R_component_3() - rhs.R_component_3(), - lhs.R_component_4() - rhs.R_component_4() - ); - } - // - // operator* - // - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator*(T const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs * rhs.R_component_1(), - lhs * rhs.R_component_2(), - lhs * rhs.R_component_3(), - lhs * rhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator*(sprout::math::quaternion const& lhs, T const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() * rhs, - lhs.R_component_2() * rhs, - lhs.R_component_3() * rhs, - lhs.R_component_4() * rhs - ); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - mul_qc_impl(T const& a, T const& b, T const& c, T const& d, T const& ar, T const& br) { - return sprout::math::quaternion( - +a * ar - b * br, - +a * br + b * ar, - +c * ar + d * br, - -c * br + d * ar - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator*(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::detail::mul_qc_impl( - lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), - rhs.real(), rhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator*(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { - return sprout::math::detail::mul_qc_impl( - rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4(), - lhs.real(), lhs.imag() - ); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - mul_qq_impl(T const& a, T const& b, T const& c, T const& d, T const& ar, T const& br, T const& cr, T const& dr) { - return sprout::math::quaternion( - +a * ar - b * br - c * cr - d * dr, - +a * br + b * ar + c * dr - d * cr, - +a * cr - b * dr + c * ar + d * br, - +a * dr + b * cr - c * br + d * ar - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator*(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::detail::mul_qq_impl( - lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), - rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4() - ); - } - // - // operator/ - // - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator/(T const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::quaternion( - lhs / rhs.R_component_1(), - lhs / rhs.R_component_2(), - lhs / rhs.R_component_3(), - lhs / rhs.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator/(sprout::math::quaternion const& lhs, T const& rhs) { - return sprout::math::quaternion( - lhs.R_component_1() / rhs, - lhs.R_component_2() / rhs, - lhs.R_component_3() / rhs, - lhs.R_component_4() / rhs - ); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - div_qq_impl_4(sprout::array const& tt) { - return sprout::math::quaternion( - tt[0], tt[1], tt[2], tt[3] - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - div_qq_impl_3(sprout::array const& tr, T const& mixam, sprout::array const& tt) { - return sprout::math::detail::div_qq_impl_3( - sprout::math::detail::mul(tt, mixam / sprout::math::detail::sum(tr)) - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - div_qq_impl_2(T const& a, T const& b, T const& c, T const& d, sprout::array const& tr, T const& mixam) { - return sprout::math::detail::div_qq_impl_3( - sprout::math::detail::mul(tr, tr), mixam, - sprout::array{{ - +a * tr[0] + b * tr[1] + c * tr[2] + d * tr[3], - -a * tr[1] + b * tr[0] - c * tr[3] + d * tr[2], - -a * tr[2] + b * tr[3] + c * tr[0] - d * tr[1], - -a * tr[3] - b * tr[2] + c * tr[1] + d * tr[0] - }} - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - div_qq_impl_1(T const& a, T const& b, T const& c, T const& d, sprout::array const& tr, T const& mixam) { - return sprout::math::detail::div_qq_impl_2( - a, b, c, d, sprout::math::detail::mul(tr, mixam), mixam - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - div_qq_impl(T const& a, T const& b, T const& c, T const& d, sprout::array const& tr) { - return sprout::math::detail::div_qq_impl_1( - a, b, c, d, tr, - static_cast(1) / sprout::math::detail::abs_max(tr) - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator/(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::detail::div_qq_impl( - lhs.real(), lhs.imag(), static_cast(0), static_cast(0), - sprout::array{{rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4()}} - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator/(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { - return sprout::math::detail::div_qq_impl( - lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), - sprout::array{{rhs.real(), rhs.imag(), static_cast(0), static_cast(0)}} - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator/(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { - return sprout::math::detail::div_qq_impl( - lhs.R_component_1(), lhs.R_component_2(), lhs.R_component_3(), lhs.R_component_4(), - sprout::array{{rhs.R_component_1(), rhs.R_component_2(), rhs.R_component_3(), rhs.R_component_4()}} - ); - } - - // - // operator+ - // operator- - // - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator+(sprout::math::quaternion const& q) { - return q; - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - operator-(sprout::math::quaternion const& q) { - return sprout::math::quaternion(-q.R_component_1(), -q.R_component_2(), -q.R_component_3(), -q.R_component_4()); - } - - // - // operator== - // operator!= - // - template - inline SPROUT_CONSTEXPR bool - operator==(T const& lhs, sprout::math::quaternion const& rhs) { - return rhs.R_component_1() == lhs - && rhs.R_component_2() == static_cast(0) - && rhs.R_component_3() == static_cast(0) - && rhs.R_component_4() == static_cast(0) - ; - } - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::math::quaternion const& lhs, T const& rhs) { - return lhs.R_component_1() == rhs - && lhs.R_component_2() == static_cast(0) - && lhs.R_component_3() == static_cast(0) - && lhs.R_component_4() == static_cast(0) - ; - } - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::complex const& lhs, sprout::math::quaternion const& rhs) { - return rhs.R_component_1() == lhs.real() - && rhs.R_component_2() == lhs.imag() - && rhs.R_component_3() == static_cast(0) - && rhs.R_component_4() == static_cast(0) - ; - } - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::math::quaternion const& lhs, sprout::complex const& rhs) { - return lhs.R_component_1() == rhs.real() - && lhs.R_component_2() == rhs.imag() - && lhs.R_component_3() == static_cast(0) - && lhs.R_component_4() == static_cast(0) - ; - } - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) { - return rhs.R_component_1() == lhs.R_component_1() - && rhs.R_component_2() == lhs.R_component_2() - && rhs.R_component_3() == lhs.R_component_3() - && rhs.R_component_4() == lhs.R_component_4() - ; - } - -#define SPROUT_QUATERNION_NOT_EQUAL_GENERATOR \ - { \ - return !(lhs == rhs); \ - } - - template - inline SPROUT_CONSTEXPR bool - operator!=(T const& lhs, sprout::math::quaternion const& rhs) - SPROUT_QUATERNION_NOT_EQUAL_GENERATOR - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::math::quaternion const& lhs, T const& rhs) - SPROUT_QUATERNION_NOT_EQUAL_GENERATOR - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::complex const& lhs, sprout::math::quaternion const& rhs) - SPROUT_QUATERNION_NOT_EQUAL_GENERATOR - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::math::quaternion const& lhs, sprout::complex const& rhs) - SPROUT_QUATERNION_NOT_EQUAL_GENERATOR - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::math::quaternion const& lhs, sprout::math::quaternion const& rhs) - SPROUT_QUATERNION_NOT_EQUAL_GENERATOR - -#undef SPROUT_QUATERNION_NOT_EQUAL_GENERATOR - - // - // operator<< - // operator>> - // - template - inline SPROUT_NON_CONSTEXPR std::basic_ostream& - operator<<( std::basic_ostream& lhs, sprout::math::quaternion const& rhs) { - std::basic_ostringstream s; - s.flags(lhs.flags()); - s.imbue(lhs.getloc()); - s.precision(lhs.precision()); - s - << '(' - << rhs.R_component_1() << ',' - << rhs.R_component_2() << ',' - << rhs.R_component_3() << ',' - << rhs.R_component_4() - << ')' - ; - return lhs << s.str(); - } - template - inline SPROUT_NON_CONSTEXPR std::basic_istream& - operator>>(std::basic_istream& lhs, sprout::math::quaternion& rhs) { - std::ctype const& ct = std::use_facet >(lhs.getloc()); - T a = T(); - T b = T(); - T c = T(); - T d = T(); - sprout::complex u = sprout::complex(); - sprout::complex v = sprout::complex(); - Elem ch = Elem(); - char cc; - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == '(') { - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == '(') { - lhs.putback(ch); - lhs >> u; - a = u.real(); - b = u.imag(); - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a, b); - } else if (cc == ',') { - lhs >> v; - c = v.real(); - d = v.imag(); - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a, b, c, d); - } else { - lhs.setstate(std::ios_base::failbit); - } - } else { - lhs.setstate(std::ios_base::failbit); - } - } else { - lhs.putback(ch); - lhs >> a; - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a); - } else if (cc == ',') { - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == '(') { - lhs.putback(ch); - lhs >> v; - c = v.real(); - d = v.imag(); - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a, b, c, d); - } else { - lhs.setstate(std::ios_base::failbit); - } - } else { - lhs.putback(ch); - lhs >> b; - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a, b); - } else if (cc == ',') { - lhs >> c; - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a, b, c); - } else if (cc == ',') { - lhs >> d; - if (!lhs.good()) { - goto finish; - } - lhs >> ch; - if (!lhs.good()) { - goto finish; - } - cc = ct.narrow(ch, char()); - if (cc == ')') { - rhs = sprout::math::quaternion(a, b, c, d); - } else { - lhs.setstate(std::ios_base::failbit); - } - } else { - lhs.setstate(std::ios_base::failbit); - } - } else { - lhs.setstate(std::ios_base::failbit); - } - } - } else { - lhs.setstate(std::ios_base::failbit); - } - } - } else { - lhs.putback(ch); - lhs >> a; - if (!lhs.good()) { - goto finish; - } - rhs = sprout::math::quaternion(a); - } - finish: - return lhs; - } - - // - // real - // unreal - // - template - inline SPROUT_CONSTEXPR T - real(sprout::math::quaternion const& q) { - return q.real(); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - unreal(sprout::math::quaternion const& q) { - return q.unreal(); - } - - // - // sup - // l1 - // - template - inline SPROUT_CONSTEXPR T - sup(sprout::math::quaternion const& q) { - return sprout::math::detail::abs_max( - sprout::array{{ - q.R_component_1(), - q.R_component_2(), - q.R_component_3(), - q.R_component_4() - }} - ); - } - template - inline SPROUT_CONSTEXPR T - l1(sprout::math::quaternion const& q) { - return sprout::math::detail::abs_sum( - sprout::array{{ - q.R_component_1(), - q.R_component_2(), - q.R_component_3(), - q.R_component_4() - }} - ); - } - - // - // abs - // - namespace detail { - template - inline SPROUT_CONSTEXPR T - abs_q_impl_3(sprout::array const& temp, T const& maxim) { - return maxim * sprout::math::sqrt(sprout::math::detail::sum(sprout::math::detail::mul(temp, temp))); - } - template - inline SPROUT_CONSTEXPR T - abs_q_impl_2(sprout::array const& temp, T const& maxim) { - return sprout::math::detail::abs_q_impl_3( - sprout::math::detail::mul(temp, maxim), maxim - ); - } - template - inline SPROUT_CONSTEXPR T - abs_q_impl_1(sprout::array const& temp, T const& maxim) { - return maxim == static_cast(0) ? sprout::math::quaternion(maxim) - : sprout::math::detail::abs_q_impl_2( - temp, static_cast(1) / maxim - ) - ; - } - template - inline SPROUT_CONSTEXPR T - abs_q_impl(sprout::array const& temp) { - return sprout::math::detail::abs_q_impl_1( - temp, sprout::math::detail::abs_max(temp) - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR T - abs(sprout::math::quaternion const& q) { - return sprout::math::detail::abs_q_impl( - sprout::array{{ - q.R_component_1(), - q.R_component_2(), - q.R_component_3(), - q.R_component_4() - }} - ); - } - -#undef SPROUT_QUATERNION_ARRAY_LOADER - - // - // conj - // norm - // - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - conj(sprout::math::quaternion const& q) { - return sprout::math::quaternion( - +q.R_component_1(), - -q.R_component_2(), - -q.R_component_3(), - -q.R_component_4() - ); - } - template - inline SPROUT_CONSTEXPR T - norm(sprout::math::quaternion const& q) { - return sprout::math::real(q * sprout::math::conj(q)); - } - - // - // spherical - // semipolar - // multipolar - // cylindrospherical - // cylindrical - // - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - spherical_impl(T const& rho, T const& theta, T const& phi1, T const& phi2, T const& p1, T const& p2) { - return rho * sprout::math::quaternion( - sprout::math::cos(theta) * (p2 * p1), - sprout::math::sin(theta) * (p2 * p1), - sprout::math::sin(phi1) * p2, - sprout::math::sin(phi2) - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - spherical(T const& rho, T const& theta, T const& phi1, T const& phi2) { - return sprout::math::detail::spherical_impl( - rho, theta, phi1, phi2, - sprout::math::cos(phi1), sprout::math::cos(phi2) - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - semipolar(T const& rho, T const& alpha, T const& theta1, T const& theta2) { - return rho * sprout::math::quaternion( - sprout::math::cos(alpha) * sprout::math::cos(theta1), - sprout::math::cos(alpha) * sprout::math::sin(theta1), - sprout::math::sin(alpha) * sprout::math::cos(theta2), - sprout::math::sin(alpha) * sprout::math::sin(theta2) - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - multipolar(T const& rho1, T const& theta1, T const& rho2, T const& theta2) { - return sprout::math::quaternion( - rho1 * sprout::math::cos(theta1), - rho1 * sprout::math::sin(theta1), - rho2 * sprout::math::cos(theta2), - rho2 * sprout::math::sin(theta2) - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - cylindrospherical(T const& t, T const& radius, T const& longitude, T const& latitude) { - return sprout::math::quaternion( - t, - radius * sprout::math::cos(longitude) * sprout::math::cos(latitude), - radius * sprout::math::sin(longitude) * sprout::math::cos(latitude), - radius * sprout::math::sin(latitude) - ); - } - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - cylindrical(T const& r, T const& angle, T const& h1, T const& h2) { - return sprout::math::quaternion( - r * sprout::math::cos(angle), - r * sprout::math::sin(angle), - h1, - h2 - ); - } - - // - // exp - // - // !!! -// namespace detail { -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// exp_impl_1(sprout::math::quaternion const& q, T const& z, T const& w) { -// return sprout::math::exp(sprout::math::real(q)) * sprout::math::quaternion( -// sprout::math::cos(z), -// w * q.R_component_2(), -// w * q.R_component_3(), -// w * q.R_component_4() -// ); -// } -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// exp_impl(sprout::math::quaternion const& q, T const& z) { -// return sprout::math::detail::exp_impl_1( -// q, z, -// sprout::math::sinc_pi(z) -// ); -// } -// } // namespace detail -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// exp(sprout::math::quaternion const& q) { -// return sprout::math::detail::exp_impl( -// q, -// sprout::math::abs(sprout::math::unreal(q)) -// ); -// } - - // - // cos - // sin - // tan - // - // !!! -// namespace detail { -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// cos_impl_1(sprout::math::quaternion const& q, T const& z, T const& w) { -// return sprout::math::quaternion( -// sprout::math::cos(q.real()) * sprout::math::cosh(z), -// w * q.R_component_2(), -// w * q.R_component_3(), -// w * q.R_component_4() -// ); -// } -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// cos_impl(sprout::math::quaternion const& q, T const& z) { -// return sprout::math::detail::cos_impl_1( -// q, z, -// -sprout::math::sin(q.real()) * sprout::math::sinhc_pi(z) -// ); -// } -// } // namespace detail -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// cos(sprout::math::quaternion const& q) { -// return sprout::math::detail::cos_impl( -// q, -// sprout::math::abs(sprout::math::unreal(q)) -// ); -// } -// namespace detail { -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// sin_impl_1(sprout::math::quaternion const& q, T const& z, T const& w) { -// return sprout::math::quaternion( -// sprout::math::sin(q.real()) * sprout::math::cosh(z), -// w * q.R_component_2(), -// w * q.R_component_3(), -// w * q.R_component_4() -// ); -// } -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// sin_impl(sprout::math::quaternion const& q, T const& z) { -// return sprout::math::detail::sin_impl_1( -// q, z, -// +sprout::math::cos(q.real()) * sprout::math::sinhc_pi(z) -// ); -// } -// } // namespace detail -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// sin(sprout::math::quaternion const& q) { -// return sprout::math::detail::sin_impl( -// q, -// sprout::math::abs(sprout::math::unreal(q)) -// ); -// } -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// tan(sprout::math::quaternion const& q) { -// return sprout::math::sin(q) / sprout::math::cos(q); -// } - - // - // cosh - // sinh - // tanh - // - // !!! -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// cosh(sprout::math::quaternion const& q) { -// return (sprout::math::exp(+q) + sprout::math::exp(-q)) / static_cast(2); -// } -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// sinh(sprout::math::quaternion const& q) { -// return (sprout::math::exp(+q) - sprout::math::exp(-q)) / static_cast(2); -// } -// template -// inline SPROUT_CONSTEXPR sprout::math::quaternion -// tanh(sprout::math::quaternion const& q) { -// return sprout::math::sinh(q) / sprout::math::cosh(q); -// } - - // - // pow - // - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - pow_q_impl(sprout::math::quaternion const& q, int n, int m, sprout::math::quaternion const& result) { - return n != m << 1 ? result * result * q - : result * result - ; - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::math::quaternion - pow(sprout::math::quaternion const& q, int n) { - return n > 1 ? sprout::math::detail::pow_q_impl( - q, n, n >> 1, sprout::math::pow(q, n >> 1) - ) - : n == 1 ? q - : n == 0 ? sprout::math::quaternion(static_cast(1)) - : sprout::math::pow(sprout::math::quaternion(static_cast(1)) / q, -n) - ; - } } // namespace math using sprout::math::quaternion; - using sprout::math::real; - using sprout::math::unreal; - using sprout::math::sup; - using sprout::math::l1; - using sprout::math::abs; - using sprout::math::conj; - using sprout::math::norm; - using sprout::math::spherical; - using sprout::math::semipolar; - using sprout::math::multipolar; - using sprout::math::cylindrospherical; - using sprout::math::cylindrical; -// using sprout::math::exp; -// using sprout::math::cos; -// using sprout::math::sin; -// using sprout::math::tan; -// using sprout::math::cosh; -// using sprout::math::sinh; -// using sprout::math::tanh; - using sprout::math::pow; } // namespace sprout #endif // #ifndef SPROUT_MATH_QUATERNION_QUATERNION_HPP diff --git a/sprout/math/quaternion/real.hpp b/sprout/math/quaternion/real.hpp new file mode 100644 index 00000000..300c8319 --- /dev/null +++ b/sprout/math/quaternion/real.hpp @@ -0,0 +1,29 @@ +/*============================================================================= + 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_REAL_HPP +#define SPROUT_MATH_QUATERNION_REAL_HPP + +#include +#include + +namespace sprout { + namespace math { + // + // real + // + template + inline SPROUT_CONSTEXPR T + real(sprout::math::quaternion const& q) { + return q.real(); + } + } // namespace math + + using sprout::math::real; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_REAL_HPP diff --git a/sprout/math/quaternion/semipolar.hpp b/sprout/math/quaternion/semipolar.hpp new file mode 100644 index 00000000..0b9cb67f --- /dev/null +++ b/sprout/math/quaternion/semipolar.hpp @@ -0,0 +1,36 @@ +/*============================================================================= + 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_SEMIPOLAR_HPP +#define SPROUT_MATH_QUATERNION_SEMIPOLAR_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // semipolar + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + semipolar(T const& rho, T const& alpha, T const& theta1, T const& theta2) { + return rho * sprout::math::quaternion( + sprout::math::cos(alpha) * sprout::math::cos(theta1), + sprout::math::cos(alpha) * sprout::math::sin(theta1), + sprout::math::sin(alpha) * sprout::math::cos(theta2), + sprout::math::sin(alpha) * sprout::math::sin(theta2) + ); + } + } // namespace math + + using sprout::math::semipolar; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_SEMIPOLAR_HPP diff --git a/sprout/math/quaternion/sin.hpp b/sprout/math/quaternion/sin.hpp new file mode 100644 index 00000000..9d0bec71 --- /dev/null +++ b/sprout/math/quaternion/sin.hpp @@ -0,0 +1,60 @@ +/*============================================================================= + 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_SIN_HPP +#define SPROUT_MATH_QUATERNION_SIN_HPP + +#include +#include +#include +#include +//#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // sin + // + // !!! +// namespace detail { +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// sin_impl_1(sprout::math::quaternion const& q, T const& z, T const& w) { +// return sprout::math::quaternion( +// sprout::math::sin(sprout::math::real(q)) * sprout::math::cosh(z), +// w * q.R_component_2(), +// w * q.R_component_3(), +// w * q.R_component_4() +// ); +// } +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// sin_impl(sprout::math::quaternion const& q, T const& z) { +// return sprout::math::detail::sin_impl_1( +// q, z, +// +sprout::math::cos(sprout::math::real(q)) * sprout::math::sinhc_pi(z) +// ); +// } +// } // namespace detail +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// sin(sprout::math::quaternion const& q) { +// return sprout::math::detail::sin_impl( +// q, +// sprout::math::abs(sprout::math::unreal(q)) +// ); +// } + } // namespace math + +// using sprout::math::sin; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_SIN_HPP diff --git a/sprout/math/quaternion/sinh.hpp b/sprout/math/quaternion/sinh.hpp new file mode 100644 index 00000000..8927d643 --- /dev/null +++ b/sprout/math/quaternion/sinh.hpp @@ -0,0 +1,31 @@ +/*============================================================================= + 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_SINH_HPP +#define SPROUT_MATH_QUATERNION_SINH_HPP + +#include +#include +#include + +namespace sprout { + namespace math { + // + // sinh + // + // !!! +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// sinh(sprout::math::quaternion const& q) { +// return (sprout::math::exp(+q) - sprout::math::exp(-q)) / static_cast(2); +// } + } // namespace math + +// using sprout::math::sinh; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_SINH_HPP diff --git a/sprout/math/quaternion/spherical.hpp b/sprout/math/quaternion/spherical.hpp new file mode 100644 index 00000000..a3aefd23 --- /dev/null +++ b/sprout/math/quaternion/spherical.hpp @@ -0,0 +1,46 @@ +/*============================================================================= + 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_SPHERICAL_HPP +#define SPROUT_MATH_QUATERNION_SPHERICAL_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // spherical + // + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + spherical_impl(T const& rho, T const& theta, T const& phi1, T const& phi2, T const& p1, T const& p2) { + return rho * sprout::math::quaternion( + sprout::math::cos(theta) * (p2 * p1), + sprout::math::sin(theta) * (p2 * p1), + sprout::math::sin(phi1) * p2, + sprout::math::sin(phi2) + ); + } + } // namespace detail + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + spherical(T const& rho, T const& theta, T const& phi1, T const& phi2) { + return sprout::math::detail::spherical_impl( + rho, theta, phi1, phi2, + sprout::math::cos(phi1), sprout::math::cos(phi2) + ); + } + } // namespace math + + using sprout::math::spherical; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_SPHERICAL_HPP diff --git a/sprout/math/quaternion/sup.hpp b/sprout/math/quaternion/sup.hpp new file mode 100644 index 00000000..d3754239 --- /dev/null +++ b/sprout/math/quaternion/sup.hpp @@ -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_SUP_HPP +#define SPROUT_MATH_QUATERNION_SUP_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // sup + // + template + inline SPROUT_CONSTEXPR T + sup(sprout::math::quaternion const& q) { + return sprout::math::detail::abs_max( + sprout::array{{ + q.R_component_1(), + q.R_component_2(), + q.R_component_3(), + q.R_component_4() + }} + ); + } + } // namespace math + + using sprout::math::sup; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_SUP_HPP diff --git a/sprout/math/quaternion/tan.hpp b/sprout/math/quaternion/tan.hpp new file mode 100644 index 00000000..81dcabdf --- /dev/null +++ b/sprout/math/quaternion/tan.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + 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_TAN_HPP +#define SPROUT_MATH_QUATERNION_TAN_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // tan + // + // !!! +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// tan(sprout::math::quaternion const& q) { +// return sprout::math::sin(q) / sprout::math::cos(q); +// } + } // namespace math + +// using sprout::math::tan; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_TAN_HPP diff --git a/sprout/math/quaternion/tanh.hpp b/sprout/math/quaternion/tanh.hpp new file mode 100644 index 00000000..df6f640a --- /dev/null +++ b/sprout/math/quaternion/tanh.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + 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_TANH_HPP +#define SPROUT_MATH_QUATERNION_TANH_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace math { + // + // tanh + // + // !!! +// template +// inline SPROUT_CONSTEXPR sprout::math::quaternion +// tanh(sprout::math::quaternion const& q) { +// return sprout::math::sinh(q) / sprout::math::cosh(q); +// } + } // namespace math + +// using sprout::math::tanh; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_TANH_HPP diff --git a/sprout/math/quaternion/transcendentals.hpp b/sprout/math/quaternion/transcendentals.hpp new file mode 100644 index 00000000..f6a7ac89 --- /dev/null +++ b/sprout/math/quaternion/transcendentals.hpp @@ -0,0 +1,21 @@ +/*============================================================================= + 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_TRANSCENDENTALS_HPP +#define SPROUT_MATH_QUATERNION_TRANSCENDENTALS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_MATH_QUATERNION_TRANSCENDENTALS_HPP diff --git a/sprout/math/quaternion/tuple.hpp b/sprout/math/quaternion/tuple.hpp new file mode 100644 index 00000000..70715ed4 --- /dev/null +++ b/sprout/math/quaternion/tuple.hpp @@ -0,0 +1,139 @@ +/*============================================================================= + 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_TUPLE_HPP +#define SPROUT_MATH_QUATERNION_TUPLE_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + namespace detail { + template + struct tuple_element_impl; + template + struct tuple_element_impl > + : public sprout::detail::nil_base + {}; + template + struct tuple_element_impl<0, sprout::math::quaternion > + : public sprout::identity + {}; + template + struct tuple_element_impl<1, sprout::math::quaternion > + : public sprout::identity + {}; + template + struct tuple_element_impl<2, sprout::math::quaternion > + : public sprout::identity + {}; + template + struct tuple_element_impl<3, sprout::math::quaternion > + : public sprout::identity + {}; + + template + struct get_impl; + template + struct get_impl<0, sprout::math::quaternion > { + public: + SPROUT_CONSTEXPR T& operator()(sprout::math::quaternion& t) const { + return t[0]; + } + SPROUT_CONSTEXPR T const& operator()(sprout::math::quaternion const& t) const { + return t[0]; + } + }; + template + struct get_impl<1, sprout::math::quaternion > { + public: + SPROUT_CONSTEXPR T& operator()(sprout::math::quaternion& t) const { + return t[1]; + } + SPROUT_CONSTEXPR T const& operator()(sprout::math::quaternion const& t) const { + return t[1]; + } + }; + template + struct get_impl<2, sprout::math::quaternion > { + public: + SPROUT_CONSTEXPR T& operator()(sprout::math::quaternion& t) const { + return t[2]; + } + SPROUT_CONSTEXPR T const& operator()(sprout::math::quaternion const& t) const { + return t[2]; + } + }; + template + struct get_impl<3, sprout::math::quaternion > { + public: + SPROUT_CONSTEXPR T& operator()(sprout::math::quaternion& t) const { + return t[3]; + } + SPROUT_CONSTEXPR T const& operator()(sprout::math::quaternion const& t) const { + return t[3]; + } + }; + } // namespace detail + } // namespace tuples +} // namespace sprout + +namespace std { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmismatched-tags" +#endif + // + // tuple_size + // + template + struct tuple_size > + : public sprout::integral_constant + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public sprout::tuples::detail::tuple_element_impl > + {}; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +} // namespace std + +namespace sprout { + // + // tuple_get + // + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + tuple_get(sprout::math::quaternion& t) SPROUT_NOEXCEPT { + static_assert(I < 4, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + tuple_get(sprout::math::quaternion const& t) SPROUT_NOEXCEPT { + static_assert(I < 4, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + tuple_get(sprout::math::quaternion&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_TUPLE_HPP diff --git a/sprout/math/quaternion/type_traits.hpp b/sprout/math/quaternion/type_traits.hpp new file mode 100644 index 00000000..fdfc2be3 --- /dev/null +++ b/sprout/math/quaternion/type_traits.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + 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_TYPE_TRAITS_HPP +#define SPROUT_MATH_QUATERNION_TYPE_TRAITS_HPP + +#include +#include +#include + +namespace sprout { + namespace math { + // + // is_quaternion + // + template + struct is_quaternion + : public sprout::false_type + {}; + template + struct is_quaternion + : public sprout::math::is_quaternion + {}; + template + struct is_quaternion + : public sprout::math::is_quaternion + {}; + template + struct is_quaternion > + : public sprout::true_type + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_quaternion_v = sprout::math::is_quaternion::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace math + + using sprout::math::is_quaternion; +#if SPROUT_USE_VARIABLE_TEMPLATES + using sprout::math::is_quaternion_v; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_TYPE_TRAITS_HPP diff --git a/sprout/math/quaternion/udl.hpp b/sprout/math/quaternion/udl.hpp new file mode 100644 index 00000000..bbe625d8 --- /dev/null +++ b/sprout/math/quaternion/udl.hpp @@ -0,0 +1,123 @@ +/*============================================================================= + 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_UDL_HPP +#define SPROUT_MATH_QUATERNION_UDL_HPP + +#include +#include +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +namespace sprout { + namespace udl { + namespace quaternion { + using sprout::udl::complex::operator"" _i; + using sprout::udl::complex::operator"" _if; + using sprout::udl::complex::operator"" _iF; + using sprout::udl::complex::operator"" _il; + using sprout::udl::complex::operator"" _iL; + + // + // _j + // + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _j(long double x) { + return sprout::math::quaternion(0, 0, x); + } + + // + // _jf + // _jF + // + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _jf(long double x) { + return sprout::math::quaternion(0, 0, static_cast(x)); + } + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _jF(long double x) { + return sprout::math::quaternion(0, 0, static_cast(x)); + } + + // + // _jl + // _jL + // + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _jl(long double x) { + return sprout::math::quaternion(0, 0, x); + } + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _jL(long double x) { + return sprout::math::quaternion(0, 0, x); + } + + // + // _k + // + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _k(long double x) { + return sprout::math::quaternion(0, 0, 0, x); + } + + // + // _kf + // _kF + // + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _kf(long double x) { + return sprout::math::quaternion(0, 0, 0, static_cast(x)); + } + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _kF(long double x) { + return sprout::math::quaternion(0, 0, 0, static_cast(x)); + } + + // + // _kl + // _kL + // + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _kl(long double x) { + return sprout::math::quaternion(0, 0, 0, x); + } + inline SPROUT_CONSTEXPR sprout::math::quaternion + operator"" _kL(long double x) { + return sprout::math::quaternion(0, 0, 0, x); + } + } // namespace quaternion + + using sprout::udl::quaternion::operator"" _j; + using sprout::udl::quaternion::operator"" _jf; + using sprout::udl::quaternion::operator"" _jF; + using sprout::udl::quaternion::operator"" _jl; + using sprout::udl::quaternion::operator"" _jL; + + using sprout::udl::quaternion::operator"" _k; + using sprout::udl::quaternion::operator"" _kf; + using sprout::udl::quaternion::operator"" _kF; + using sprout::udl::quaternion::operator"" _kl; + using sprout::udl::quaternion::operator"" _kL; + } // namespace udl + + using sprout::udl::quaternion::operator"" _j; + using sprout::udl::quaternion::operator"" _jf; + using sprout::udl::quaternion::operator"" _jF; + using sprout::udl::quaternion::operator"" _jl; + using sprout::udl::quaternion::operator"" _jL; + + using sprout::udl::quaternion::operator"" _k; + using sprout::udl::quaternion::operator"" _kf; + using sprout::udl::quaternion::operator"" _kF; + using sprout::udl::quaternion::operator"" _kl; + using sprout::udl::quaternion::operator"" _kL; +} // namespace sprout + +#endif // #if SPROUT_USE_USER_DEFINED_LITERALS + +#endif // #ifndef SPROUT_MATH_QUATERNION_UDL_HPP diff --git a/sprout/math/quaternion/unreal.hpp b/sprout/math/quaternion/unreal.hpp new file mode 100644 index 00000000..5eef9973 --- /dev/null +++ b/sprout/math/quaternion/unreal.hpp @@ -0,0 +1,29 @@ +/*============================================================================= + 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_UNREAL_HPP +#define SPROUT_MATH_QUATERNION_UNREAL_HPP + +#include +#include + +namespace sprout { + namespace math { + // + // unreal + // + template + inline SPROUT_CONSTEXPR sprout::math::quaternion + unreal(sprout::math::quaternion const& q) { + return q.unreal(); + } + } // namespace math + + using sprout::math::unreal; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_QUATERNION_UNREAL_HPP diff --git a/sprout/math/quaternion/values.hpp b/sprout/math/quaternion/values.hpp new file mode 100644 index 00000000..d67bba20 --- /dev/null +++ b/sprout/math/quaternion/values.hpp @@ -0,0 +1,20 @@ +/*============================================================================= + 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_VALUES_HPP +#define SPROUT_MATH_QUATERNION_VALUES_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_MATH_QUATERNION_VALUES_HPP