File: vec_mat_operations.hpp

package info (click to toggle)
boost1.62 1.62.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 686,420 kB
  • sloc: cpp: 2,609,004; xml: 972,558; ansic: 53,674; python: 32,437; sh: 8,829; asm: 3,071; cs: 2,121; makefile: 964; perl: 859; yacc: 472; php: 132; ruby: 94; f90: 55; sql: 13; csh: 6
file content (168 lines) | stat: -rw-r--r-- 7,177 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//Copyright (c) 2008-2016 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)

#ifndef UUID_A61EC088D31511DFA59D2B03E0D72085
#define UUID_A61EC088D31511DFA59D2B03E0D72085

#include <boost/qvm/vec_mat_operations2.hpp>
#include <boost/qvm/vec_mat_operations3.hpp>
#include <boost/qvm/vec_mat_operations4.hpp>

namespace
boost
    {
    namespace
    qvm
        {
        ////////////////////////////////////////////////

        namespace
        qvm_detail
            {
            template <int M,int N>
            struct
            mul_mv_defined
                {
                static bool const value=false;
                };
            }

        template <class A,class B>
        BOOST_QVM_INLINE_OPERATIONS
        typename lazy_enable_if_c<
            is_mat<A>::value && is_vec<B>::value &&
            mat_traits<A>::cols==vec_traits<B>::dim &&
            !qvm_detail::mul_mv_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
            deduce_vec2<A,B,mat_traits<A>::rows> >::type
        operator*( A const & a, B const & b )
            {
            typedef typename deduce_vec2<A,B,mat_traits<A>::rows>::type R;
            R r;
            for( int i=0; i<mat_traits<A>::rows; ++i )
                {
                typedef typename vec_traits<R>::scalar_type Tr;
                Tr x(scalar_traits<Tr>::value(0));
                for( int j=0; j<mat_traits<A>::cols; ++j )
                    x += mat_traits<A>::read_element_idx(i,j,a)*vec_traits<B>::read_element_idx(j,b);
                vec_traits<R>::write_element_idx(i,r) = x;
                }
            return r;
            }

        namespace
        qvm_detail
            {
            template <int M,int N>
            struct
            mul_vm_defined
                {
                static bool const value=false;
                };
            }

        template <class A,class B>
        BOOST_QVM_INLINE_OPERATIONS
        typename lazy_enable_if_c<
            is_vec<A>::value && is_mat<B>::value &&
            vec_traits<A>::dim==mat_traits<B>::rows &&
            !qvm_detail::mul_vm_defined<mat_traits<B>::rows,mat_traits<B>::cols>::value,
            deduce_vec2<A,B,mat_traits<B>::cols> >::type
        operator*( A const & a, B const & b )
            {
            typedef typename deduce_vec2<A,B,mat_traits<B>::cols>::type R;
            R r;
            for( int i=0; i<mat_traits<B>::cols; ++i )
                {
                typedef typename vec_traits<R>::scalar_type Tr;
                Tr x(scalar_traits<Tr>::value(0));
                for( int j=0; j<mat_traits<B>::rows; ++j )
                    x += vec_traits<A>::read_element_idx(j,a)*mat_traits<B>::read_element_idx(j,i,b);
                vec_traits<R>::write_element_idx(i,r) = x;
                }
            return r;
            }

        ////////////////////////////////////////////////

        template <class A,class B>
        BOOST_QVM_INLINE_OPERATIONS
        typename lazy_enable_if_c<
            mat_traits<A>::rows==4 && mat_traits<A>::cols==4 &&
            vec_traits<B>::dim==3,
            deduce_vec2<A,B,3> >::type
        transform_point( A const & a, B const & b )
            {
            typedef typename mat_traits<A>::scalar_type Ta;
            typedef typename vec_traits<B>::scalar_type Tb;
            Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
            Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
            Ta const a02 = mat_traits<A>::template read_element<0,2>(a);
            Ta const a03 = mat_traits<A>::template read_element<0,3>(a);
            Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
            Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
            Ta const a12 = mat_traits<A>::template read_element<1,2>(a);
            Ta const a13 = mat_traits<A>::template read_element<1,3>(a);
            Ta const a20 = mat_traits<A>::template read_element<2,0>(a);
            Ta const a21 = mat_traits<A>::template read_element<2,1>(a);
            Ta const a22 = mat_traits<A>::template read_element<2,2>(a);
            Ta const a23 = mat_traits<A>::template read_element<2,3>(a);
            Tb const b0 = vec_traits<B>::template read_element<0>(b);
            Tb const b1 = vec_traits<B>::template read_element<1>(b);
            Tb const b2 = vec_traits<B>::template read_element<2>(b);
            typedef typename deduce_vec2<A,B,3>::type R;
            BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==3);
            R r;
            vec_traits<R>::template write_element<0>(r)=a00*b0+a01*b1+a02*b2+a03;
            vec_traits<R>::template write_element<1>(r)=a10*b0+a11*b1+a12*b2+a13;
            vec_traits<R>::template write_element<2>(r)=a20*b0+a21*b1+a22*b2+a23;
            return r;
            }

        template <class A,class B>
        BOOST_QVM_INLINE_OPERATIONS
        typename lazy_enable_if_c<
            mat_traits<A>::rows==4 && mat_traits<A>::cols==4 &&
            vec_traits<B>::dim==3,
            deduce_vec2<A,B,3> >::type
        transform_vector( A const & a, B const & b )
            {
            typedef typename mat_traits<A>::scalar_type Ta;
            typedef typename vec_traits<B>::scalar_type Tb;
            Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
            Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
            Ta const a02 = mat_traits<A>::template read_element<0,2>(a);
            Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
            Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
            Ta const a12 = mat_traits<A>::template read_element<1,2>(a);
            Ta const a20 = mat_traits<A>::template read_element<2,0>(a);
            Ta const a21 = mat_traits<A>::template read_element<2,1>(a);
            Ta const a22 = mat_traits<A>::template read_element<2,2>(a);
            Tb const b0 = vec_traits<B>::template read_element<0>(b);
            Tb const b1 = vec_traits<B>::template read_element<1>(b);
            Tb const b2 = vec_traits<B>::template read_element<2>(b);
            typedef typename deduce_vec2<A,B,3>::type R;
            BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==3);
            R r;
            vec_traits<R>::template write_element<0>(r)=a00*b0+a01*b1+a02*b2;
            vec_traits<R>::template write_element<1>(r)=a10*b0+a11*b1+a12*b2;
            vec_traits<R>::template write_element<2>(r)=a20*b0+a21*b1+a22*b2;
            return r;
            }

        ////////////////////////////////////////////////

        namespace
        sfinae
            {
            using ::boost::qvm::operator*;
            using ::boost::qvm::transform_point;
            using ::boost::qvm::transform_vector;
            }

        ////////////////////////////////////////////////
        }
    }

#endif