#ifndef BOOST_QVM_MAP_MAT_VEC_HPP_INCLUDED #define BOOST_QVM_MAP_MAT_VEC_HPP_INCLUDED /// Copyright (c) 2008-2021 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 { namespace qvm_detail { template class col_ { col_( col_ const & ); col_ & operator=( col_ const & ); ~col_(); public: template BOOST_QVM_INLINE_TRIVIAL col_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct vec_traits< qvm_detail::col_ > { typedef qvm_detail::col_ this_vector; typedef typename mat_traits::scalar_type scalar_type; static int const dim=mat_traits::rows; BOOST_QVM_STATIC_ASSERT(Col>=0); BOOST_QVM_STATIC_ASSERT(Col::cols); template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_vector const & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template read_element(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_vector & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template write_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int i, this_vector const & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::read_element_idx(i,Col,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int i, this_vector & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::write_element_idx(i,Col,reinterpret_cast(x)); } }; template struct deduce_vec,D> { typedef vec::scalar_type,D> type; }; template struct deduce_vec2,qvm_detail::col_,D> { typedef vec::scalar_type,D> type; }; template typename enable_if_c< is_mat::value, qvm_detail::col_ const &>::type BOOST_QVM_INLINE_TRIVIAL col( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::col_ &>::type BOOST_QVM_INLINE_TRIVIAL col( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class row_ { row_( row_ const & ); row_ & operator=( row_ const & ); ~row_(); public: template BOOST_QVM_INLINE_TRIVIAL row_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct vec_traits< qvm_detail::row_ > { typedef qvm_detail::row_ this_vector; typedef typename mat_traits::scalar_type scalar_type; static int const dim=mat_traits::cols; BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row::rows); template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_vector const & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template read_element(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_vector & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template write_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int i, this_vector const & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::read_element_idx(Row,i,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int i, this_vector & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::write_element_idx(Row,i,reinterpret_cast(x)); } }; template struct deduce_vec,D> { typedef vec::scalar_type,D> type; }; template struct deduce_vec2,qvm_detail::row_,D> { typedef vec::scalar_type,D> type; }; template typename enable_if_c< is_mat::value, qvm_detail::row_ const &>::type BOOST_QVM_INLINE_TRIVIAL row( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::row_ &>::type BOOST_QVM_INLINE_TRIVIAL row( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class diag_ { diag_( diag_ const & ); diag_ & operator=( diag_ const & ); ~diag_(); public: template BOOST_QVM_INLINE_TRIVIAL diag_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; template struct diag_bool_dispatch; template struct diag_bool_dispatch { static int const value=X; }; template struct diag_bool_dispatch { static int const value=Y; }; } template struct vec_traits< qvm_detail::diag_ > { typedef qvm_detail::diag_ this_vector; typedef typename mat_traits::scalar_type scalar_type; static int const dim=qvm_detail::diag_bool_dispatch< mat_traits::rows, mat_traits::cols, mat_traits::rows<=mat_traits::cols>::value; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_vector const & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template read_element(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_vector & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template write_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int i, this_vector const & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::read_element_idx(i,i,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int i, this_vector & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::write_element_idx(i,i,reinterpret_cast(x)); } }; template struct deduce_vec,D> { typedef vec::scalar_type,D> type; }; template struct deduce_vec2,qvm_detail::diag_,D> { typedef vec::scalar_type,D> type; }; template typename enable_if_c< is_mat::value, qvm_detail::diag_ const &>::type BOOST_QVM_INLINE_TRIVIAL diag( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::diag_ &>::type BOOST_QVM_INLINE_TRIVIAL diag( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class translation_ { translation_( translation_ const & ); ~translation_(); public: translation_ & operator=( translation_ const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL translation_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct vec_traits< qvm_detail::translation_ > { typedef qvm_detail::translation_ this_vector; typedef typename mat_traits::scalar_type scalar_type; static int const dim=mat_traits::rows-1; BOOST_QVM_STATIC_ASSERT(mat_traits::rows==mat_traits::cols); BOOST_QVM_STATIC_ASSERT(mat_traits::rows>=3); template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_vector const & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template read_element(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_vector & x ) { BOOST_QVM_STATIC_ASSERT(I>=0); BOOST_QVM_STATIC_ASSERT(I::template write_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int i, this_vector const & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::read_element_idx(i,dim,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int i, this_vector & x ) { BOOST_QVM_ASSERT(i>=0); BOOST_QVM_ASSERT(i::write_element_idx(i,dim,reinterpret_cast(x)); } }; template struct deduce_vec,D> { typedef vec::scalar_type,D> type; }; template struct deduce_vec2,qvm_detail::translation_,D> { typedef vec::scalar_type,D> type; }; template typename enable_if_c< is_mat::value && mat_traits::rows==mat_traits::cols && mat_traits::rows>=3, qvm_detail::translation_ const &>::type BOOST_QVM_INLINE_TRIVIAL translation( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value && mat_traits::rows==mat_traits::cols && mat_traits::rows>=3, qvm_detail::translation_ &>::type BOOST_QVM_INLINE_TRIVIAL translation( A & a ) { return reinterpret_cast &>(a); } } } #endif