#ifndef BOOST_QVM_QUAT_ACCESS_HPP_INCLUDED #define BOOST_QVM_QUAT_ACCESS_HPP_INCLUDED // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. // 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) #include #include #include #include #include namespace boost { namespace qvm { template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value,typename quat_traits::scalar_type>::type S( Q const & a ) { return quat_traits::template read_element<0>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value,typename quat_traits::scalar_type>::type X( Q const & a ) { return quat_traits::template read_element<1>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value,typename quat_traits::scalar_type>::type Y( Q const & a ) { return quat_traits::template read_element<2>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value,typename quat_traits::scalar_type>::type Z( Q const & a ) { return quat_traits::template read_element<3>(a); } namespace qvm_detail { template struct q_element_access { BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL void operator=( typename quat_traits::scalar_type s ) { quat_traits::template write_element(*reinterpret_cast(this), s); } BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL operator typename vec_traits::scalar_type() const { return quat_traits::template read_element(*reinterpret_cast(this)); } }; template struct quat_v_ { template = 201103L , class = typename enable_if >::type #endif > operator R() const { R r; assign(r,*this); return r; } private: quat_v_( quat_v_ const & ); quat_v_ const & operator=( quat_v_ const & ); ~quat_v_(); }; template ::value> struct quat_v_write_traits; template struct quat_v_write_traits { typedef qvm_detail::quat_v_ this_vector; typedef typename quat_traits::scalar_type scalar_type; static int const dim=3; template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL static scalar_type & write_element( this_vector & q ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template write_element( reinterpret_cast(q) ); } }; template struct quat_v_write_traits { typedef qvm_detail::quat_v_ this_vector; typedef typename quat_traits::scalar_type scalar_type; static int const dim=3; template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL static void write_element( this_vector & q, scalar_type s ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template write_element( reinterpret_cast(q), s ); } }; } template struct vec_traits; template struct vec_traits< qvm_detail::quat_v_ >: qvm_detail::quat_v_write_traits { typedef qvm_detail::quat_v_ this_vector; typedef typename quat_traits::scalar_type scalar_type; static int const dim=3; template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL static scalar_type read_element( this_vector const & q ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template read_element( reinterpret_cast(q) ); } }; template struct deduce_vec,D> { typedef vec::scalar_type,D> type; }; template struct deduce_vec2,qvm_detail::quat_v_,D> { typedef vec::scalar_type,D> type; }; template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c< is_quat::value, qvm_detail::quat_v_ const &>::type V( Q const & a ) { return reinterpret_cast const &>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c< is_quat::value, qvm_detail::quat_v_ &>::type V( Q & a ) { return reinterpret_cast &>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && quat_write_element_ref::value,typename quat_traits::scalar_type &>::type S( Q & a ) { return quat_traits::template write_element<0>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && quat_write_element_ref::value,typename quat_traits::scalar_type &>::type X( Q & a ) { return quat_traits::template write_element<1>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && quat_write_element_ref::value,typename quat_traits::scalar_type &>::type Y( Q & a ) { return quat_traits::template write_element<2>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && quat_write_element_ref::value,typename quat_traits::scalar_type &>::type Z( Q & a ) { return quat_traits::template write_element<3>(a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && !quat_write_element_ref::value,qvm_detail::q_element_access<0,Q> &>::type S( Q & a ) { return *reinterpret_cast *>(&a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && !quat_write_element_ref::value,qvm_detail::q_element_access<1,Q> &>::type X( Q & a ) { return *reinterpret_cast *>(&a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && !quat_write_element_ref::value,qvm_detail::q_element_access<2,Q> &>::type Y( Q & a ) { return *reinterpret_cast *>(&a); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL typename enable_if_c::value && !quat_write_element_ref::value,qvm_detail::q_element_access<3,Q> &>::type Z( Q & a ) { return *reinterpret_cast *>(&a); } } } #endif