File indexing completed on 2025-01-30 09:59:04
0001 #ifndef BOOST_QVM_MAP_MAT_VEC_HPP_INCLUDED
0002 #define BOOST_QVM_MAP_MAT_VEC_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009 #include <boost/qvm/config.hpp>
0010 #include <boost/qvm/mat_traits.hpp>
0011 #include <boost/qvm/deduce_vec.hpp>
0012 #include <boost/qvm/assert.hpp>
0013 #include <boost/qvm/enable_if.hpp>
0014
0015 namespace boost { namespace qvm {
0016
0017 namespace
0018 qvm_detail
0019 {
0020 template <int Col,class OriginalMatrix>
0021 class
0022 col_
0023 {
0024 col_( col_ const & );
0025 col_ & operator=( col_ const & );
0026 ~col_();
0027
0028 public:
0029
0030 template <class T>
0031 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0032 col_ &
0033 operator=( T const & x )
0034 {
0035 assign(*this,x);
0036 return *this;
0037 }
0038
0039 template <class R
0040 #if __cplusplus >= 201103L
0041 , class = typename enable_if<is_vec<R> >::type
0042 #endif
0043 >
0044 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0045 operator R() const
0046 {
0047 R r;
0048 assign(r,*this);
0049 return r;
0050 }
0051 };
0052
0053 template <int Col,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
0054 struct col_write_traits;
0055
0056 template <int Col,class OriginalMatrix>
0057 struct
0058 col_write_traits<Col,OriginalMatrix,true>
0059 {
0060 typedef qvm_detail::col_<Col,OriginalMatrix> this_vector;
0061 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0062 static int const dim=mat_traits<OriginalMatrix>::rows;
0063 BOOST_QVM_STATIC_ASSERT(Col>=0);
0064 BOOST_QVM_STATIC_ASSERT(Col<mat_traits<OriginalMatrix>::cols);
0065
0066 template <int I>
0067 static
0068 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0069 scalar_type &
0070 write_element( this_vector & x )
0071 {
0072 BOOST_QVM_STATIC_ASSERT(I>=0);
0073 BOOST_QVM_STATIC_ASSERT(I<dim);
0074 return mat_traits<OriginalMatrix>::template write_element<I,Col>(reinterpret_cast<OriginalMatrix &>(x));
0075 }
0076
0077 static
0078 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0079 scalar_type &
0080 write_element_idx( int i, this_vector & x )
0081 {
0082 BOOST_QVM_ASSERT(i>=0);
0083 BOOST_QVM_ASSERT(i<dim);
0084 return mat_traits<OriginalMatrix>::write_element_idx(i,Col,reinterpret_cast<OriginalMatrix &>(x));
0085 }
0086 };
0087
0088 template <int Col,class OriginalMatrix>
0089 struct
0090 col_write_traits<Col,OriginalMatrix,false>
0091 {
0092 typedef qvm_detail::col_<Col,OriginalMatrix> this_vector;
0093 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0094 static int const dim=mat_traits<OriginalMatrix>::rows;
0095 BOOST_QVM_STATIC_ASSERT(Col>=0);
0096 BOOST_QVM_STATIC_ASSERT(Col<mat_traits<OriginalMatrix>::cols);
0097
0098 template <int I>
0099 static
0100 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0101 void
0102 write_element( this_vector & x, scalar_type s )
0103 {
0104 BOOST_QVM_STATIC_ASSERT(I>=0);
0105 BOOST_QVM_STATIC_ASSERT(I<dim);
0106 mat_traits<OriginalMatrix>::template write_element<I,Col>(reinterpret_cast<OriginalMatrix &>(x), s);
0107 }
0108
0109 static
0110 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0111 void
0112 write_element_idx( int i, this_vector & x, scalar_type s )
0113 {
0114 BOOST_QVM_ASSERT(i>=0);
0115 BOOST_QVM_ASSERT(i<dim);
0116 mat_traits<OriginalMatrix>::write_element_idx(i,Col,reinterpret_cast<OriginalMatrix &>(x), s);
0117 }
0118 };
0119 }
0120
0121 template <int Col,class OriginalMatrix>
0122 struct
0123 vec_traits< qvm_detail::col_<Col,OriginalMatrix> >:
0124 qvm_detail::col_write_traits<Col,OriginalMatrix>
0125 {
0126 typedef qvm_detail::col_<Col,OriginalMatrix> this_vector;
0127 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0128 static int const dim=mat_traits<OriginalMatrix>::rows;
0129 BOOST_QVM_STATIC_ASSERT(Col>=0);
0130 BOOST_QVM_STATIC_ASSERT(Col<mat_traits<OriginalMatrix>::cols);
0131
0132 template <int I>
0133 static
0134 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0135 scalar_type
0136 read_element( this_vector const & x )
0137 {
0138 BOOST_QVM_STATIC_ASSERT(I>=0);
0139 BOOST_QVM_STATIC_ASSERT(I<dim);
0140 return mat_traits<OriginalMatrix>::template read_element<I,Col>(reinterpret_cast<OriginalMatrix const &>(x));
0141 }
0142
0143 static
0144 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0145 scalar_type
0146 read_element_idx( int i, this_vector const & x )
0147 {
0148 BOOST_QVM_ASSERT(i>=0);
0149 BOOST_QVM_ASSERT(i<dim);
0150 return mat_traits<OriginalMatrix>::read_element_idx(i,Col,reinterpret_cast<OriginalMatrix const &>(x));
0151 }
0152 };
0153
0154 template <int Col,class OriginalMatrix,int D>
0155 struct
0156 deduce_vec<qvm_detail::col_<Col,OriginalMatrix>,D>
0157 {
0158 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0159 };
0160
0161 template <int Col,class OriginalMatrix,int D>
0162 struct
0163 deduce_vec2<qvm_detail::col_<Col,OriginalMatrix>,qvm_detail::col_<Col,OriginalMatrix>,D>
0164 {
0165 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0166 };
0167
0168 template <int Col,class A>
0169 typename enable_if_c<
0170 is_mat<A>::value,
0171 qvm_detail::col_<Col,A> const &>::type
0172 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0173 col( A const & a )
0174 {
0175 return reinterpret_cast<typename qvm_detail::col_<Col,A> const &>(a);
0176 }
0177
0178 template <int Col,class A>
0179 typename enable_if_c<
0180 is_mat<A>::value,
0181 qvm_detail::col_<Col,A> &>::type
0182 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0183 col( A & a )
0184 {
0185 return reinterpret_cast<typename qvm_detail::col_<Col,A> &>(a);
0186 }
0187
0188
0189
0190 namespace
0191 qvm_detail
0192 {
0193 template <int Row,class OriginalMatrix>
0194 class
0195 row_
0196 {
0197 row_( row_ const & );
0198 row_ & operator=( row_ const & );
0199 ~row_();
0200
0201 public:
0202
0203 template <class T>
0204 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0205 row_ &
0206 operator=( T const & x )
0207 {
0208 assign(*this,x);
0209 return *this;
0210 }
0211
0212 template <class R
0213 #if __cplusplus >= 201103L
0214 , class = typename enable_if<is_vec<R> >::type
0215 #endif
0216 >
0217 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0218 operator R() const
0219 {
0220 R r;
0221 assign(r,*this);
0222 return r;
0223 }
0224 };
0225
0226 template <int Row,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
0227 struct row_write_traits;
0228
0229 template <int Row,class OriginalMatrix>
0230 struct
0231 row_write_traits<Row,OriginalMatrix,true>
0232 {
0233 typedef qvm_detail::row_<Row,OriginalMatrix> this_vector;
0234 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0235 static int const dim=mat_traits<OriginalMatrix>::cols;
0236 BOOST_QVM_STATIC_ASSERT(Row>=0);
0237 BOOST_QVM_STATIC_ASSERT(Row<mat_traits<OriginalMatrix>::rows);
0238
0239 template <int I>
0240 static
0241 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0242 scalar_type &
0243 write_element( this_vector & x )
0244 {
0245 BOOST_QVM_STATIC_ASSERT(I>=0);
0246 BOOST_QVM_STATIC_ASSERT(I<dim);
0247 return mat_traits<OriginalMatrix>::template write_element<Row,I>(reinterpret_cast<OriginalMatrix &>(x));
0248 }
0249
0250 static
0251 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0252 scalar_type &
0253 write_element_idx( int i, this_vector & x )
0254 {
0255 BOOST_QVM_ASSERT(i>=0);
0256 BOOST_QVM_ASSERT(i<dim);
0257 return mat_traits<OriginalMatrix>::write_element_idx(Row,i,reinterpret_cast<OriginalMatrix &>(x));
0258 }
0259 };
0260
0261 template <int Row,class OriginalMatrix>
0262 struct
0263 row_write_traits<Row,OriginalMatrix,false>
0264 {
0265 typedef qvm_detail::row_<Row,OriginalMatrix> this_vector;
0266 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0267 static int const dim=mat_traits<OriginalMatrix>::cols;
0268 BOOST_QVM_STATIC_ASSERT(Row>=0);
0269 BOOST_QVM_STATIC_ASSERT(Row<mat_traits<OriginalMatrix>::rows);
0270
0271 template <int I>
0272 static
0273 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0274 void
0275 write_element( this_vector & x, scalar_type s )
0276 {
0277 BOOST_QVM_STATIC_ASSERT(I>=0);
0278 BOOST_QVM_STATIC_ASSERT(I<dim);
0279 mat_traits<OriginalMatrix>::template write_element<Row,I>(reinterpret_cast<OriginalMatrix &>(x), s);
0280 }
0281
0282 static
0283 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0284 void
0285 write_element_idx( int i, this_vector & x, scalar_type s )
0286 {
0287 BOOST_QVM_ASSERT(i>=0);
0288 BOOST_QVM_ASSERT(i<dim);
0289 mat_traits<OriginalMatrix>::write_element_idx(Row,i,reinterpret_cast<OriginalMatrix &>(x), s);
0290 }
0291 };
0292 }
0293
0294 template <int Row,class OriginalMatrix>
0295 struct
0296 vec_traits< qvm_detail::row_<Row,OriginalMatrix> >:
0297 qvm_detail::row_write_traits<Row,OriginalMatrix>
0298 {
0299 typedef qvm_detail::row_<Row,OriginalMatrix> this_vector;
0300 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0301 static int const dim=mat_traits<OriginalMatrix>::cols;
0302 BOOST_QVM_STATIC_ASSERT(Row>=0);
0303 BOOST_QVM_STATIC_ASSERT(Row<mat_traits<OriginalMatrix>::rows);
0304
0305 template <int I>
0306 static
0307 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0308 scalar_type
0309 read_element( this_vector const & x )
0310 {
0311 BOOST_QVM_STATIC_ASSERT(I>=0);
0312 BOOST_QVM_STATIC_ASSERT(I<dim);
0313 return mat_traits<OriginalMatrix>::template read_element<Row,I>(reinterpret_cast<OriginalMatrix const &>(x));
0314 }
0315
0316 static
0317 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0318 scalar_type
0319 read_element_idx( int i, this_vector const & x )
0320 {
0321 BOOST_QVM_ASSERT(i>=0);
0322 BOOST_QVM_ASSERT(i<dim);
0323 return mat_traits<OriginalMatrix>::read_element_idx(Row,i,reinterpret_cast<OriginalMatrix const &>(x));
0324 }
0325 };
0326
0327 template <int Row,class OriginalMatrix,int D>
0328 struct
0329 deduce_vec<qvm_detail::row_<Row,OriginalMatrix>,D>
0330 {
0331 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0332 };
0333
0334 template <int Row,class OriginalMatrix,int D>
0335 struct
0336 deduce_vec2<qvm_detail::row_<Row,OriginalMatrix>,qvm_detail::row_<Row,OriginalMatrix>,D>
0337 {
0338 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0339 };
0340
0341 template <int Row,class A>
0342 typename enable_if_c<
0343 is_mat<A>::value,
0344 qvm_detail::row_<Row,A> const &>::type
0345 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0346 row( A const & a )
0347 {
0348 return reinterpret_cast<typename qvm_detail::row_<Row,A> const &>(a);
0349 }
0350
0351 template <int Row,class A>
0352 typename enable_if_c<
0353 is_mat<A>::value,
0354 qvm_detail::row_<Row,A> &>::type
0355 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0356 row( A & a )
0357 {
0358 return reinterpret_cast<typename qvm_detail::row_<Row,A> &>(a);
0359 }
0360
0361
0362
0363 namespace
0364 qvm_detail
0365 {
0366 template <class OriginalMatrix>
0367 class
0368 diag_
0369 {
0370 diag_( diag_ const & );
0371 diag_ & operator=( diag_ const & );
0372 ~diag_();
0373
0374 public:
0375
0376 template <class T>
0377 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0378 diag_ &
0379 operator=( T const & x )
0380 {
0381 assign(*this,x);
0382 return *this;
0383 }
0384
0385 template <class R
0386 #if __cplusplus >= 201103L
0387 , class = typename enable_if<is_vec<R> >::type
0388 #endif
0389 >
0390 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0391 operator R() const
0392 {
0393 R r;
0394 assign(r,*this);
0395 return r;
0396 }
0397 };
0398
0399 template <int X,int Y,bool Which>
0400 struct diag_bool_dispatch;
0401
0402 template <int X,int Y>
0403 struct
0404 diag_bool_dispatch<X,Y,true>
0405 {
0406 static int const value=X;
0407 };
0408
0409 template <int X,int Y>
0410 struct
0411 diag_bool_dispatch<X,Y,false>
0412 {
0413 static int const value=Y;
0414 };
0415
0416 template <class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
0417 struct diag_write_traits;
0418
0419 template <class OriginalMatrix>
0420 struct
0421 diag_write_traits<OriginalMatrix,true>
0422 {
0423 typedef qvm_detail::diag_<OriginalMatrix> this_vector;
0424 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0425 static int const dim=qvm_detail::diag_bool_dispatch<
0426 mat_traits<OriginalMatrix>::rows,
0427 mat_traits<OriginalMatrix>::cols,
0428 mat_traits<OriginalMatrix>::rows<=mat_traits<OriginalMatrix>::cols>::value;
0429
0430 template <int I>
0431 static
0432 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0433 scalar_type &
0434 write_element( this_vector & x )
0435 {
0436 BOOST_QVM_STATIC_ASSERT(I>=0);
0437 BOOST_QVM_STATIC_ASSERT(I<dim);
0438 return mat_traits<OriginalMatrix>::template write_element<I,I>(reinterpret_cast<OriginalMatrix &>(x));
0439 }
0440
0441 static
0442 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0443 scalar_type &
0444 write_element_idx( int i, this_vector & x )
0445 {
0446 BOOST_QVM_ASSERT(i>=0);
0447 BOOST_QVM_ASSERT(i<dim);
0448 return mat_traits<OriginalMatrix>::write_element_idx(i,i,reinterpret_cast<OriginalMatrix &>(x));
0449 }
0450 };
0451
0452 template <class OriginalMatrix>
0453 struct
0454 diag_write_traits<OriginalMatrix,false>
0455 {
0456 typedef qvm_detail::diag_<OriginalMatrix> this_vector;
0457 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0458 static int const dim=qvm_detail::diag_bool_dispatch<
0459 mat_traits<OriginalMatrix>::rows,
0460 mat_traits<OriginalMatrix>::cols,
0461 mat_traits<OriginalMatrix>::rows<=mat_traits<OriginalMatrix>::cols>::value;
0462
0463 template <int I>
0464 static
0465 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0466 void
0467 write_element( this_vector & x, scalar_type s )
0468 {
0469 BOOST_QVM_STATIC_ASSERT(I>=0);
0470 BOOST_QVM_STATIC_ASSERT(I<dim);
0471 mat_traits<OriginalMatrix>::template write_element<I,I>(reinterpret_cast<OriginalMatrix &>(x), s);
0472 }
0473
0474 static
0475 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0476 void
0477 write_element_idx( int i, this_vector & x, scalar_type s )
0478 {
0479 BOOST_QVM_ASSERT(i>=0);
0480 BOOST_QVM_ASSERT(i<dim);
0481 mat_traits<OriginalMatrix>::write_element_idx(i,i,reinterpret_cast<OriginalMatrix &>(x), s);
0482 }
0483 };
0484 }
0485
0486 template <class OriginalMatrix>
0487 struct
0488 vec_traits< qvm_detail::diag_<OriginalMatrix> >:
0489 qvm_detail::diag_write_traits<OriginalMatrix>
0490 {
0491 typedef qvm_detail::diag_<OriginalMatrix> this_vector;
0492 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0493 static int const dim=qvm_detail::diag_bool_dispatch<
0494 mat_traits<OriginalMatrix>::rows,
0495 mat_traits<OriginalMatrix>::cols,
0496 mat_traits<OriginalMatrix>::rows<=mat_traits<OriginalMatrix>::cols>::value;
0497
0498 template <int I>
0499 static
0500 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0501 scalar_type
0502 read_element( this_vector const & x )
0503 {
0504 BOOST_QVM_STATIC_ASSERT(I>=0);
0505 BOOST_QVM_STATIC_ASSERT(I<dim);
0506 return mat_traits<OriginalMatrix>::template read_element<I,I>(reinterpret_cast<OriginalMatrix const &>(x));
0507 }
0508
0509 static
0510 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0511 scalar_type
0512 read_element_idx( int i, this_vector const & x )
0513 {
0514 BOOST_QVM_ASSERT(i>=0);
0515 BOOST_QVM_ASSERT(i<dim);
0516 return mat_traits<OriginalMatrix>::read_element_idx(i,i,reinterpret_cast<OriginalMatrix const &>(x));
0517 }
0518 };
0519
0520 template <class OriginalMatrix,int D>
0521 struct
0522 deduce_vec<qvm_detail::diag_<OriginalMatrix>,D>
0523 {
0524 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0525 };
0526
0527 template <class OriginalMatrix,int D>
0528 struct
0529 deduce_vec2<qvm_detail::diag_<OriginalMatrix>,qvm_detail::diag_<OriginalMatrix>,D>
0530 {
0531 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0532 };
0533
0534 template <class A>
0535 typename enable_if_c<
0536 is_mat<A>::value,
0537 qvm_detail::diag_<A> const &>::type
0538 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0539 diag( A const & a )
0540 {
0541 return reinterpret_cast<typename qvm_detail::diag_<A> const &>(a);
0542 }
0543
0544 template <class A>
0545 typename enable_if_c<
0546 is_mat<A>::value,
0547 qvm_detail::diag_<A> &>::type
0548 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0549 diag( A & a )
0550 {
0551 return reinterpret_cast<typename qvm_detail::diag_<A> &>(a);
0552 }
0553
0554
0555
0556 namespace
0557 qvm_detail
0558 {
0559 template <class OriginalMatrix>
0560 class
0561 translation_
0562 {
0563 translation_( translation_ const & );
0564 ~translation_();
0565
0566 public:
0567
0568 translation_ &
0569 operator=( translation_ const & x )
0570 {
0571 assign(*this,x);
0572 return *this;
0573 }
0574
0575 template <class T>
0576 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0577 translation_ &
0578 operator=( T const & x )
0579 {
0580 assign(*this,x);
0581 return *this;
0582 }
0583
0584 template <class R
0585 #if __cplusplus >= 201103L
0586 , class = typename enable_if<is_vec<R> >::type
0587 #endif
0588 >
0589 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0590 operator R() const
0591 {
0592 R r;
0593 assign(r,*this);
0594 return r;
0595 }
0596 };
0597
0598 template <class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
0599 struct translation_write_traits;
0600
0601 template <class OriginalMatrix>
0602 struct
0603 translation_write_traits<OriginalMatrix,true>
0604 {
0605 typedef qvm_detail::translation_<OriginalMatrix> this_vector;
0606 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0607 static int const dim=mat_traits<OriginalMatrix>::cols-1;
0608 BOOST_QVM_STATIC_ASSERT(mat_traits<OriginalMatrix>::rows==mat_traits<OriginalMatrix>::cols || mat_traits<OriginalMatrix>::rows+1==mat_traits<OriginalMatrix>::cols);
0609 BOOST_QVM_STATIC_ASSERT(mat_traits<OriginalMatrix>::cols>=3);
0610
0611 template <int I>
0612 static
0613 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0614 scalar_type &
0615 write_element( this_vector & x )
0616 {
0617 BOOST_QVM_STATIC_ASSERT(I>=0);
0618 BOOST_QVM_STATIC_ASSERT(I<dim);
0619 return mat_traits<OriginalMatrix>::template write_element<I,dim>(reinterpret_cast<OriginalMatrix &>(x));
0620 }
0621
0622 static
0623 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0624 scalar_type &
0625 write_element_idx( int i, this_vector & x )
0626 {
0627 BOOST_QVM_ASSERT(i>=0);
0628 BOOST_QVM_ASSERT(i<dim);
0629 return mat_traits<OriginalMatrix>::write_element_idx(i,dim,reinterpret_cast<OriginalMatrix &>(x));
0630 }
0631 };
0632
0633 template <class OriginalMatrix>
0634 struct
0635 translation_write_traits<OriginalMatrix,false>
0636 {
0637 typedef qvm_detail::translation_<OriginalMatrix> this_vector;
0638 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0639 static int const dim=mat_traits<OriginalMatrix>::cols-1;
0640 BOOST_QVM_STATIC_ASSERT(mat_traits<OriginalMatrix>::rows==mat_traits<OriginalMatrix>::cols || mat_traits<OriginalMatrix>::rows+1==mat_traits<OriginalMatrix>::cols);
0641 BOOST_QVM_STATIC_ASSERT(mat_traits<OriginalMatrix>::cols>=3);
0642
0643 template <int I>
0644 static
0645 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0646 void
0647 write_element( this_vector & x, scalar_type s )
0648 {
0649 BOOST_QVM_STATIC_ASSERT(I>=0);
0650 BOOST_QVM_STATIC_ASSERT(I<dim);
0651 mat_traits<OriginalMatrix>::template write_element<I,dim>(reinterpret_cast<OriginalMatrix &>(x), s);
0652 }
0653
0654 static
0655 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0656 void
0657 write_element_idx( int i, this_vector & x, scalar_type s )
0658 {
0659 BOOST_QVM_ASSERT(i>=0);
0660 BOOST_QVM_ASSERT(i<dim);
0661 mat_traits<OriginalMatrix>::write_element_idx(i,dim,reinterpret_cast<OriginalMatrix &>(x), s);
0662 }
0663 };
0664 }
0665
0666 template <class OriginalMatrix>
0667 struct
0668 vec_traits< qvm_detail::translation_<OriginalMatrix> >:
0669 qvm_detail::translation_write_traits<OriginalMatrix>
0670 {
0671 typedef qvm_detail::translation_<OriginalMatrix> this_vector;
0672 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0673 static int const dim=mat_traits<OriginalMatrix>::cols-1;
0674 BOOST_QVM_STATIC_ASSERT(mat_traits<OriginalMatrix>::rows==mat_traits<OriginalMatrix>::cols || mat_traits<OriginalMatrix>::rows+1==mat_traits<OriginalMatrix>::cols);
0675 BOOST_QVM_STATIC_ASSERT(mat_traits<OriginalMatrix>::cols>=3);
0676
0677 template <int I>
0678 static
0679 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0680 scalar_type
0681 read_element( this_vector const & x )
0682 {
0683 BOOST_QVM_STATIC_ASSERT(I>=0);
0684 BOOST_QVM_STATIC_ASSERT(I<dim);
0685 return mat_traits<OriginalMatrix>::template read_element<I,dim>(reinterpret_cast<OriginalMatrix const &>(x));
0686 }
0687
0688 static
0689 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0690 scalar_type
0691 read_element_idx( int i, this_vector const & x )
0692 {
0693 BOOST_QVM_ASSERT(i>=0);
0694 BOOST_QVM_ASSERT(i<dim);
0695 return mat_traits<OriginalMatrix>::read_element_idx(i,dim,reinterpret_cast<OriginalMatrix const &>(x));
0696 }
0697 };
0698
0699 template <class OriginalMatrix,int D>
0700 struct
0701 deduce_vec<qvm_detail::translation_<OriginalMatrix>,D>
0702 {
0703 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0704 };
0705
0706 template <class OriginalMatrix,int D>
0707 struct
0708 deduce_vec2<qvm_detail::translation_<OriginalMatrix>,qvm_detail::translation_<OriginalMatrix>,D>
0709 {
0710 typedef vec<typename mat_traits<OriginalMatrix>::scalar_type,D> type;
0711 };
0712
0713 template <class A>
0714 typename enable_if_c<
0715 is_mat<A>::value && (mat_traits<A>::rows==mat_traits<A>::cols || mat_traits<A>::rows+1==mat_traits<A>::cols) && mat_traits<A>::cols>=3,
0716 qvm_detail::translation_<A> const &>::type
0717 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0718 translation( A const & a )
0719 {
0720 return reinterpret_cast<typename qvm_detail::translation_<A> const &>(a);
0721 }
0722
0723 template <class A>
0724 typename enable_if_c<
0725 is_mat<A>::value && (mat_traits<A>::rows==mat_traits<A>::cols || mat_traits<A>::rows+1==mat_traits<A>::cols) && mat_traits<A>::cols>=3,
0726 qvm_detail::translation_<A> &>::type
0727 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0728 translation( A & a )
0729 {
0730 return reinterpret_cast<typename qvm_detail::translation_<A> &>(a);
0731 }
0732
0733 } }
0734
0735 #endif