| 1 | #ifndef BOOST_QVM_QUAT_HPP_INCLUDED |
|---|---|
| 2 | #define BOOST_QVM_QUAT_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 5 | |
| 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | #include <boost/qvm/detail/quat_assign.hpp> |
| 10 | #include <boost/qvm/assert.hpp> |
| 11 | #include <boost/qvm/static_assert.hpp> |
| 12 | |
| 13 | namespace boost { namespace qvm { |
| 14 | |
| 15 | template <class T> |
| 16 | struct |
| 17 | quat |
| 18 | { |
| 19 | T a[4]; |
| 20 | template <class R |
| 21 | #if __cplusplus >= 201103L |
| 22 | , class = typename enable_if<is_quat<R> >::type |
| 23 | #endif |
| 24 | > |
| 25 | operator R() const |
| 26 | { |
| 27 | R r; |
| 28 | assign(r,*this); |
| 29 | return r; |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | template <class Q> |
| 34 | struct quat_traits; |
| 35 | |
| 36 | template <class T> |
| 37 | struct |
| 38 | quat_traits< quat<T> > |
| 39 | { |
| 40 | typedef quat<T> this_quaternion; |
| 41 | typedef T scalar_type; |
| 42 | |
| 43 | template <int I> |
| 44 | static |
| 45 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 46 | scalar_type |
| 47 | read_element( this_quaternion const & x ) |
| 48 | { |
| 49 | BOOST_QVM_STATIC_ASSERT(I>=0); |
| 50 | BOOST_QVM_STATIC_ASSERT(I<4); |
| 51 | return x.a[I]; |
| 52 | } |
| 53 | |
| 54 | template <int I> |
| 55 | static |
| 56 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 57 | scalar_type & |
| 58 | write_element( this_quaternion & x ) |
| 59 | { |
| 60 | BOOST_QVM_STATIC_ASSERT(I>=0); |
| 61 | BOOST_QVM_STATIC_ASSERT(I<4); |
| 62 | return x.a[I]; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | } } |
| 67 | |
| 68 | #endif |
| 69 |
