| 1 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 2 | |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #ifndef BOOST_QVM_EF9152E42E4711DFB699737156D89593 |
| 7 | #define BOOST_QVM_EF9152E42E4711DFB699737156D89593 |
| 8 | |
| 9 | #if defined(BOOST_QVM_TEST_SINGLE_HEADER) && !defined(BOOST_QVM_TEST_SINGLE_HEADER) |
| 10 | # define BOOST_QVM_TEST_REF_WRITE_ELEMENT |
| 11 | #endif |
| 12 | |
| 13 | #include <boost/qvm/quat_traits_defaults.hpp> |
| 14 | #include <boost/qvm/deduce_quat.hpp> |
| 15 | #include <boost/qvm/assert.hpp> |
| 16 | #include "test_qvm.hpp" |
| 17 | |
| 18 | namespace |
| 19 | test_qvm |
| 20 | { |
| 21 | template <class Tag,class T=float> |
| 22 | struct |
| 23 | quaternion |
| 24 | { |
| 25 | T a[4]; |
| 26 | mutable T b[4]; |
| 27 | |
| 28 | explicit |
| 29 | quaternion( T start=T(0), T step=T(0) ) |
| 30 | { |
| 31 | for( int i=0; i!=4; ++i,start+=step ) |
| 32 | a[i]=b[i]=start; |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | template <class Tag1,class T1,class Tag2,class T2> |
| 37 | void |
| 38 | dump_ab( quaternion<Tag1,T1> const & a, quaternion<Tag2,T2> const & b ) |
| 39 | { |
| 40 | detail::dump_ab(a.a,b.a); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | namespace boost { namespace qvm { |
| 45 | |
| 46 | #ifdef BOOST_QVM_TEST_REF_WRITE_ELEMENT |
| 47 | |
| 48 | template <class Tag,class T> |
| 49 | struct |
| 50 | quat_traits< test_qvm::quaternion<Tag,T> >: |
| 51 | quat_traits_defaults<test_qvm::quaternion<Tag,T>,T> |
| 52 | { |
| 53 | typedef quat_traits_defaults<test_qvm::quaternion<Tag,T>,T> base; |
| 54 | |
| 55 | template <int I> |
| 56 | static |
| 57 | typename base::scalar_type & |
| 58 | write_element( typename base::quat_type & m ) |
| 59 | { |
| 60 | BOOST_QVM_STATIC_ASSERT(I>=0); |
| 61 | BOOST_QVM_STATIC_ASSERT(I<4); |
| 62 | return m.a[I]; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | #else |
| 67 | |
| 68 | template <class Tag,class T> |
| 69 | struct |
| 70 | quat_traits< test_qvm::quaternion<Tag,T> > |
| 71 | { |
| 72 | typedef test_qvm::quaternion<Tag,T> this_quaternion; |
| 73 | typedef T scalar_type; |
| 74 | |
| 75 | template <int I> |
| 76 | static |
| 77 | T |
| 78 | read_element( this_quaternion const & v ) |
| 79 | { |
| 80 | BOOST_QVM_STATIC_ASSERT(I>=0); |
| 81 | BOOST_QVM_STATIC_ASSERT(I<4); |
| 82 | return v.a[I]; |
| 83 | } |
| 84 | |
| 85 | template <int I> |
| 86 | static |
| 87 | void |
| 88 | write_element( this_quaternion & v, T s ) |
| 89 | { |
| 90 | BOOST_QVM_STATIC_ASSERT(I>=0); |
| 91 | BOOST_QVM_STATIC_ASSERT(I<4); |
| 92 | v.a[I] = s; |
| 93 | } |
| 94 | |
| 95 | static |
| 96 | T |
| 97 | read_element_idx( int i, this_quaternion const & v ) |
| 98 | { |
| 99 | BOOST_QVM_ASSERT(i>=0); |
| 100 | BOOST_QVM_ASSERT(i<4); |
| 101 | return v.a[i]; |
| 102 | } |
| 103 | |
| 104 | static |
| 105 | void |
| 106 | write_element_idx( int i, this_quaternion & v, T s ) |
| 107 | { |
| 108 | BOOST_QVM_ASSERT(i>=0); |
| 109 | BOOST_QVM_ASSERT(i<4); |
| 110 | v.a[i] = s; |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | #endif |
| 115 | |
| 116 | template <class Tag,class T> |
| 117 | struct |
| 118 | deduce_quat2<test_qvm::quaternion<Tag,T>,test_qvm::quaternion<Tag,T> > |
| 119 | { |
| 120 | typedef test_qvm::quaternion<Tag,T> type; |
| 121 | }; |
| 122 | |
| 123 | } } |
| 124 | |
| 125 | namespace |
| 126 | { |
| 127 | struct Q1; |
| 128 | struct Q2; |
| 129 | struct Q3; |
| 130 | } |
| 131 | |
| 132 | #endif |
| 133 | |