1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539 |
- #ifndef BOOST_QVM_MAT_OPERATIONS_HPP_INCLUDED
- #define BOOST_QVM_MAT_OPERATIONS_HPP_INCLUDED
- // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
- // Copyright 2019 agate-pris
- // 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 <boost/qvm/detail/mat_assign.hpp>
- #include <boost/qvm/mat_operations2.hpp>
- #include <boost/qvm/mat_operations3.hpp>
- #include <boost/qvm/mat_operations4.hpp>
- #include <boost/qvm/math.hpp>
- #include <boost/qvm/detail/determinant_impl.hpp>
- #include <boost/qvm/detail/cofactor_impl.hpp>
- #include <boost/qvm/detail/transp_impl.hpp>
- #include <boost/qvm/scalar_traits.hpp>
- #include <boost/qvm/to_string.hpp>
- namespace boost { namespace qvm {
- namespace
- qvm_detail
- {
- BOOST_QVM_INLINE_CRITICAL
- void const *
- get_valid_ptr_mat_operations()
- {
- static int const obj=0;
- return &obj;
- }
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int R,int C>
- struct
- to_string_m_defined
- {
- static bool const value=false;
- };
- template <int I,int SizeMinusOne>
- struct
- to_string_matrix_elements
- {
- template <class A>
- static
- std::string
- f( A const & a )
- {
- using namespace qvm_to_string_detail;
- return
- ( (I%mat_traits<A>::cols)==0 ? '(' : ',' ) +
- to_string(mat_traits<A>::template read_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a)) +
- ( (I%mat_traits<A>::cols)==mat_traits<A>::cols-1 ? ")" : "" ) +
- to_string_matrix_elements<I+1,SizeMinusOne>::f(a);
- }
- };
- template <int SizeMinusOne>
- struct
- to_string_matrix_elements<SizeMinusOne,SizeMinusOne>
- {
- template <class A>
- static
- std::string
- f( A const & a )
- {
- using namespace qvm_to_string_detail;
- return
- ( (SizeMinusOne%mat_traits<A>::cols)==0 ? '(' : ',' ) +
- to_string(mat_traits<A>::template read_element<SizeMinusOne/mat_traits<A>::cols,SizeMinusOne%mat_traits<A>::cols>(a)) +
- ')';
- }
- };
- }
- template <class A>
- inline
- typename enable_if_c<
- is_mat<A>::value &&
- !qvm_detail::to_string_m_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- std::string>::type
- to_string( A const & a )
- {
- return "("+qvm_detail::to_string_matrix_elements<0,mat_traits<A>::rows*mat_traits<A>::cols-1>::f(a)+')';
- }
- ////////////////////////////////////////////////
- template <class A,class B,class Cmp>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols,
- bool>::type
- cmp( A const & a, B const & b, Cmp f )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- if( !f(
- mat_traits<A>::read_element_idx(i, j, a),
- mat_traits<B>::read_element_idx(i, j, b)) )
- return false;
- return true;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- convert_to_m_defined
- {
- static bool const value=false;
- };
- }
- template <class R,class A>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<R>::value && is_mat<A>::value &&
- mat_traits<R>::rows==mat_traits<A>::rows &&
- mat_traits<R>::cols==mat_traits<A>::cols &&
- !qvm_detail::convert_to_m_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- R>::type
- convert_to( A const & a )
- {
- R r; assign(r,a);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D>
- struct
- determinant_defined
- {
- static bool const value=false;
- };
- }
- template <class A>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- !qvm_detail::determinant_defined<mat_traits<A>::rows>::value,
- typename mat_traits<A>::scalar_type>::type
- determinant( A const & a )
- {
- return qvm_detail::determinant_impl(a);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T,int Dim>
- class
- identity_mat_
- {
- identity_mat_( identity_mat_ const & );
- identity_mat_ & operator=( identity_mat_ const & );
- ~identity_mat_();
- public:
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- }
- template <class T,int Dim>
- struct
- mat_traits< qvm_detail::identity_mat_<T,Dim> >
- {
- typedef qvm_detail::identity_mat_<T,Dim> this_matrix;
- typedef T scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & /*x*/ )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return scalar_traits<scalar_type>::value(Row==Col);
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & /*x*/ )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<Dim);
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <class T,int Dim>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::identity_mat_<T,Dim> const &
- identity_mat()
- {
- return *(qvm_detail::identity_mat_<T,Dim> const *)qvm_detail::get_valid_ptr_mat_operations();
- }
- template <class A>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_identity( A & a )
- {
- assign(a,identity_mat<typename mat_traits<A>::scalar_type,mat_traits<A>::rows>());
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T>
- struct
- projection_
- {
- T const _00;
- T const _11;
- T const _22;
- T const _23;
- T const _32;
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- projection_( T _00, T _11, T _22, T _23, T _32 ):
- _00(_00),
- _11(_11),
- _22(_22),
- _23(_23),
- _32(_32)
- {
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <int Row,int Col>
- struct
- projection_get
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( projection_<T> const & )
- {
- return scalar_traits<T>::value(0);
- }
- };
- template <> struct projection_get<0,0> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._00; } };
- template <> struct projection_get<1,1> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._11; } };
- template <> struct projection_get<2,2> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._22; } };
- template <> struct projection_get<2,3> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._23; } };
- template <> struct projection_get<3,2> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._32; } };
- }
- template <class T>
- struct
- mat_traits< qvm_detail::projection_<T> >
- {
- typedef qvm_detail::projection_<T> this_matrix;
- typedef T scalar_type;
- static int const rows=4;
- static int const cols=4;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return qvm_detail::projection_get<Row,Col>::get(x);
- }
- };
- template <class T>
- qvm_detail::projection_<T>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- perspective_lh( T fov_y, T aspect_ratio, T z_near, T z_far )
- {
- T const one = scalar_traits<T>::value(1);
- T const ys = one/tan(fov_y/scalar_traits<T>::value(2));
- T const xs = ys/aspect_ratio;
- T const zd = z_far-z_near;
- T const z1 = z_far/zd;
- T const z2 = -z_near*z1;
- return qvm_detail::projection_<T>(xs,ys,z1,z2,one);
- }
- template <class T>
- qvm_detail::projection_<T>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- perspective_rh( T fov_y, T aspect_ratio, T z_near, T z_far )
- {
- T const one = scalar_traits<T>::value(1);
- T const ys = one/tan(fov_y/scalar_traits<T>::value(2));
- T const xs = ys/aspect_ratio;
- T const zd = z_near-z_far;
- T const z1 = z_far/zd;
- T const z2 = z_near*z1;
- return qvm_detail::projection_<T>(xs,ys,z1,z2,-one);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class OriginalType,class Scalar>
- class
- matrix_scalar_cast_
- {
- matrix_scalar_cast_( matrix_scalar_cast_ const & );
- matrix_scalar_cast_ & operator=( matrix_scalar_cast_ const & );
- ~matrix_scalar_cast_();
- public:
- template <class T>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- matrix_scalar_cast_ &
- operator=( T const & x )
- {
- assign(*this,x);
- return *this;
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <bool> struct scalar_cast_matrix_filter { };
- template <> struct scalar_cast_matrix_filter<true> { typedef int type; };
- }
- template <class OriginalType,class Scalar>
- struct
- mat_traits< qvm_detail::matrix_scalar_cast_<OriginalType,Scalar> >
- {
- typedef Scalar scalar_type;
- typedef qvm_detail::matrix_scalar_cast_<OriginalType,Scalar> this_matrix;
- static int const rows=mat_traits<OriginalType>::rows;
- static int const cols=mat_traits<OriginalType>::cols;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return scalar_type(mat_traits<OriginalType>::template read_element<Row,Col>(reinterpret_cast<OriginalType const &>(x)));
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return scalar_type(mat_traits<OriginalType>::read_element_idx(col,row,reinterpret_cast<OriginalType const &>(x)));
- }
- };
- template <class OriginalType,class Scalar,int R,int C>
- struct
- deduce_mat<qvm_detail::matrix_scalar_cast_<OriginalType,Scalar>,R,C>
- {
- typedef mat<Scalar,R,C> type;
- };
- template <class Scalar,class T>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::matrix_scalar_cast_<T,Scalar> const &
- scalar_cast( T const & x, typename qvm_detail::scalar_cast_matrix_filter<is_mat<T>::value>::type=0 )
- {
- return reinterpret_cast<qvm_detail::matrix_scalar_cast_<T,Scalar> const &>(x);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- div_eq_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::div_eq_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator/=( A & a, B b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,a,mat_traits<A>::read_element_idx(i,j,a)/b);
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- div_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::div_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator/( A const & a, B b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,r,mat_traits<A>::read_element_idx(i,j,a)/b);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::eq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- bool>::type
- operator==( A const & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- if( mat_traits<A>::read_element_idx(i,j,a)!=mat_traits<B>::read_element_idx(i,j,b) )
- return false;
- return true;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- minus_eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::minus_eq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator-=( A & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,a,mat_traits<A>::read_element_idx(i,j,a)-mat_traits<B>::read_element_idx(i,j,b));
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- minus_m_defined
- {
- static bool const value=false;
- };
- }
- template <class A>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value &&
- !qvm_detail::minus_m_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat<A> >::type
- operator-( A const & a )
- {
- typedef typename deduce_mat<A>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,r,-mat_traits<A>::read_element_idx(i,j,a));
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- minus_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::minus_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator-( A const & a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,r,mat_traits<A>::read_element_idx(i,j,a)-mat_traits<B>::read_element_idx(i,j,b));
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D>
- struct
- mul_eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::mul_eq_mm_defined<mat_traits<A>::rows>::value,
- A &>::type
- operator*=( A & r, B const & b )
- {
- typedef typename mat_traits<A>::scalar_type Ta;
- Ta a[mat_traits<A>::rows][mat_traits<A>::cols];
- for( int i=0; i<mat_traits<A>::rows; ++i )
- for( int j=0; j<mat_traits<B>::cols; ++j )
- a[i][j]=mat_traits<A>::read_element_idx(i,j,r);
- for( int i=0; i<mat_traits<A>::rows; ++i )
- for( int j=0; j<mat_traits<B>::cols; ++j )
- {
- Ta x(scalar_traits<Ta>::value(0));
- for( int k=0; k<mat_traits<A>::cols; ++k )
- x += a[i][k]*mat_traits<B>::read_element_idx(k,j,b);
- write_mat_element_idx(i,j,r,x);
- }
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- mul_eq_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::mul_eq_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator*=( A & a, B b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,a,mat_traits<A>::read_element_idx(i,j,a)*b);
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int R,int /*CR*/,int C>
- struct
- mul_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::cols==mat_traits<B>::rows &&
- !qvm_detail::mul_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols,mat_traits<B>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<B>::cols> >::type
- operator*( A const & a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<B>::cols>::type R;
- R r;
- for( int i=0; i<mat_traits<A>::rows; ++i )
- for( int j=0; j<mat_traits<B>::cols; ++j )
- {
- typedef typename mat_traits<A>::scalar_type Ta;
- Ta x(scalar_traits<Ta>::value(0));
- for( int k=0; k<mat_traits<A>::cols; ++k )
- x += mat_traits<A>::read_element_idx(i,k,a)*mat_traits<B>::read_element_idx(k,j,b);
- write_mat_element_idx(i,j,r,x);
- }
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- mul_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::mul_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator*( A const & a, B b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,r,mat_traits<A>::read_element_idx(i,j,a)*b);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- mul_sm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_scalar<A>::value && is_mat<B>::value &&
- !qvm_detail::mul_sm_defined<mat_traits<B>::rows,mat_traits<B>::cols>::value,
- deduce_mat2<A,B,mat_traits<B>::rows,mat_traits<B>::cols> >::type
- operator*( A a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<B>::rows,mat_traits<B>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<B>::rows; ++i )
- for( int j=0; j!=mat_traits<B>::cols; ++j )
- write_mat_element_idx(i,j,r,a*mat_traits<B>::read_element_idx(i,j,b));
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- neq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::neq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- bool>::type
- operator!=( A const & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- if( mat_traits<A>::read_element_idx(i,j,a)!=mat_traits<B>::read_element_idx(i,j,b) )
- return true;
- return false;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- plus_eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::plus_eq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator+=( A & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,a,mat_traits<A>::read_element_idx(i,j,a)+mat_traits<B>::read_element_idx(i,j,b));
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- plus_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::plus_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator+( A const & a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- write_mat_element_idx(i,j,r,mat_traits<A>::read_element_idx(i,j,a)+mat_traits<B>::read_element_idx(i,j,b));
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T>
- class
- mref_
- {
- mref_( mref_ const & );
- mref_ & operator=( mref_ const & );
- ~mref_();
- public:
- template <class R>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- mref_ &
- operator=( R const & x )
- {
- assign(*this,x);
- return *this;
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <class M,bool WriteElementRef=mat_write_element_ref<M>::value>
- struct mref_write_traits;
- template <class M>
- struct
- mref_write_traits<M,true>
- {
- typedef typename mat_traits<M>::scalar_type scalar_type;
- typedef qvm_detail::mref_<M> this_matrix;
- static int const rows=mat_traits<M>::rows;
- static int const cols=mat_traits<M>::cols;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type &
- write_element( this_matrix & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return mat_traits<M>::template write_element<Row,Col>(reinterpret_cast<M &>(x));
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type &
- write_element_idx( int row, int col, this_matrix & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return mat_traits<M>::write_element_idx(row,col,reinterpret_cast<M &>(x));
- }
- };
- template <class M>
- struct
- mref_write_traits<M,false>
- {
- typedef typename mat_traits<M>::scalar_type scalar_type;
- typedef qvm_detail::mref_<M> this_matrix;
- static int const rows=mat_traits<M>::rows;
- static int const cols=mat_traits<M>::cols;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- void
- write_element( this_matrix & x, scalar_type s )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- mat_traits<M>::template write_element<Row,Col>(reinterpret_cast<M &>(x), s);
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- void
- write_element_idx( int row, int col, this_matrix & x, scalar_type s )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- mat_traits<M>::write_element_idx(row,col,reinterpret_cast<M &>(x), s);
- }
- };
- }
- template <class M>
- struct
- mat_traits< qvm_detail::mref_<M> >:
- qvm_detail::mref_write_traits<M>
- {
- typedef typename mat_traits<M>::scalar_type scalar_type;
- typedef qvm_detail::mref_<M> this_matrix;
- static int const rows=mat_traits<M>::rows;
- static int const cols=mat_traits<M>::cols;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return mat_traits<M>::template read_element<Row,Col>(reinterpret_cast<M const &>(x));
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return mat_traits<M>::read_element_idx(row,col,reinterpret_cast<M const &>(x));
- }
- };
- template <class M,int R,int C>
- struct
- deduce_mat<qvm_detail::mref_<M>,R,C>
- {
- typedef mat<typename mat_traits<M>::scalar_type,R,C> type;
- };
- template <class M>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<M>::value,
- qvm_detail::mref_<M> const &>::type
- mref( M const & a )
- {
- return reinterpret_cast<qvm_detail::mref_<M> const &>(a);
- }
- template <class M>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<M>::value,
- qvm_detail::mref_<M> &>::type
- mref( M & a )
- {
- return reinterpret_cast<qvm_detail::mref_<M> &>(a);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T,int Rows,int Cols>
- class
- zero_mat_
- {
- zero_mat_( zero_mat_ const & );
- zero_mat_ & operator=( zero_mat_ const & );
- ~zero_mat_();
- public:
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- }
- template <class T,int Rows,int Cols>
- struct
- mat_traits< qvm_detail::zero_mat_<T,Rows,Cols> >
- {
- typedef qvm_detail::zero_mat_<T,Rows,Cols> this_matrix;
- typedef T scalar_type;
- static int const rows=Rows;
- static int const cols=Cols;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return scalar_traits<scalar_type>::value(0);
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return scalar_traits<scalar_type>::value(0);
- }
- };
- template <class T,int Rows,int Cols,int R,int C>
- struct
- deduce_mat<qvm_detail::zero_mat_<T,Rows,Cols>,R,C>
- {
- typedef mat<T,R,C> type;
- };
- template <class T,int Rows,int Cols>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::zero_mat_<T,Rows,Cols> const &
- zero_mat()
- {
- return *(qvm_detail::zero_mat_<T,Rows,Cols> const *)qvm_detail::get_valid_ptr_mat_operations();
- }
- template <class T,int Dim>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::zero_mat_<T,Dim,Dim> const &
- zero_mat()
- {
- return *(qvm_detail::zero_mat_<T,Dim,Dim> const *)qvm_detail::get_valid_ptr_mat_operations();
- }
- template <class A>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value,
- void>::type
- set_zero( A & a )
- {
- assign(a,zero_mat<typename mat_traits<A>::scalar_type,mat_traits<A>::rows,mat_traits<A>::cols>());
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D,class S>
- struct
- rot_mat_
- {
- typedef S scalar_type;
- scalar_type a[3][3];
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- rot_mat_(
- scalar_type a00, scalar_type a01, scalar_type a02,
- scalar_type a10, scalar_type a11, scalar_type a12,
- scalar_type a20, scalar_type a21, scalar_type a22 )
- {
- a[0][0] = a00;
- a[0][1] = a01;
- a[0][2] = a02;
- a[1][0] = a10;
- a[1][1] = a11;
- a[1][2] = a12;
- a[2][0] = a20;
- a[2][1] = a21;
- a[2][2] = a22;
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <int Row,int Col>
- struct
- rot_m_get
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const (&)[3][3] )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <> struct rot_m_get<0,0> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[0][0]; } };
- template <> struct rot_m_get<0,1> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[0][1]; } };
- template <> struct rot_m_get<0,2> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[0][2]; } };
- template <> struct rot_m_get<1,0> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[1][0]; } };
- template <> struct rot_m_get<1,1> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[1][1]; } };
- template <> struct rot_m_get<1,2> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[1][2]; } };
- template <> struct rot_m_get<2,0> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[2][0]; } };
- template <> struct rot_m_get<2,1> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[2][1]; } };
- template <> struct rot_m_get<2,2> { template <class T> static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[2][2]; } };
- }
- template <class M>
- struct mat_traits;
- template <int D,class S>
- struct
- mat_traits< qvm_detail::rot_mat_<D,S> >
- {
- typedef qvm_detail::rot_mat_<D,S> this_matrix;
- typedef typename this_matrix::scalar_type scalar_type;
- static int const rows=D;
- static int const cols=D;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<D);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<D);
- return qvm_detail::rot_m_get<Row,Col>::get(x.a);
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<D);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<D);
- return row<3 && col<3?
- x.a[row][col] :
- scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class V,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- typename enable_if_c<
- is_vec<V>::value && vec_traits<V>::dim==3,
- qvm_detail::rot_mat_<Dim,Angle> >::type
- rot_mat( V const & axis, Angle angle )
- {
- typedef Angle scalar_type;
- scalar_type const x=vec_traits<V>::template read_element<0>(axis);
- scalar_type const y=vec_traits<V>::template read_element<1>(axis);
- scalar_type const z=vec_traits<V>::template read_element<2>(axis);
- scalar_type const m2=x*x+y*y+z*z;
- if( m2==scalar_traits<scalar_type>::value(0) )
- BOOST_QVM_THROW_EXCEPTION(zero_magnitude_error());
- scalar_type const s = sin(angle);
- scalar_type const c = cos(angle);
- scalar_type const x2 = x*x;
- scalar_type const y2 = y*y;
- scalar_type const z2 = z*z;
- scalar_type const xy = x*y;
- scalar_type const xz = x*z;
- scalar_type const yz = y*z;
- scalar_type const xs = x*s;
- scalar_type const ys = y*s;
- scalar_type const zs = z*s;
- scalar_type const one = scalar_traits<scalar_type>::value(1);
- scalar_type const c1 = one-c;
- return qvm_detail::rot_mat_<Dim,Angle>(
- x2+(one-x2)*c, xy*c1-zs, xz*(one-c)+ys,
- xy*c1+zs, y2+(one-y2)*c, yz*c1-xs,
- xz*c1-ys, yz*c1+xs, z2+(one-z2)*c );
- }
- template <class A,class B,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3 &&
- is_vec<B>::value && vec_traits<B>::dim==3,
- void>::type
- set_rot( A & a, B const & axis, Angle angle )
- {
- assign(a,rot_mat<mat_traits<A>::rows>(axis,angle));
- }
- template <class A,class B,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3 &&
- is_vec<B>::value && vec_traits<B>::dim==3,
- void>::type
- rotate( A & a, B const & axis, Angle angle )
- {
- a *= rot_mat<mat_traits<A>::rows>(axis,angle);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xzy( Angle x1, Angle z2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(x1);
- scalar_type const s1 = sin(x1);
- scalar_type const c2 = cos(z2);
- scalar_type const s2 = sin(z2);
- scalar_type const c3 = cos(y3);
- scalar_type const s3 = sin(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2*c3, -s2, c2*s3,
- s1*s3 + c1*c3*s2, c1*c2, c1*s2*s3 - c3*s1,
- c3*s1*s2 - c1*s3, c2*s1, c1*c3 + s1*s2*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xzy( A & a, Angle x1, Angle z2, Angle y3 )
- {
- assign(a,rot_mat_xzy<mat_traits<A>::rows>(x1,z2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xzy( A & a, Angle x1, Angle z2, Angle y3 )
- {
- a *= rot_mat_xzy<mat_traits<A>::rows>(x1,z2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xyz( Angle x1, Angle y2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(x1);
- scalar_type const s1 = sin(x1);
- scalar_type const c2 = cos(y2);
- scalar_type const s2 = sin(y2);
- scalar_type const c3 = cos(z3);
- scalar_type const s3 = sin(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2*c3, -c2*s3, s2,
- c1*s3 + c3*s1*s2, c1*c3 - s1*s2*s3, -c2*s1,
- s1*s3 - c1*c3*s2, c3*s1 + c1*s2*s3, c1*c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xyz( A & a, Angle x1, Angle y2, Angle z3 )
- {
- assign(a,rot_mat_xyz<mat_traits<A>::rows>(x1,y2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xyz( A & a, Angle x1, Angle y2, Angle z3 )
- {
- a *= rot_mat_xyz<mat_traits<A>::rows>(x1,y2,z3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yxz( Angle y1, Angle x2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(y1);
- scalar_type const s1 = sin(y1);
- scalar_type const c2 = cos(x2);
- scalar_type const s2 = sin(x2);
- scalar_type const c3 = cos(z3);
- scalar_type const s3 = sin(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 + s1*s2*s3, c3*s1*s2 - c1*s3, c2*s1,
- c2*s3, c2*c3, -s2,
- c1*s2*s3 - c3*s1, c1*c3*s2 + s1*s3, c1*c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yxz( A & a, Angle y1, Angle x2, Angle z3 )
- {
- assign(a,rot_mat_yxz<mat_traits<A>::rows>(y1,x2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yxz( A & a, Angle y1, Angle x2, Angle z3 )
- {
- a *= rot_mat_yxz<mat_traits<A>::rows>(y1,x2,z3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yzx( Angle y1, Angle z2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(y1);
- scalar_type const s1 = sin(y1);
- scalar_type const c2 = cos(z2);
- scalar_type const s2 = sin(z2);
- scalar_type const c3 = cos(x3);
- scalar_type const s3 = sin(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2, s1*s3 - c1*c3*s2, c3*s1 + c1*s2*s3,
- s2, c2*c3, -c2*s3,
- -c2*s1, c1*s3 + c3*s1*s2, c1*c3 - s1*s2*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yzx( A & a, Angle y1, Angle z2, Angle x3 )
- {
- assign(a,rot_mat_yzx<mat_traits<A>::rows>(y1,z2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yzx( A & a, Angle y1, Angle z2, Angle x3 )
- {
- a *= rot_mat_yzx<mat_traits<A>::rows>(y1,z2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zyx( Angle z1, Angle y2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(z1);
- scalar_type const s1 = sin(z1);
- scalar_type const c2 = cos(y2);
- scalar_type const s2 = sin(y2);
- scalar_type const c3 = cos(x3);
- scalar_type const s3 = sin(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2, c1*s2*s3 - c3*s1, s1*s3 + c1*c3*s2,
- c2*s1, c1*c3 + s1*s2*s3, c3*s1*s2 - c1*s3,
- -s2, c2*s3, c2*c3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zyx( A & a, Angle z1, Angle y2, Angle x3 )
- {
- assign(a,rot_mat_zyx<mat_traits<A>::rows>(z1,y2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zyx( A & a, Angle z1, Angle y2, Angle x3 )
- {
- a *= rot_mat_zyx<mat_traits<A>::rows>(z1,y2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zxy( Angle z1, Angle x2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(z1);
- scalar_type const s1 = sin(z1);
- scalar_type const c2 = cos(x2);
- scalar_type const s2 = sin(x2);
- scalar_type const c3 = cos(y3);
- scalar_type const s3 = sin(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 - s1*s2*s3, -c2*s1, c1*s3 + c3*s1*s2,
- c3*s1 + c1*s2*s3, c1*c2, s1*s3 - c1*c3*s2,
- -c2*s3, s2, c2*c3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zxy( A & a, Angle z1, Angle x2, Angle y3 )
- {
- assign(a,rot_mat_zxy<mat_traits<A>::rows>(z1,x2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zxy( A & a, Angle z1, Angle x2, Angle y3 )
- {
- a *= rot_mat_zxy<mat_traits<A>::rows>(z1,x2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xzx( Angle x1, Angle z2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(x1);
- scalar_type const s1 = sin(x1);
- scalar_type const c2 = cos(z2);
- scalar_type const s2 = sin(z2);
- scalar_type const c3 = cos(x3);
- scalar_type const s3 = sin(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2, -c3*s2, s2*s3,
- c1*s2, c1*c2*c3 - s1*s3, -c3*s1 - c1*c2*s3,
- s1*s2, c1*s3 + c2*c3*s1, c1*c3 - c2*s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xzx( A & a, Angle x1, Angle z2, Angle x3 )
- {
- assign(a,rot_mat_xzx<mat_traits<A>::rows>(x1,z2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xzx( A & a, Angle x1, Angle z2, Angle x3 )
- {
- a *= rot_mat_xzx<mat_traits<A>::rows>(x1,z2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xyx( Angle x1, Angle y2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(x1);
- scalar_type const s1 = sin(x1);
- scalar_type const c2 = cos(y2);
- scalar_type const s2 = sin(y2);
- scalar_type const c3 = cos(x3);
- scalar_type const s3 = sin(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2, s2*s3, c3*s2,
- s1*s2, c1*c3 - c2*s1*s3, -c1*s3 - c2*c3*s1,
- -c1*s2, c3*s1 + c1*c2*s3, c1*c2*c3 - s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xyx( A & a, Angle x1, Angle y2, Angle x3 )
- {
- assign(a,rot_mat_xyx<mat_traits<A>::rows>(x1,y2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xyx( A & a, Angle x1, Angle y2, Angle x3 )
- {
- a *= rot_mat_xyx<mat_traits<A>::rows>(x1,y2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yxy( Angle y1, Angle x2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(y1);
- scalar_type const s1 = sin(y1);
- scalar_type const c2 = cos(x2);
- scalar_type const s2 = sin(x2);
- scalar_type const c3 = cos(y3);
- scalar_type const s3 = sin(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 - c2*s1*s3, s1*s2, c1*s3 + c2*c3*s1,
- s2*s3, c2, -c3*s2,
- -c3*s1 - c1*c2*s3, c1*s2, c1*c2*c3 - s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yxy( A & a, Angle y1, Angle x2, Angle y3 )
- {
- assign(a,rot_mat_yxy<mat_traits<A>::rows>(y1,x2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yxy( A & a, Angle y1, Angle x2, Angle y3 )
- {
- a *= rot_mat_yxy<mat_traits<A>::rows>(y1,x2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yzy( Angle y1, Angle z2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(y1);
- scalar_type const s1 = sin(y1);
- scalar_type const c2 = cos(z2);
- scalar_type const s2 = sin(z2);
- scalar_type const c3 = cos(y3);
- scalar_type const s3 = sin(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2*c3 - s1*s3, -c1*s2, c3*s1 + c1*c2*s3,
- c3*s2, c2, s2*s3,
- -c1*s3 - c2*c3*s1, s1*s2, c1*c3 - c2*s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yzy( A & a, Angle y1, Angle z2, Angle y3 )
- {
- assign(a,rot_mat_yzy<mat_traits<A>::rows>(y1,z2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yzy( A & a, Angle y1, Angle z2, Angle y3 )
- {
- a *= rot_mat_yzy<mat_traits<A>::rows>(y1,z2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zyz( Angle z1, Angle y2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(z1);
- scalar_type const s1 = sin(z1);
- scalar_type const c2 = cos(y2);
- scalar_type const s2 = sin(y2);
- scalar_type const c3 = cos(z3);
- scalar_type const s3 = sin(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2*c3 - s1*s3, -c3*s1 - c1*c2*s3, c1*s2,
- c1*s3 + c2*c3*s1, c1*c3 - c2*s1*s3, s1*s2,
- -c3*s2, s2*s3, c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zyz( A & a, Angle z1, Angle y2, Angle z3 )
- {
- assign(a,rot_mat_zyz<mat_traits<A>::rows>(z1,y2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zyz( A & a, Angle z1, Angle y2, Angle z3 )
- {
- a *= rot_mat_zyz<mat_traits<A>::rows>(z1,y2,z3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zxz( Angle z1, Angle x2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos(z1);
- scalar_type const s1 = sin(z1);
- scalar_type const c2 = cos(x2);
- scalar_type const s2 = sin(x2);
- scalar_type const c3 = cos(z3);
- scalar_type const s3 = sin(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 - c2*s1*s3, -c1*s3 - c2*c3*s1, s1*s2,
- c3*s1 + c1*c2*s3, c1*c2*c3 - s1*s3, -c1*s2,
- s2*s3, c3*s2, c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zxz( A & a, Angle z1, Angle x2, Angle z3 )
- {
- assign(a,rot_mat_zxz<mat_traits<A>::rows>(z1,x2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zxz( A & a, Angle z1, Angle x2, Angle z3 )
- {
- a *= rot_mat_zxz<mat_traits<A>::rows>(z1,x2,z3);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int Dim,class Angle>
- struct
- rotx_mat_
- {
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- rotx_mat_()
- {
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- private:
- rotx_mat_( rotx_mat_ const & );
- rotx_mat_ & operator=( rotx_mat_ const & );
- ~rotx_mat_();
- };
- template <int Row,int Col>
- struct
- rotx_m_get
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <>
- struct
- rotx_m_get<1,1>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos(angle);
- }
- };
- template <>
- struct
- rotx_m_get<1,2>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return -sin(angle);
- }
- };
- template <>
- struct
- rotx_m_get<2,1>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return sin(angle);
- }
- };
- template <>
- struct
- rotx_m_get<2,2>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos(angle);
- }
- };
- }
- template <int Dim,class Angle>
- struct
- mat_traits< qvm_detail::rotx_mat_<Dim,Angle> >
- {
- typedef qvm_detail::rotx_mat_<Dim,Angle> this_matrix;
- typedef Angle scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return qvm_detail::rotx_m_get<Row,Col>::get(reinterpret_cast<Angle const &>(x));
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col<Dim);
- Angle const & a=reinterpret_cast<Angle const &>(x);
- if( row==1 )
- {
- if( col==1 )
- return cos(a);
- if( col==2 )
- return -sin(a);
- }
- if( row==2 )
- {
- if( col==1 )
- return sin(a);
- if( col==2 )
- return cos(a);
- }
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class Angle>
- struct
- deduce_mat<qvm_detail::rotx_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- struct
- deduce_mat2<qvm_detail::rotx_mat_<Dim,Angle>,qvm_detail::rotx_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::rotx_mat_<Dim,Angle> const &
- rotx_mat( Angle const & angle )
- {
- BOOST_QVM_STATIC_ASSERT(Dim>=3);
- return reinterpret_cast<qvm_detail::rotx_mat_<Dim,Angle> const &>(angle);
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=3 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_rotx( A & a, Angle angle )
- {
- assign(a,rotx_mat<mat_traits<A>::rows>(angle));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=3 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- rotate_x( A & a, Angle angle )
- {
- a *= rotx_mat<mat_traits<A>::rows>(angle);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int Dim,class Angle>
- struct
- roty_mat_
- {
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- roty_mat_()
- {
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- private:
- roty_mat_( roty_mat_ const & );
- roty_mat_ & operator=( roty_mat_ const & );
- ~roty_mat_();
- };
- template <int Row,int Col>
- struct
- roty_m_get
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <>
- struct
- roty_m_get<0,0>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos(angle);
- }
- };
- template <>
- struct
- roty_m_get<0,2>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return sin(angle);
- }
- };
- template <>
- struct
- roty_m_get<2,0>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return -sin(angle);
- }
- };
- template <>
- struct
- roty_m_get<2,2>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos(angle);
- }
- };
- }
- template <int Dim,class Angle>
- struct
- mat_traits< qvm_detail::roty_mat_<Dim,Angle> >
- {
- typedef qvm_detail::roty_mat_<Dim,Angle> this_matrix;
- typedef Angle scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return qvm_detail::roty_m_get<Row,Col>::get(reinterpret_cast<Angle const &>(x));
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col<Dim);
- Angle const & a=reinterpret_cast<Angle const &>(x);
- if( row==0 )
- {
- if( col==0 )
- return cos(a);
- if( col==2 )
- return sin(a);
- }
- if( row==2 )
- {
- if( col==0 )
- return -sin(a);
- if( col==2 )
- return cos(a);
- }
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class Angle>
- struct
- deduce_mat<qvm_detail::roty_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- struct
- deduce_mat2<qvm_detail::roty_mat_<Dim,Angle>,qvm_detail::roty_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::roty_mat_<Dim,Angle> const &
- roty_mat( Angle const & angle )
- {
- BOOST_QVM_STATIC_ASSERT(Dim>=3);
- return reinterpret_cast<qvm_detail::roty_mat_<Dim,Angle> const &>(angle);
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=2 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_roty( A & a, Angle angle )
- {
- assign(a,roty_mat<mat_traits<A>::rows>(angle));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=3 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- rotate_y( A & a, Angle angle )
- {
- a *= roty_mat<mat_traits<A>::rows>(angle);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int Dim,class Angle>
- struct
- rotz_mat_
- {
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- rotz_mat_()
- {
- }
- template <class R
- #if __cplusplus >= 201103L
- , class = typename enable_if<is_mat<R> >::type
- #endif
- >
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- private:
- rotz_mat_( rotz_mat_ const & );
- rotz_mat_ & operator=( rotz_mat_ const & );
- ~rotz_mat_();
- };
- template <int Row,int Col>
- struct
- rotz_m_get
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <>
- struct
- rotz_m_get<0,0>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos(angle);
- }
- };
- template <>
- struct
- rotz_m_get<0,1>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return -sin(angle);
- }
- };
- template <>
- struct
- rotz_m_get<1,0>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return sin(angle);
- }
- };
- template <>
- struct
- rotz_m_get<1,1>
- {
- template <class T>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos(angle);
- }
- };
- }
- template <int Dim,class Angle>
- struct
- mat_traits< qvm_detail::rotz_mat_<Dim,Angle> >
- {
- typedef qvm_detail::rotz_mat_<Dim,Angle> this_matrix;
- typedef Angle scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return qvm_detail::rotz_m_get<Row,Col>::get(reinterpret_cast<Angle const &>(x));
- }
- static
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col<Dim);
- Angle const & a=reinterpret_cast<Angle const &>(x);
- if( row==0 )
- {
- if( col==0 )
- return cos(a);
- if( col==1 )
- return -sin(a);
- }
- if( row==1 )
- {
- if( col==0 )
- return sin(a);
- if( col==1 )
- return cos(a);
- }
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class Angle>
- struct
- deduce_mat<qvm_detail::rotz_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle,int R,int C>
- struct
- deduce_mat2<qvm_detail::rotz_mat_<Dim,Angle>,qvm_detail::rotz_mat_<Dim,Angle>,R,C>
- {
- typedef mat<Angle,R,C> type;
- };
- template <int Dim,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::rotz_mat_<Dim,Angle> const &
- rotz_mat( Angle const & angle )
- {
- BOOST_QVM_STATIC_ASSERT(Dim>=2);
- return reinterpret_cast<qvm_detail::rotz_mat_<Dim,Angle> const &>(angle);
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=2 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_rotz( A & a, Angle angle )
- {
- assign(a,rotz_mat<mat_traits<A>::rows>(angle));
- }
- template <class A,class Angle>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=2 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- rotate_z( A & a, Angle angle )
- {
- a *= rotz_mat<mat_traits<A>::rows>(angle);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D>
- struct
- inverse_m_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- typename lazy_enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- !qvm_detail::inverse_m_defined<mat_traits<A>::rows>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- inverse( A const & a, B det )
- {
- typedef typename mat_traits<A>::scalar_type T;
- BOOST_QVM_ASSERT(det!=scalar_traits<T>::value(0));
- T f=scalar_traits<T>::value(1)/det;
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type cofactor_return_type;
- cofactor_return_type c=qvm_detail::cofactor_impl(a);
- return reinterpret_cast<qvm_detail::transposed_<cofactor_return_type> const &>(c) * f;
- }
- template <class A>
- BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
- typename lazy_enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- !qvm_detail::inverse_m_defined<mat_traits<A>::rows>::value,
- deduce_mat<A> >::type
- inverse( A const & a )
- {
- typedef typename mat_traits<A>::scalar_type T;
- T det=determinant(a);
- if( det==scalar_traits<T>::value(0) )
- BOOST_QVM_THROW_EXCEPTION(zero_determinant_error());
- return inverse(a,det);
- }
- ////////////////////////////////////////////////
- namespace
- sfinae
- {
- using ::boost::qvm::to_string;
- using ::boost::qvm::assign;
- using ::boost::qvm::determinant;
- using ::boost::qvm::cmp;
- using ::boost::qvm::convert_to;
- using ::boost::qvm::set_identity;
- using ::boost::qvm::set_zero;
- using ::boost::qvm::scalar_cast;
- using ::boost::qvm::operator/=;
- using ::boost::qvm::operator/;
- using ::boost::qvm::operator==;
- using ::boost::qvm::operator-=;
- using ::boost::qvm::operator-;
- using ::boost::qvm::operator*=;
- using ::boost::qvm::operator*;
- using ::boost::qvm::operator!=;
- using ::boost::qvm::operator+=;
- using ::boost::qvm::operator+;
- using ::boost::qvm::mref;
- using ::boost::qvm::rot_mat;
- using ::boost::qvm::set_rot;
- using ::boost::qvm::rotate;
- using ::boost::qvm::set_rotx;
- using ::boost::qvm::rotate_x;
- using ::boost::qvm::set_roty;
- using ::boost::qvm::rotate_y;
- using ::boost::qvm::set_rotz;
- using ::boost::qvm::rotate_z;
- using ::boost::qvm::inverse;
- }
- } }
- #endif
|