Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:51:38

0001 #ifndef BOOST_QVM_VEC_MAT_OPERATIONS_HPP_INCLUDED
0002 #define BOOST_QVM_VEC_MAT_OPERATIONS_HPP_INCLUDED
0003 
0004 // Copyright 2008-2024 Emil Dotchevski and Reverge Studios, Inc.
0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #include <boost/qvm/vec_mat_operations2.hpp>
0009 #include <boost/qvm/vec_mat_operations3.hpp>
0010 #include <boost/qvm/vec_mat_operations4.hpp>
0011 
0012 namespace boost { namespace qvm {
0013 
0014 namespace
0015 qvm_detail
0016     {
0017     template <int M,int N>
0018     struct
0019     mul_mv_defined
0020         {
0021         static bool const value=false;
0022         };
0023     }
0024 
0025 template <class A,class B>
0026 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
0027 typename lazy_enable_if_c<
0028     is_mat<A>::value && is_vec<B>::value &&
0029     mat_traits<A>::cols==vec_traits<B>::dim &&
0030     !qvm_detail::mul_mv_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
0031     deduce_vec2<A,B,mat_traits<A>::rows> >::type
0032 operator*( A const & a, B const & b )
0033     {
0034     typedef typename deduce_vec2<A,B,mat_traits<A>::rows>::type R;
0035     R r;
0036     for( int i=0; i<mat_traits<A>::rows; ++i )
0037         {
0038         typedef typename vec_traits<R>::scalar_type Tr;
0039         Tr x(scalar_traits<Tr>::value(0));
0040         for( int j=0; j<mat_traits<A>::cols; ++j )
0041             x += mat_traits<A>::read_element_idx(i,j,a)*vec_traits<B>::read_element_idx(j,b);
0042         write_vec_element_idx(i,r,x);
0043         }
0044     return r;
0045     }
0046 
0047 namespace
0048 qvm_detail
0049     {
0050     template <int M,int N>
0051     struct
0052     mul_vm_defined
0053         {
0054         static bool const value=false;
0055         };
0056     }
0057 
0058 template <class A,class B>
0059 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
0060 typename lazy_enable_if_c<
0061     is_vec<A>::value && is_mat<B>::value &&
0062     vec_traits<A>::dim==mat_traits<B>::rows &&
0063     !qvm_detail::mul_vm_defined<mat_traits<B>::rows,mat_traits<B>::cols>::value,
0064     deduce_vec2<A,B,mat_traits<B>::cols> >::type
0065 operator*( A const & a, B const & b )
0066     {
0067     typedef typename deduce_vec2<A,B,mat_traits<B>::cols>::type R;
0068     R r;
0069     for( int i=0; i<mat_traits<B>::cols; ++i )
0070         {
0071         typedef typename vec_traits<R>::scalar_type Tr;
0072         Tr x(scalar_traits<Tr>::value(0));
0073         for( int j=0; j<mat_traits<B>::rows; ++j )
0074             x += vec_traits<A>::read_element_idx(j,a)*mat_traits<B>::read_element_idx(j,i,b);
0075         write_vec_element_idx(i,r,x);
0076         }
0077     return r;
0078     }
0079 
0080 ////////////////////////////////////////////////
0081 
0082 template <class A,class B>
0083 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
0084 typename lazy_enable_if_c<
0085     mat_traits<A>::rows==4 && mat_traits<A>::cols==4 &&
0086     vec_traits<B>::dim==3,
0087     deduce_vec2<A,B,3> >::type
0088 transform_point( A const & a, B const & b )
0089     {
0090     typedef typename mat_traits<A>::scalar_type Ta;
0091     typedef typename vec_traits<B>::scalar_type Tb;
0092     Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
0093     Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
0094     Ta const a02 = mat_traits<A>::template read_element<0,2>(a);
0095     Ta const a03 = mat_traits<A>::template read_element<0,3>(a);
0096     Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
0097     Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
0098     Ta const a12 = mat_traits<A>::template read_element<1,2>(a);
0099     Ta const a13 = mat_traits<A>::template read_element<1,3>(a);
0100     Ta const a20 = mat_traits<A>::template read_element<2,0>(a);
0101     Ta const a21 = mat_traits<A>::template read_element<2,1>(a);
0102     Ta const a22 = mat_traits<A>::template read_element<2,2>(a);
0103     Ta const a23 = mat_traits<A>::template read_element<2,3>(a);
0104     Tb const b0 = vec_traits<B>::template read_element<0>(b);
0105     Tb const b1 = vec_traits<B>::template read_element<1>(b);
0106     Tb const b2 = vec_traits<B>::template read_element<2>(b);
0107     typedef typename deduce_vec2<A,B,3>::type R;
0108     BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==3);
0109     R r;
0110     write_vec_element<0>(r, a00*b0+a01*b1+a02*b2+a03);
0111     write_vec_element<1>(r, a10*b0+a11*b1+a12*b2+a13);
0112     write_vec_element<2>(r, a20*b0+a21*b1+a22*b2+a23);
0113     return r;
0114     }
0115 
0116 template <class A,class B>
0117 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
0118 typename lazy_enable_if_c<
0119     mat_traits<A>::rows==4 && mat_traits<A>::cols==4 &&
0120     vec_traits<B>::dim==3,
0121     deduce_vec2<A,B,3> >::type
0122 transform_vector( A const & a, B const & b )
0123     {
0124     typedef typename mat_traits<A>::scalar_type Ta;
0125     typedef typename vec_traits<B>::scalar_type Tb;
0126     Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
0127     Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
0128     Ta const a02 = mat_traits<A>::template read_element<0,2>(a);
0129     Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
0130     Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
0131     Ta const a12 = mat_traits<A>::template read_element<1,2>(a);
0132     Ta const a20 = mat_traits<A>::template read_element<2,0>(a);
0133     Ta const a21 = mat_traits<A>::template read_element<2,1>(a);
0134     Ta const a22 = mat_traits<A>::template read_element<2,2>(a);
0135     Tb const b0 = vec_traits<B>::template read_element<0>(b);
0136     Tb const b1 = vec_traits<B>::template read_element<1>(b);
0137     Tb const b2 = vec_traits<B>::template read_element<2>(b);
0138     typedef typename deduce_vec2<A,B,3>::type R;
0139     BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==3);
0140     R r;
0141     write_vec_element<0>(r, a00*b0+a01*b1+a02*b2);
0142     write_vec_element<1>(r, a10*b0+a11*b1+a12*b2);
0143     write_vec_element<2>(r, a20*b0+a21*b1+a22*b2);
0144     return r;
0145     }
0146 
0147 ////////////////////////////////////////////////
0148 
0149 namespace
0150 sfinae
0151     {
0152     using ::boost::qvm::operator*;
0153     using ::boost::qvm::transform_point;
0154     using ::boost::qvm::transform_vector;
0155     }
0156 
0157 } }
0158 
0159 #endif