]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/qvm/vec_mat_operations.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / qvm / vec_mat_operations.hpp
CommitLineData
1e59de90
TL
1#ifndef BOOST_QVM_VEC_MAT_OPERATIONS_HPP_INCLUDED
2#define BOOST_QVM_VEC_MAT_OPERATIONS_HPP_INCLUDED
92f5a8d4 3
1e59de90 4// Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
92f5a8d4 5
1e59de90
TL
6// Distributed under the Boost Software License, Version 1.0. (See accompanying
7// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
92f5a8d4
TL
8
9#include <boost/qvm/vec_mat_operations2.hpp>
10#include <boost/qvm/vec_mat_operations3.hpp>
11#include <boost/qvm/vec_mat_operations4.hpp>
12
1e59de90
TL
13namespace boost { namespace qvm {
14
92f5a8d4 15namespace
1e59de90 16qvm_detail
92f5a8d4 17 {
1e59de90
TL
18 template <int M,int N>
19 struct
20 mul_mv_defined
92f5a8d4 21 {
1e59de90
TL
22 static bool const value=false;
23 };
24 }
92f5a8d4 25
1e59de90
TL
26template <class A,class B>
27BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
28typename lazy_enable_if_c<
29 is_mat<A>::value && is_vec<B>::value &&
30 mat_traits<A>::cols==vec_traits<B>::dim &&
31 !qvm_detail::mul_mv_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
32 deduce_vec2<A,B,mat_traits<A>::rows> >::type
33operator*( A const & a, B const & b )
34 {
35 typedef typename deduce_vec2<A,B,mat_traits<A>::rows>::type R;
36 R r;
37 for( int i=0; i<mat_traits<A>::rows; ++i )
38 {
39 typedef typename vec_traits<R>::scalar_type Tr;
40 Tr x(scalar_traits<Tr>::value(0));
41 for( int j=0; j<mat_traits<A>::cols; ++j )
42 x += mat_traits<A>::read_element_idx(i,j,a)*vec_traits<B>::read_element_idx(j,b);
43 vec_traits<R>::write_element_idx(i,r) = x;
44 }
45 return r;
46 }
92f5a8d4 47
1e59de90
TL
48namespace
49qvm_detail
50 {
51 template <int M,int N>
52 struct
53 mul_vm_defined
54 {
55 static bool const value=false;
56 };
57 }
92f5a8d4 58
1e59de90
TL
59template <class A,class B>
60BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
61typename lazy_enable_if_c<
62 is_vec<A>::value && is_mat<B>::value &&
63 vec_traits<A>::dim==mat_traits<B>::rows &&
64 !qvm_detail::mul_vm_defined<mat_traits<B>::rows,mat_traits<B>::cols>::value,
65 deduce_vec2<A,B,mat_traits<B>::cols> >::type
66operator*( A const & a, B const & b )
67 {
68 typedef typename deduce_vec2<A,B,mat_traits<B>::cols>::type R;
69 R r;
70 for( int i=0; i<mat_traits<B>::cols; ++i )
71 {
72 typedef typename vec_traits<R>::scalar_type Tr;
73 Tr x(scalar_traits<Tr>::value(0));
74 for( int j=0; j<mat_traits<B>::rows; ++j )
75 x += vec_traits<A>::read_element_idx(j,a)*mat_traits<B>::read_element_idx(j,i,b);
76 vec_traits<R>::write_element_idx(i,r) = x;
77 }
78 return r;
79 }
92f5a8d4 80
1e59de90 81////////////////////////////////////////////////
92f5a8d4 82
1e59de90
TL
83template <class A,class B>
84BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
85typename lazy_enable_if_c<
86 mat_traits<A>::rows==4 && mat_traits<A>::cols==4 &&
87 vec_traits<B>::dim==3,
88 deduce_vec2<A,B,3> >::type
89transform_point( A const & a, B const & b )
90 {
91 typedef typename mat_traits<A>::scalar_type Ta;
92 typedef typename vec_traits<B>::scalar_type Tb;
93 Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
94 Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
95 Ta const a02 = mat_traits<A>::template read_element<0,2>(a);
96 Ta const a03 = mat_traits<A>::template read_element<0,3>(a);
97 Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
98 Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
99 Ta const a12 = mat_traits<A>::template read_element<1,2>(a);
100 Ta const a13 = mat_traits<A>::template read_element<1,3>(a);
101 Ta const a20 = mat_traits<A>::template read_element<2,0>(a);
102 Ta const a21 = mat_traits<A>::template read_element<2,1>(a);
103 Ta const a22 = mat_traits<A>::template read_element<2,2>(a);
104 Ta const a23 = mat_traits<A>::template read_element<2,3>(a);
105 Tb const b0 = vec_traits<B>::template read_element<0>(b);
106 Tb const b1 = vec_traits<B>::template read_element<1>(b);
107 Tb const b2 = vec_traits<B>::template read_element<2>(b);
108 typedef typename deduce_vec2<A,B,3>::type R;
109 BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==3);
110 R r;
111 vec_traits<R>::template write_element<0>(r)=a00*b0+a01*b1+a02*b2+a03;
112 vec_traits<R>::template write_element<1>(r)=a10*b0+a11*b1+a12*b2+a13;
113 vec_traits<R>::template write_element<2>(r)=a20*b0+a21*b1+a22*b2+a23;
114 return r;
115 }
92f5a8d4 116
1e59de90
TL
117template <class A,class B>
118BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
119typename lazy_enable_if_c<
120 mat_traits<A>::rows==4 && mat_traits<A>::cols==4 &&
121 vec_traits<B>::dim==3,
122 deduce_vec2<A,B,3> >::type
123transform_vector( A const & a, B const & b )
124 {
125 typedef typename mat_traits<A>::scalar_type Ta;
126 typedef typename vec_traits<B>::scalar_type Tb;
127 Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
128 Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
129 Ta const a02 = mat_traits<A>::template read_element<0,2>(a);
130 Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
131 Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
132 Ta const a12 = mat_traits<A>::template read_element<1,2>(a);
133 Ta const a20 = mat_traits<A>::template read_element<2,0>(a);
134 Ta const a21 = mat_traits<A>::template read_element<2,1>(a);
135 Ta const a22 = mat_traits<A>::template read_element<2,2>(a);
136 Tb const b0 = vec_traits<B>::template read_element<0>(b);
137 Tb const b1 = vec_traits<B>::template read_element<1>(b);
138 Tb const b2 = vec_traits<B>::template read_element<2>(b);
139 typedef typename deduce_vec2<A,B,3>::type R;
140 BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==3);
141 R r;
142 vec_traits<R>::template write_element<0>(r)=a00*b0+a01*b1+a02*b2;
143 vec_traits<R>::template write_element<1>(r)=a10*b0+a11*b1+a12*b2;
144 vec_traits<R>::template write_element<2>(r)=a20*b0+a21*b1+a22*b2;
145 return r;
146 }
92f5a8d4 147
1e59de90 148////////////////////////////////////////////////
92f5a8d4 149
1e59de90
TL
150namespace
151sfinae
152 {
153 using ::boost::qvm::operator*;
154 using ::boost::qvm::transform_point;
155 using ::boost::qvm::transform_vector;
92f5a8d4
TL
156 }
157
1e59de90
TL
158} }
159
92f5a8d4 160#endif