mat_operations2.hpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. //Copyright (c) 2008-2017 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_QVM_2923BE84E16CD6AE529049F1F1BBE9EB
  5. #define BOOST_QVM_2923BE84E16CD6AE529049F1F1BBE9EB
  6. //This file was generated by a program. Do not edit manually.
  7. #include <boost/qvm/assert.hpp>
  8. #include <boost/qvm/deduce_mat.hpp>
  9. #include <boost/qvm/deduce_vec.hpp>
  10. #include <boost/qvm/error.hpp>
  11. #include <boost/qvm/gen/mat_assign2.hpp>
  12. #include <boost/qvm/throw_exception.hpp>
  13. namespace
  14. boost
  15. {
  16. namespace
  17. qvm
  18. {
  19. template <class A,class B>
  20. BOOST_QVM_INLINE_OPERATIONS
  21. typename lazy_enable_if_c<
  22. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  23. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  24. deduce_mat2<A,B,2,2> >::type
  25. operator+( A const & a, B const & b )
  26. {
  27. typedef typename deduce_mat2<A,B,2,2>::type R;
  28. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==2);
  29. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==2);
  30. R r;
  31. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)+mat_traits<B>::template read_element<0,0>(b);
  32. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)+mat_traits<B>::template read_element<0,1>(b);
  33. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)+mat_traits<B>::template read_element<1,0>(b);
  34. mat_traits<R>::template write_element<1,1>(r)=mat_traits<A>::template read_element<1,1>(a)+mat_traits<B>::template read_element<1,1>(b);
  35. return r;
  36. }
  37. namespace
  38. sfinae
  39. {
  40. using ::boost::qvm::operator+;
  41. }
  42. namespace
  43. qvm_detail
  44. {
  45. template <int R,int C>
  46. struct plus_mm_defined;
  47. template <>
  48. struct
  49. plus_mm_defined<2,2>
  50. {
  51. static bool const value=true;
  52. };
  53. }
  54. template <class A,class B>
  55. BOOST_QVM_INLINE_OPERATIONS
  56. typename lazy_enable_if_c<
  57. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  58. mat_traits<A>::cols==1 && mat_traits<B>::cols==1,
  59. deduce_mat2<A,B,2,1> >::type
  60. operator+( A const & a, B const & b )
  61. {
  62. typedef typename deduce_mat2<A,B,2,1>::type R;
  63. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==2);
  64. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==1);
  65. R r;
  66. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)+mat_traits<B>::template read_element<0,0>(b);
  67. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)+mat_traits<B>::template read_element<1,0>(b);
  68. return r;
  69. }
  70. namespace
  71. sfinae
  72. {
  73. using ::boost::qvm::operator+;
  74. }
  75. namespace
  76. qvm_detail
  77. {
  78. template <int R,int C>
  79. struct plus_mm_defined;
  80. template <>
  81. struct
  82. plus_mm_defined<2,1>
  83. {
  84. static bool const value=true;
  85. };
  86. }
  87. template <class A,class B>
  88. BOOST_QVM_INLINE_OPERATIONS
  89. typename lazy_enable_if_c<
  90. mat_traits<A>::rows==1 && mat_traits<B>::rows==1 &&
  91. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  92. deduce_mat2<A,B,1,2> >::type
  93. operator+( A const & a, B const & b )
  94. {
  95. typedef typename deduce_mat2<A,B,1,2>::type R;
  96. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==1);
  97. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==2);
  98. R r;
  99. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)+mat_traits<B>::template read_element<0,0>(b);
  100. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)+mat_traits<B>::template read_element<0,1>(b);
  101. return r;
  102. }
  103. namespace
  104. sfinae
  105. {
  106. using ::boost::qvm::operator+;
  107. }
  108. namespace
  109. qvm_detail
  110. {
  111. template <int R,int C>
  112. struct plus_mm_defined;
  113. template <>
  114. struct
  115. plus_mm_defined<1,2>
  116. {
  117. static bool const value=true;
  118. };
  119. }
  120. template <class A,class B>
  121. BOOST_QVM_INLINE_OPERATIONS
  122. typename lazy_enable_if_c<
  123. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  124. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  125. deduce_mat2<A,B,2,2> >::type
  126. operator-( A const & a, B const & b )
  127. {
  128. typedef typename deduce_mat2<A,B,2,2>::type R;
  129. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==2);
  130. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==2);
  131. R r;
  132. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)-mat_traits<B>::template read_element<0,0>(b);
  133. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)-mat_traits<B>::template read_element<0,1>(b);
  134. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)-mat_traits<B>::template read_element<1,0>(b);
  135. mat_traits<R>::template write_element<1,1>(r)=mat_traits<A>::template read_element<1,1>(a)-mat_traits<B>::template read_element<1,1>(b);
  136. return r;
  137. }
  138. namespace
  139. sfinae
  140. {
  141. using ::boost::qvm::operator-;
  142. }
  143. namespace
  144. qvm_detail
  145. {
  146. template <int R,int C>
  147. struct minus_mm_defined;
  148. template <>
  149. struct
  150. minus_mm_defined<2,2>
  151. {
  152. static bool const value=true;
  153. };
  154. }
  155. template <class A,class B>
  156. BOOST_QVM_INLINE_OPERATIONS
  157. typename lazy_enable_if_c<
  158. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  159. mat_traits<A>::cols==1 && mat_traits<B>::cols==1,
  160. deduce_mat2<A,B,2,1> >::type
  161. operator-( A const & a, B const & b )
  162. {
  163. typedef typename deduce_mat2<A,B,2,1>::type R;
  164. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==2);
  165. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==1);
  166. R r;
  167. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)-mat_traits<B>::template read_element<0,0>(b);
  168. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)-mat_traits<B>::template read_element<1,0>(b);
  169. return r;
  170. }
  171. namespace
  172. sfinae
  173. {
  174. using ::boost::qvm::operator-;
  175. }
  176. namespace
  177. qvm_detail
  178. {
  179. template <int R,int C>
  180. struct minus_mm_defined;
  181. template <>
  182. struct
  183. minus_mm_defined<2,1>
  184. {
  185. static bool const value=true;
  186. };
  187. }
  188. template <class A,class B>
  189. BOOST_QVM_INLINE_OPERATIONS
  190. typename lazy_enable_if_c<
  191. mat_traits<A>::rows==1 && mat_traits<B>::rows==1 &&
  192. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  193. deduce_mat2<A,B,1,2> >::type
  194. operator-( A const & a, B const & b )
  195. {
  196. typedef typename deduce_mat2<A,B,1,2>::type R;
  197. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==1);
  198. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==2);
  199. R r;
  200. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)-mat_traits<B>::template read_element<0,0>(b);
  201. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)-mat_traits<B>::template read_element<0,1>(b);
  202. return r;
  203. }
  204. namespace
  205. sfinae
  206. {
  207. using ::boost::qvm::operator-;
  208. }
  209. namespace
  210. qvm_detail
  211. {
  212. template <int R,int C>
  213. struct minus_mm_defined;
  214. template <>
  215. struct
  216. minus_mm_defined<1,2>
  217. {
  218. static bool const value=true;
  219. };
  220. }
  221. template <class A,class B>
  222. BOOST_QVM_INLINE_OPERATIONS
  223. typename enable_if_c<
  224. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  225. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  226. A &>::type
  227. operator+=( A & a, B const & b )
  228. {
  229. mat_traits<A>::template write_element<0,0>(a)+=mat_traits<B>::template read_element<0,0>(b);
  230. mat_traits<A>::template write_element<0,1>(a)+=mat_traits<B>::template read_element<0,1>(b);
  231. mat_traits<A>::template write_element<1,0>(a)+=mat_traits<B>::template read_element<1,0>(b);
  232. mat_traits<A>::template write_element<1,1>(a)+=mat_traits<B>::template read_element<1,1>(b);
  233. return a;
  234. }
  235. namespace
  236. sfinae
  237. {
  238. using ::boost::qvm::operator+=;
  239. }
  240. namespace
  241. qvm_detail
  242. {
  243. template <int R,int C>
  244. struct plus_eq_mm_defined;
  245. template <>
  246. struct
  247. plus_eq_mm_defined<2,2>
  248. {
  249. static bool const value=true;
  250. };
  251. }
  252. template <class A,class B>
  253. BOOST_QVM_INLINE_OPERATIONS
  254. typename enable_if_c<
  255. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  256. mat_traits<A>::cols==1 && mat_traits<B>::cols==1,
  257. A &>::type
  258. operator+=( A & a, B const & b )
  259. {
  260. mat_traits<A>::template write_element<0,0>(a)+=mat_traits<B>::template read_element<0,0>(b);
  261. mat_traits<A>::template write_element<1,0>(a)+=mat_traits<B>::template read_element<1,0>(b);
  262. return a;
  263. }
  264. namespace
  265. sfinae
  266. {
  267. using ::boost::qvm::operator+=;
  268. }
  269. namespace
  270. qvm_detail
  271. {
  272. template <int R,int C>
  273. struct plus_eq_mm_defined;
  274. template <>
  275. struct
  276. plus_eq_mm_defined<2,1>
  277. {
  278. static bool const value=true;
  279. };
  280. }
  281. template <class A,class B>
  282. BOOST_QVM_INLINE_OPERATIONS
  283. typename enable_if_c<
  284. mat_traits<A>::rows==1 && mat_traits<B>::rows==1 &&
  285. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  286. A &>::type
  287. operator+=( A & a, B const & b )
  288. {
  289. mat_traits<A>::template write_element<0,0>(a)+=mat_traits<B>::template read_element<0,0>(b);
  290. mat_traits<A>::template write_element<0,1>(a)+=mat_traits<B>::template read_element<0,1>(b);
  291. return a;
  292. }
  293. namespace
  294. sfinae
  295. {
  296. using ::boost::qvm::operator+=;
  297. }
  298. namespace
  299. qvm_detail
  300. {
  301. template <int R,int C>
  302. struct plus_eq_mm_defined;
  303. template <>
  304. struct
  305. plus_eq_mm_defined<1,2>
  306. {
  307. static bool const value=true;
  308. };
  309. }
  310. template <class A,class B>
  311. BOOST_QVM_INLINE_OPERATIONS
  312. typename enable_if_c<
  313. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  314. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  315. A &>::type
  316. operator-=( A & a, B const & b )
  317. {
  318. mat_traits<A>::template write_element<0,0>(a)-=mat_traits<B>::template read_element<0,0>(b);
  319. mat_traits<A>::template write_element<0,1>(a)-=mat_traits<B>::template read_element<0,1>(b);
  320. mat_traits<A>::template write_element<1,0>(a)-=mat_traits<B>::template read_element<1,0>(b);
  321. mat_traits<A>::template write_element<1,1>(a)-=mat_traits<B>::template read_element<1,1>(b);
  322. return a;
  323. }
  324. namespace
  325. sfinae
  326. {
  327. using ::boost::qvm::operator-=;
  328. }
  329. namespace
  330. qvm_detail
  331. {
  332. template <int R,int C>
  333. struct minus_eq_mm_defined;
  334. template <>
  335. struct
  336. minus_eq_mm_defined<2,2>
  337. {
  338. static bool const value=true;
  339. };
  340. }
  341. template <class A,class B>
  342. BOOST_QVM_INLINE_OPERATIONS
  343. typename enable_if_c<
  344. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  345. mat_traits<A>::cols==1 && mat_traits<B>::cols==1,
  346. A &>::type
  347. operator-=( A & a, B const & b )
  348. {
  349. mat_traits<A>::template write_element<0,0>(a)-=mat_traits<B>::template read_element<0,0>(b);
  350. mat_traits<A>::template write_element<1,0>(a)-=mat_traits<B>::template read_element<1,0>(b);
  351. return a;
  352. }
  353. namespace
  354. sfinae
  355. {
  356. using ::boost::qvm::operator-=;
  357. }
  358. namespace
  359. qvm_detail
  360. {
  361. template <int R,int C>
  362. struct minus_eq_mm_defined;
  363. template <>
  364. struct
  365. minus_eq_mm_defined<2,1>
  366. {
  367. static bool const value=true;
  368. };
  369. }
  370. template <class A,class B>
  371. BOOST_QVM_INLINE_OPERATIONS
  372. typename enable_if_c<
  373. mat_traits<A>::rows==1 && mat_traits<B>::rows==1 &&
  374. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  375. A &>::type
  376. operator-=( A & a, B const & b )
  377. {
  378. mat_traits<A>::template write_element<0,0>(a)-=mat_traits<B>::template read_element<0,0>(b);
  379. mat_traits<A>::template write_element<0,1>(a)-=mat_traits<B>::template read_element<0,1>(b);
  380. return a;
  381. }
  382. namespace
  383. sfinae
  384. {
  385. using ::boost::qvm::operator-=;
  386. }
  387. namespace
  388. qvm_detail
  389. {
  390. template <int R,int C>
  391. struct minus_eq_mm_defined;
  392. template <>
  393. struct
  394. minus_eq_mm_defined<1,2>
  395. {
  396. static bool const value=true;
  397. };
  398. }
  399. template <class A,class B>
  400. BOOST_QVM_INLINE_OPERATIONS
  401. typename lazy_enable_if_c<
  402. mat_traits<A>::rows==2 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  403. deduce_mat<A> >::type
  404. operator*( A const & a, B b )
  405. {
  406. typedef typename deduce_mat<A>::type R;
  407. R r;
  408. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)*b;
  409. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)*b;
  410. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)*b;
  411. mat_traits<R>::template write_element<1,1>(r)=mat_traits<A>::template read_element<1,1>(a)*b;
  412. return r;
  413. }
  414. namespace
  415. sfinae
  416. {
  417. using ::boost::qvm::operator*;
  418. }
  419. namespace
  420. qvm_detail
  421. {
  422. template <int R,int C>
  423. struct mul_ms_defined;
  424. template <>
  425. struct
  426. mul_ms_defined<2,2>
  427. {
  428. static bool const value=true;
  429. };
  430. }
  431. template <class A,class B>
  432. BOOST_QVM_INLINE_OPERATIONS
  433. typename lazy_enable_if_c<
  434. is_scalar<A>::value && mat_traits<B>::rows==2 && mat_traits<B>::cols==2,
  435. deduce_mat<B> >::type
  436. operator*( A a, B const & b )
  437. {
  438. typedef typename deduce_mat<B>::type R;
  439. R r;
  440. mat_traits<R>::template write_element<0,0>(r)=a*mat_traits<B>::template read_element<0,0>(b);
  441. mat_traits<R>::template write_element<0,1>(r)=a*mat_traits<B>::template read_element<0,1>(b);
  442. mat_traits<R>::template write_element<1,0>(r)=a*mat_traits<B>::template read_element<1,0>(b);
  443. mat_traits<R>::template write_element<1,1>(r)=a*mat_traits<B>::template read_element<1,1>(b);
  444. return r;
  445. }
  446. namespace
  447. sfinae
  448. {
  449. using ::boost::qvm::operator*;
  450. }
  451. namespace
  452. qvm_detail
  453. {
  454. template <int R,int C>
  455. struct mul_sm_defined;
  456. template <>
  457. struct
  458. mul_sm_defined<2,2>
  459. {
  460. static bool const value=true;
  461. };
  462. }
  463. template <class A,class B>
  464. BOOST_QVM_INLINE_OPERATIONS
  465. typename lazy_enable_if_c<
  466. mat_traits<A>::rows==2 && mat_traits<A>::cols==1 && is_scalar<B>::value,
  467. deduce_mat<A> >::type
  468. operator*( A const & a, B b )
  469. {
  470. typedef typename deduce_mat<A>::type R;
  471. R r;
  472. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)*b;
  473. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)*b;
  474. return r;
  475. }
  476. namespace
  477. sfinae
  478. {
  479. using ::boost::qvm::operator*;
  480. }
  481. namespace
  482. qvm_detail
  483. {
  484. template <int R,int C>
  485. struct mul_ms_defined;
  486. template <>
  487. struct
  488. mul_ms_defined<2,1>
  489. {
  490. static bool const value=true;
  491. };
  492. }
  493. template <class A,class B>
  494. BOOST_QVM_INLINE_OPERATIONS
  495. typename lazy_enable_if_c<
  496. is_scalar<A>::value && mat_traits<B>::rows==2 && mat_traits<B>::cols==1,
  497. deduce_mat<B> >::type
  498. operator*( A a, B const & b )
  499. {
  500. typedef typename deduce_mat<B>::type R;
  501. R r;
  502. mat_traits<R>::template write_element<0,0>(r)=a*mat_traits<B>::template read_element<0,0>(b);
  503. mat_traits<R>::template write_element<1,0>(r)=a*mat_traits<B>::template read_element<1,0>(b);
  504. return r;
  505. }
  506. namespace
  507. sfinae
  508. {
  509. using ::boost::qvm::operator*;
  510. }
  511. namespace
  512. qvm_detail
  513. {
  514. template <int R,int C>
  515. struct mul_sm_defined;
  516. template <>
  517. struct
  518. mul_sm_defined<2,1>
  519. {
  520. static bool const value=true;
  521. };
  522. }
  523. template <class A,class B>
  524. BOOST_QVM_INLINE_OPERATIONS
  525. typename lazy_enable_if_c<
  526. mat_traits<A>::rows==1 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  527. deduce_mat<A> >::type
  528. operator*( A const & a, B b )
  529. {
  530. typedef typename deduce_mat<A>::type R;
  531. R r;
  532. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)*b;
  533. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)*b;
  534. return r;
  535. }
  536. namespace
  537. sfinae
  538. {
  539. using ::boost::qvm::operator*;
  540. }
  541. namespace
  542. qvm_detail
  543. {
  544. template <int R,int C>
  545. struct mul_ms_defined;
  546. template <>
  547. struct
  548. mul_ms_defined<1,2>
  549. {
  550. static bool const value=true;
  551. };
  552. }
  553. template <class A,class B>
  554. BOOST_QVM_INLINE_OPERATIONS
  555. typename lazy_enable_if_c<
  556. is_scalar<A>::value && mat_traits<B>::rows==1 && mat_traits<B>::cols==2,
  557. deduce_mat<B> >::type
  558. operator*( A a, B const & b )
  559. {
  560. typedef typename deduce_mat<B>::type R;
  561. R r;
  562. mat_traits<R>::template write_element<0,0>(r)=a*mat_traits<B>::template read_element<0,0>(b);
  563. mat_traits<R>::template write_element<0,1>(r)=a*mat_traits<B>::template read_element<0,1>(b);
  564. return r;
  565. }
  566. namespace
  567. sfinae
  568. {
  569. using ::boost::qvm::operator*;
  570. }
  571. namespace
  572. qvm_detail
  573. {
  574. template <int R,int C>
  575. struct mul_sm_defined;
  576. template <>
  577. struct
  578. mul_sm_defined<1,2>
  579. {
  580. static bool const value=true;
  581. };
  582. }
  583. template <class A,class B>
  584. BOOST_QVM_INLINE_OPERATIONS
  585. typename enable_if_c<
  586. mat_traits<A>::rows==2 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  587. A &>::type
  588. operator*=( A & a, B b )
  589. {
  590. mat_traits<A>::template write_element<0,0>(a)*=b;
  591. mat_traits<A>::template write_element<0,1>(a)*=b;
  592. mat_traits<A>::template write_element<1,0>(a)*=b;
  593. mat_traits<A>::template write_element<1,1>(a)*=b;
  594. return a;
  595. }
  596. namespace
  597. sfinae
  598. {
  599. using ::boost::qvm::operator*=;
  600. }
  601. namespace
  602. qvm_detail
  603. {
  604. template <int R,int C>
  605. struct mul_eq_ms_defined;
  606. template <>
  607. struct
  608. mul_eq_ms_defined<2,2>
  609. {
  610. static bool const value=true;
  611. };
  612. }
  613. template <class A,class B>
  614. BOOST_QVM_INLINE_OPERATIONS
  615. typename enable_if_c<
  616. mat_traits<A>::rows==2 && mat_traits<A>::cols==1 && is_scalar<B>::value,
  617. A &>::type
  618. operator*=( A & a, B b )
  619. {
  620. mat_traits<A>::template write_element<0,0>(a)*=b;
  621. mat_traits<A>::template write_element<1,0>(a)*=b;
  622. return a;
  623. }
  624. namespace
  625. sfinae
  626. {
  627. using ::boost::qvm::operator*=;
  628. }
  629. namespace
  630. qvm_detail
  631. {
  632. template <int R,int C>
  633. struct mul_eq_ms_defined;
  634. template <>
  635. struct
  636. mul_eq_ms_defined<2,1>
  637. {
  638. static bool const value=true;
  639. };
  640. }
  641. template <class A,class B>
  642. BOOST_QVM_INLINE_OPERATIONS
  643. typename enable_if_c<
  644. mat_traits<A>::rows==1 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  645. A &>::type
  646. operator*=( A & a, B b )
  647. {
  648. mat_traits<A>::template write_element<0,0>(a)*=b;
  649. mat_traits<A>::template write_element<0,1>(a)*=b;
  650. return a;
  651. }
  652. namespace
  653. sfinae
  654. {
  655. using ::boost::qvm::operator*=;
  656. }
  657. namespace
  658. qvm_detail
  659. {
  660. template <int R,int C>
  661. struct mul_eq_ms_defined;
  662. template <>
  663. struct
  664. mul_eq_ms_defined<1,2>
  665. {
  666. static bool const value=true;
  667. };
  668. }
  669. template <class A,class B>
  670. BOOST_QVM_INLINE_OPERATIONS
  671. typename lazy_enable_if_c<
  672. mat_traits<A>::rows==2 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  673. deduce_mat<A> >::type
  674. operator/( A const & a, B b )
  675. {
  676. typedef typename deduce_mat<A>::type R;
  677. R r;
  678. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)/b;
  679. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)/b;
  680. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)/b;
  681. mat_traits<R>::template write_element<1,1>(r)=mat_traits<A>::template read_element<1,1>(a)/b;
  682. return r;
  683. }
  684. namespace
  685. sfinae
  686. {
  687. using ::boost::qvm::operator/;
  688. }
  689. namespace
  690. qvm_detail
  691. {
  692. template <int R,int C>
  693. struct div_ms_defined;
  694. template <>
  695. struct
  696. div_ms_defined<2,2>
  697. {
  698. static bool const value=true;
  699. };
  700. }
  701. template <class A,class B>
  702. BOOST_QVM_INLINE_OPERATIONS
  703. typename lazy_enable_if_c<
  704. is_scalar<A>::value && mat_traits<B>::rows==2 && mat_traits<B>::cols==2,
  705. deduce_mat<B> >::type
  706. operator/( A a, B const & b )
  707. {
  708. typedef typename deduce_mat<B>::type R;
  709. R r;
  710. mat_traits<R>::template write_element<0,0>(r)=a/mat_traits<B>::template read_element<0,0>(b);
  711. mat_traits<R>::template write_element<0,1>(r)=a/mat_traits<B>::template read_element<0,1>(b);
  712. mat_traits<R>::template write_element<1,0>(r)=a/mat_traits<B>::template read_element<1,0>(b);
  713. mat_traits<R>::template write_element<1,1>(r)=a/mat_traits<B>::template read_element<1,1>(b);
  714. return r;
  715. }
  716. namespace
  717. sfinae
  718. {
  719. using ::boost::qvm::operator/;
  720. }
  721. namespace
  722. qvm_detail
  723. {
  724. template <int R,int C>
  725. struct div_sm_defined;
  726. template <>
  727. struct
  728. div_sm_defined<2,2>
  729. {
  730. static bool const value=true;
  731. };
  732. }
  733. template <class A,class B>
  734. BOOST_QVM_INLINE_OPERATIONS
  735. typename lazy_enable_if_c<
  736. mat_traits<A>::rows==2 && mat_traits<A>::cols==1 && is_scalar<B>::value,
  737. deduce_mat<A> >::type
  738. operator/( A const & a, B b )
  739. {
  740. typedef typename deduce_mat<A>::type R;
  741. R r;
  742. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)/b;
  743. mat_traits<R>::template write_element<1,0>(r)=mat_traits<A>::template read_element<1,0>(a)/b;
  744. return r;
  745. }
  746. namespace
  747. sfinae
  748. {
  749. using ::boost::qvm::operator/;
  750. }
  751. namespace
  752. qvm_detail
  753. {
  754. template <int R,int C>
  755. struct div_ms_defined;
  756. template <>
  757. struct
  758. div_ms_defined<2,1>
  759. {
  760. static bool const value=true;
  761. };
  762. }
  763. template <class A,class B>
  764. BOOST_QVM_INLINE_OPERATIONS
  765. typename lazy_enable_if_c<
  766. is_scalar<A>::value && mat_traits<B>::rows==2 && mat_traits<B>::cols==1,
  767. deduce_mat<B> >::type
  768. operator/( A a, B const & b )
  769. {
  770. typedef typename deduce_mat<B>::type R;
  771. R r;
  772. mat_traits<R>::template write_element<0,0>(r)=a/mat_traits<B>::template read_element<0,0>(b);
  773. mat_traits<R>::template write_element<1,0>(r)=a/mat_traits<B>::template read_element<1,0>(b);
  774. return r;
  775. }
  776. namespace
  777. sfinae
  778. {
  779. using ::boost::qvm::operator/;
  780. }
  781. namespace
  782. qvm_detail
  783. {
  784. template <int R,int C>
  785. struct div_sm_defined;
  786. template <>
  787. struct
  788. div_sm_defined<2,1>
  789. {
  790. static bool const value=true;
  791. };
  792. }
  793. template <class A,class B>
  794. BOOST_QVM_INLINE_OPERATIONS
  795. typename lazy_enable_if_c<
  796. mat_traits<A>::rows==1 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  797. deduce_mat<A> >::type
  798. operator/( A const & a, B b )
  799. {
  800. typedef typename deduce_mat<A>::type R;
  801. R r;
  802. mat_traits<R>::template write_element<0,0>(r)=mat_traits<A>::template read_element<0,0>(a)/b;
  803. mat_traits<R>::template write_element<0,1>(r)=mat_traits<A>::template read_element<0,1>(a)/b;
  804. return r;
  805. }
  806. namespace
  807. sfinae
  808. {
  809. using ::boost::qvm::operator/;
  810. }
  811. namespace
  812. qvm_detail
  813. {
  814. template <int R,int C>
  815. struct div_ms_defined;
  816. template <>
  817. struct
  818. div_ms_defined<1,2>
  819. {
  820. static bool const value=true;
  821. };
  822. }
  823. template <class A,class B>
  824. BOOST_QVM_INLINE_OPERATIONS
  825. typename enable_if_c<
  826. mat_traits<A>::rows==2 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  827. A &>::type
  828. operator/=( A & a, B b )
  829. {
  830. mat_traits<A>::template write_element<0,0>(a)/=b;
  831. mat_traits<A>::template write_element<0,1>(a)/=b;
  832. mat_traits<A>::template write_element<1,0>(a)/=b;
  833. mat_traits<A>::template write_element<1,1>(a)/=b;
  834. return a;
  835. }
  836. namespace
  837. sfinae
  838. {
  839. using ::boost::qvm::operator/=;
  840. }
  841. namespace
  842. qvm_detail
  843. {
  844. template <int R,int C>
  845. struct div_eq_ms_defined;
  846. template <>
  847. struct
  848. div_eq_ms_defined<2,2>
  849. {
  850. static bool const value=true;
  851. };
  852. }
  853. template <class A,class B>
  854. BOOST_QVM_INLINE_OPERATIONS
  855. typename enable_if_c<
  856. mat_traits<A>::rows==2 && mat_traits<A>::cols==1 && is_scalar<B>::value,
  857. A &>::type
  858. operator/=( A & a, B b )
  859. {
  860. mat_traits<A>::template write_element<0,0>(a)/=b;
  861. mat_traits<A>::template write_element<1,0>(a)/=b;
  862. return a;
  863. }
  864. namespace
  865. sfinae
  866. {
  867. using ::boost::qvm::operator/=;
  868. }
  869. namespace
  870. qvm_detail
  871. {
  872. template <int R,int C>
  873. struct div_eq_ms_defined;
  874. template <>
  875. struct
  876. div_eq_ms_defined<2,1>
  877. {
  878. static bool const value=true;
  879. };
  880. }
  881. template <class A,class B>
  882. BOOST_QVM_INLINE_OPERATIONS
  883. typename enable_if_c<
  884. mat_traits<A>::rows==1 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  885. A &>::type
  886. operator/=( A & a, B b )
  887. {
  888. mat_traits<A>::template write_element<0,0>(a)/=b;
  889. mat_traits<A>::template write_element<0,1>(a)/=b;
  890. return a;
  891. }
  892. namespace
  893. sfinae
  894. {
  895. using ::boost::qvm::operator/=;
  896. }
  897. namespace
  898. qvm_detail
  899. {
  900. template <int R,int C>
  901. struct div_eq_ms_defined;
  902. template <>
  903. struct
  904. div_eq_ms_defined<1,2>
  905. {
  906. static bool const value=true;
  907. };
  908. }
  909. template <class R,class A>
  910. BOOST_QVM_INLINE_OPERATIONS
  911. typename enable_if_c<
  912. mat_traits<R>::rows==2 && mat_traits<A>::rows==2 &&
  913. mat_traits<R>::cols==2 && mat_traits<A>::cols==2,
  914. R>::type
  915. convert_to( A const & a )
  916. {
  917. R r;
  918. mat_traits<R>::template write_element<0,0>(r) = mat_traits<A>::template read_element<0,0>(a);
  919. mat_traits<R>::template write_element<0,1>(r) = mat_traits<A>::template read_element<0,1>(a);
  920. mat_traits<R>::template write_element<1,0>(r) = mat_traits<A>::template read_element<1,0>(a);
  921. mat_traits<R>::template write_element<1,1>(r) = mat_traits<A>::template read_element<1,1>(a);
  922. return r;
  923. }
  924. namespace
  925. sfinae
  926. {
  927. using ::boost::qvm::convert_to;
  928. }
  929. namespace
  930. qvm_detail
  931. {
  932. template <int R,int C>
  933. struct convert_to_m_defined;
  934. template <>
  935. struct
  936. convert_to_m_defined<2,2>
  937. {
  938. static bool const value=true;
  939. };
  940. }
  941. template <class R,class A>
  942. BOOST_QVM_INLINE_OPERATIONS
  943. typename enable_if_c<
  944. mat_traits<R>::rows==2 && mat_traits<A>::rows==2 &&
  945. mat_traits<R>::cols==1 && mat_traits<A>::cols==1,
  946. R>::type
  947. convert_to( A const & a )
  948. {
  949. R r;
  950. mat_traits<R>::template write_element<0,0>(r) = mat_traits<A>::template read_element<0,0>(a);
  951. mat_traits<R>::template write_element<1,0>(r) = mat_traits<A>::template read_element<1,0>(a);
  952. return r;
  953. }
  954. namespace
  955. sfinae
  956. {
  957. using ::boost::qvm::convert_to;
  958. }
  959. namespace
  960. qvm_detail
  961. {
  962. template <int R,int C>
  963. struct convert_to_m_defined;
  964. template <>
  965. struct
  966. convert_to_m_defined<2,1>
  967. {
  968. static bool const value=true;
  969. };
  970. }
  971. template <class R,class A>
  972. BOOST_QVM_INLINE_OPERATIONS
  973. typename enable_if_c<
  974. mat_traits<R>::rows==1 && mat_traits<A>::rows==1 &&
  975. mat_traits<R>::cols==2 && mat_traits<A>::cols==2,
  976. R>::type
  977. convert_to( A const & a )
  978. {
  979. R r;
  980. mat_traits<R>::template write_element<0,0>(r) = mat_traits<A>::template read_element<0,0>(a);
  981. mat_traits<R>::template write_element<0,1>(r) = mat_traits<A>::template read_element<0,1>(a);
  982. return r;
  983. }
  984. namespace
  985. sfinae
  986. {
  987. using ::boost::qvm::convert_to;
  988. }
  989. namespace
  990. qvm_detail
  991. {
  992. template <int R,int C>
  993. struct convert_to_m_defined;
  994. template <>
  995. struct
  996. convert_to_m_defined<1,2>
  997. {
  998. static bool const value=true;
  999. };
  1000. }
  1001. template <class A,class B>
  1002. BOOST_QVM_INLINE_OPERATIONS
  1003. typename enable_if_c<
  1004. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1005. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1006. bool>::type
  1007. operator==( A const & a, B const & b )
  1008. {
  1009. return
  1010. mat_traits<A>::template read_element<0,0>(a)==mat_traits<B>::template read_element<0,0>(b) &&
  1011. mat_traits<A>::template read_element<0,1>(a)==mat_traits<B>::template read_element<0,1>(b) &&
  1012. mat_traits<A>::template read_element<1,0>(a)==mat_traits<B>::template read_element<1,0>(b) &&
  1013. mat_traits<A>::template read_element<1,1>(a)==mat_traits<B>::template read_element<1,1>(b);
  1014. }
  1015. namespace
  1016. sfinae
  1017. {
  1018. using ::boost::qvm::operator==;
  1019. }
  1020. namespace
  1021. qvm_detail
  1022. {
  1023. template <int R,int C>
  1024. struct eq_mm_defined;
  1025. template <>
  1026. struct
  1027. eq_mm_defined<2,2>
  1028. {
  1029. static bool const value=true;
  1030. };
  1031. }
  1032. template <class A,class B>
  1033. BOOST_QVM_INLINE_OPERATIONS
  1034. typename enable_if_c<
  1035. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1036. mat_traits<A>::cols==1 && mat_traits<B>::cols==1,
  1037. bool>::type
  1038. operator==( A const & a, B const & b )
  1039. {
  1040. return
  1041. mat_traits<A>::template read_element<0,0>(a)==mat_traits<B>::template read_element<0,0>(b) &&
  1042. mat_traits<A>::template read_element<1,0>(a)==mat_traits<B>::template read_element<1,0>(b);
  1043. }
  1044. namespace
  1045. sfinae
  1046. {
  1047. using ::boost::qvm::operator==;
  1048. }
  1049. namespace
  1050. qvm_detail
  1051. {
  1052. template <int R,int C>
  1053. struct eq_mm_defined;
  1054. template <>
  1055. struct
  1056. eq_mm_defined<2,1>
  1057. {
  1058. static bool const value=true;
  1059. };
  1060. }
  1061. template <class A,class B>
  1062. BOOST_QVM_INLINE_OPERATIONS
  1063. typename enable_if_c<
  1064. mat_traits<A>::rows==1 && mat_traits<B>::rows==1 &&
  1065. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1066. bool>::type
  1067. operator==( A const & a, B const & b )
  1068. {
  1069. return
  1070. mat_traits<A>::template read_element<0,0>(a)==mat_traits<B>::template read_element<0,0>(b) &&
  1071. mat_traits<A>::template read_element<0,1>(a)==mat_traits<B>::template read_element<0,1>(b);
  1072. }
  1073. namespace
  1074. sfinae
  1075. {
  1076. using ::boost::qvm::operator==;
  1077. }
  1078. namespace
  1079. qvm_detail
  1080. {
  1081. template <int R,int C>
  1082. struct eq_mm_defined;
  1083. template <>
  1084. struct
  1085. eq_mm_defined<1,2>
  1086. {
  1087. static bool const value=true;
  1088. };
  1089. }
  1090. template <class A,class B>
  1091. BOOST_QVM_INLINE_OPERATIONS
  1092. typename enable_if_c<
  1093. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1094. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1095. bool>::type
  1096. operator!=( A const & a, B const & b )
  1097. {
  1098. return
  1099. !(mat_traits<A>::template read_element<0,0>(a)==mat_traits<B>::template read_element<0,0>(b)) ||
  1100. !(mat_traits<A>::template read_element<0,1>(a)==mat_traits<B>::template read_element<0,1>(b)) ||
  1101. !(mat_traits<A>::template read_element<1,0>(a)==mat_traits<B>::template read_element<1,0>(b)) ||
  1102. !(mat_traits<A>::template read_element<1,1>(a)==mat_traits<B>::template read_element<1,1>(b));
  1103. }
  1104. namespace
  1105. sfinae
  1106. {
  1107. using ::boost::qvm::operator!=;
  1108. }
  1109. namespace
  1110. qvm_detail
  1111. {
  1112. template <int R,int C>
  1113. struct neq_mm_defined;
  1114. template <>
  1115. struct
  1116. neq_mm_defined<2,2>
  1117. {
  1118. static bool const value=true;
  1119. };
  1120. }
  1121. template <class A,class B>
  1122. BOOST_QVM_INLINE_OPERATIONS
  1123. typename enable_if_c<
  1124. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1125. mat_traits<A>::cols==1 && mat_traits<B>::cols==1,
  1126. bool>::type
  1127. operator!=( A const & a, B const & b )
  1128. {
  1129. return
  1130. !(mat_traits<A>::template read_element<0,0>(a)==mat_traits<B>::template read_element<0,0>(b)) ||
  1131. !(mat_traits<A>::template read_element<1,0>(a)==mat_traits<B>::template read_element<1,0>(b));
  1132. }
  1133. namespace
  1134. sfinae
  1135. {
  1136. using ::boost::qvm::operator!=;
  1137. }
  1138. namespace
  1139. qvm_detail
  1140. {
  1141. template <int R,int C>
  1142. struct neq_mm_defined;
  1143. template <>
  1144. struct
  1145. neq_mm_defined<2,1>
  1146. {
  1147. static bool const value=true;
  1148. };
  1149. }
  1150. template <class A,class B>
  1151. BOOST_QVM_INLINE_OPERATIONS
  1152. typename enable_if_c<
  1153. mat_traits<A>::rows==1 && mat_traits<B>::rows==1 &&
  1154. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1155. bool>::type
  1156. operator!=( A const & a, B const & b )
  1157. {
  1158. return
  1159. !(mat_traits<A>::template read_element<0,0>(a)==mat_traits<B>::template read_element<0,0>(b)) ||
  1160. !(mat_traits<A>::template read_element<0,1>(a)==mat_traits<B>::template read_element<0,1>(b));
  1161. }
  1162. namespace
  1163. sfinae
  1164. {
  1165. using ::boost::qvm::operator!=;
  1166. }
  1167. namespace
  1168. qvm_detail
  1169. {
  1170. template <int R,int C>
  1171. struct neq_mm_defined;
  1172. template <>
  1173. struct
  1174. neq_mm_defined<1,2>
  1175. {
  1176. static bool const value=true;
  1177. };
  1178. }
  1179. template <class A>
  1180. BOOST_QVM_INLINE_OPERATIONS
  1181. typename lazy_enable_if_c<
  1182. mat_traits<A>::rows==2 && mat_traits<A>::cols==2,
  1183. deduce_mat<A> >::type
  1184. operator-( A const & a )
  1185. {
  1186. typedef typename deduce_mat<A>::type R;
  1187. R r;
  1188. mat_traits<R>::template write_element<0,0>(r)=-mat_traits<A>::template read_element<0,0>(a);
  1189. mat_traits<R>::template write_element<0,1>(r)=-mat_traits<A>::template read_element<0,1>(a);
  1190. mat_traits<R>::template write_element<1,0>(r)=-mat_traits<A>::template read_element<1,0>(a);
  1191. mat_traits<R>::template write_element<1,1>(r)=-mat_traits<A>::template read_element<1,1>(a);
  1192. return r;
  1193. }
  1194. namespace
  1195. sfinae
  1196. {
  1197. using ::boost::qvm::operator-;
  1198. }
  1199. namespace
  1200. qvm_detail
  1201. {
  1202. template <int R,int C>
  1203. struct minus_m_defined;
  1204. template <>
  1205. struct
  1206. minus_m_defined<2,2>
  1207. {
  1208. static bool const value=true;
  1209. };
  1210. }
  1211. template <class A>
  1212. BOOST_QVM_INLINE_OPERATIONS
  1213. typename lazy_enable_if_c<
  1214. mat_traits<A>::rows==2 && mat_traits<A>::cols==1,
  1215. deduce_mat<A> >::type
  1216. operator-( A const & a )
  1217. {
  1218. typedef typename deduce_mat<A>::type R;
  1219. R r;
  1220. mat_traits<R>::template write_element<0,0>(r)=-mat_traits<A>::template read_element<0,0>(a);
  1221. mat_traits<R>::template write_element<1,0>(r)=-mat_traits<A>::template read_element<1,0>(a);
  1222. return r;
  1223. }
  1224. namespace
  1225. sfinae
  1226. {
  1227. using ::boost::qvm::operator-;
  1228. }
  1229. namespace
  1230. qvm_detail
  1231. {
  1232. template <int R,int C>
  1233. struct minus_m_defined;
  1234. template <>
  1235. struct
  1236. minus_m_defined<2,1>
  1237. {
  1238. static bool const value=true;
  1239. };
  1240. }
  1241. template <class A>
  1242. BOOST_QVM_INLINE_OPERATIONS
  1243. typename lazy_enable_if_c<
  1244. mat_traits<A>::rows==1 && mat_traits<A>::cols==2,
  1245. deduce_mat<A> >::type
  1246. operator-( A const & a )
  1247. {
  1248. typedef typename deduce_mat<A>::type R;
  1249. R r;
  1250. mat_traits<R>::template write_element<0,0>(r)=-mat_traits<A>::template read_element<0,0>(a);
  1251. mat_traits<R>::template write_element<0,1>(r)=-mat_traits<A>::template read_element<0,1>(a);
  1252. return r;
  1253. }
  1254. namespace
  1255. sfinae
  1256. {
  1257. using ::boost::qvm::operator-;
  1258. }
  1259. namespace
  1260. qvm_detail
  1261. {
  1262. template <int R,int C>
  1263. struct minus_m_defined;
  1264. template <>
  1265. struct
  1266. minus_m_defined<1,2>
  1267. {
  1268. static bool const value=true;
  1269. };
  1270. }
  1271. template <class A>
  1272. BOOST_QVM_INLINE_OPERATIONS
  1273. typename enable_if_c<
  1274. mat_traits<A>::rows==2 && mat_traits<A>::cols==2,
  1275. typename mat_traits<A>::scalar_type>::type
  1276. determinant( A const & a )
  1277. {
  1278. typedef typename mat_traits<A>::scalar_type T;
  1279. T const a00=mat_traits<A>::template read_element<0,0>(a);
  1280. T const a01=mat_traits<A>::template read_element<0,1>(a);
  1281. T const a10=mat_traits<A>::template read_element<1,0>(a);
  1282. T const a11=mat_traits<A>::template read_element<1,1>(a);
  1283. T det=(a00*a11-a01*a10);
  1284. return det;
  1285. }
  1286. namespace
  1287. sfinae
  1288. {
  1289. using ::boost::qvm::determinant;
  1290. }
  1291. namespace
  1292. qvm_detail
  1293. {
  1294. template <int D>
  1295. struct determinant_defined;
  1296. template <>
  1297. struct
  1298. determinant_defined<2>
  1299. {
  1300. static bool const value=true;
  1301. };
  1302. }
  1303. template <class A,class B>
  1304. BOOST_QVM_INLINE_OPERATIONS
  1305. typename lazy_enable_if_c<
  1306. mat_traits<A>::rows==2 && mat_traits<A>::cols==2 && is_scalar<B>::value,
  1307. deduce_mat<A> >::type
  1308. inverse( A const & a, B det )
  1309. {
  1310. typedef typename mat_traits<A>::scalar_type T;
  1311. BOOST_QVM_ASSERT(det!=scalar_traits<B>::value(0));
  1312. T const a00=mat_traits<A>::template read_element<0,0>(a);
  1313. T const a01=mat_traits<A>::template read_element<0,1>(a);
  1314. T const a10=mat_traits<A>::template read_element<1,0>(a);
  1315. T const a11=mat_traits<A>::template read_element<1,1>(a);
  1316. T const f=scalar_traits<T>::value(1)/det;
  1317. typedef typename deduce_mat<A>::type R;
  1318. R r;
  1319. mat_traits<R>::template write_element<0,0>(r)= f*a11;
  1320. mat_traits<R>::template write_element<0,1>(r)=-f*a01;
  1321. mat_traits<R>::template write_element<1,0>(r)=-f*a10;
  1322. mat_traits<R>::template write_element<1,1>(r)= f*a00;
  1323. return r;
  1324. }
  1325. template <class A>
  1326. BOOST_QVM_INLINE_OPERATIONS
  1327. typename lazy_enable_if_c<
  1328. mat_traits<A>::rows==2 && mat_traits<A>::cols==2,
  1329. deduce_mat<A> >::type
  1330. inverse( A const & a )
  1331. {
  1332. typedef typename mat_traits<A>::scalar_type T;
  1333. T det=determinant(a);
  1334. if( det==scalar_traits<T>::value(0) )
  1335. BOOST_QVM_THROW_EXCEPTION(zero_determinant_error());
  1336. return inverse(a,det);
  1337. }
  1338. namespace
  1339. sfinae
  1340. {
  1341. using ::boost::qvm::inverse;
  1342. }
  1343. namespace
  1344. qvm_detail
  1345. {
  1346. template <int D>
  1347. struct inverse_m_defined;
  1348. template <>
  1349. struct
  1350. inverse_m_defined<2>
  1351. {
  1352. static bool const value=true;
  1353. };
  1354. }
  1355. template <class A,class B>
  1356. BOOST_QVM_INLINE_OPERATIONS
  1357. typename lazy_enable_if_c<
  1358. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1359. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1360. deduce_mat2<A,B,2,2> >::type
  1361. operator*( A const & a, B const & b )
  1362. {
  1363. typedef typename mat_traits<A>::scalar_type Ta;
  1364. typedef typename mat_traits<B>::scalar_type Tb;
  1365. Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
  1366. Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
  1367. Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
  1368. Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
  1369. Tb const b00 = mat_traits<B>::template read_element<0,0>(b);
  1370. Tb const b01 = mat_traits<B>::template read_element<0,1>(b);
  1371. Tb const b10 = mat_traits<B>::template read_element<1,0>(b);
  1372. Tb const b11 = mat_traits<B>::template read_element<1,1>(b);
  1373. typedef typename deduce_mat2<A,B,2,2>::type R;
  1374. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==2);
  1375. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==2);
  1376. R r;
  1377. mat_traits<R>::template write_element<0,0>(r)=a00*b00+a01*b10;
  1378. mat_traits<R>::template write_element<0,1>(r)=a00*b01+a01*b11;
  1379. mat_traits<R>::template write_element<1,0>(r)=a10*b00+a11*b10;
  1380. mat_traits<R>::template write_element<1,1>(r)=a10*b01+a11*b11;
  1381. return r;
  1382. }
  1383. namespace
  1384. sfinae
  1385. {
  1386. using ::boost::qvm::operator*;
  1387. }
  1388. namespace
  1389. qvm_detail
  1390. {
  1391. template <int R,int CR,int C>
  1392. struct mul_mm_defined;
  1393. template <>
  1394. struct
  1395. mul_mm_defined<2,2,2>
  1396. {
  1397. static bool const value=true;
  1398. };
  1399. }
  1400. template <class A,class B>
  1401. BOOST_QVM_INLINE_OPERATIONS
  1402. typename enable_if_c<
  1403. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1404. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1405. A &>::type
  1406. operator*=( A & a, B const & b )
  1407. {
  1408. typedef typename mat_traits<A>::scalar_type Ta;
  1409. typedef typename mat_traits<B>::scalar_type Tb;
  1410. Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
  1411. Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
  1412. Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
  1413. Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
  1414. Tb const b00 = mat_traits<B>::template read_element<0,0>(b);
  1415. Tb const b01 = mat_traits<B>::template read_element<0,1>(b);
  1416. Tb const b10 = mat_traits<B>::template read_element<1,0>(b);
  1417. Tb const b11 = mat_traits<B>::template read_element<1,1>(b);
  1418. mat_traits<A>::template write_element<0,0>(a)=a00*b00+a01*b10;
  1419. mat_traits<A>::template write_element<0,1>(a)=a00*b01+a01*b11;
  1420. mat_traits<A>::template write_element<1,0>(a)=a10*b00+a11*b10;
  1421. mat_traits<A>::template write_element<1,1>(a)=a10*b01+a11*b11;
  1422. return a;
  1423. }
  1424. namespace
  1425. sfinae
  1426. {
  1427. using ::boost::qvm::operator*=;
  1428. }
  1429. namespace
  1430. qvm_detail
  1431. {
  1432. template <int D>
  1433. struct mul_eq_mm_defined;
  1434. template <>
  1435. struct
  1436. mul_eq_mm_defined<2>
  1437. {
  1438. static bool const value=true;
  1439. };
  1440. }
  1441. template <class A,class B>
  1442. BOOST_QVM_INLINE_OPERATIONS
  1443. typename lazy_enable_if_c<
  1444. mat_traits<A>::rows==2 && mat_traits<B>::rows==2 &&
  1445. mat_traits<A>::cols==2 && mat_traits<B>::cols==1,
  1446. deduce_mat2<A,B,2,1> >::type
  1447. operator*( A const & a, B const & b )
  1448. {
  1449. typedef typename mat_traits<A>::scalar_type Ta;
  1450. typedef typename mat_traits<B>::scalar_type Tb;
  1451. Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
  1452. Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
  1453. Ta const a10 = mat_traits<A>::template read_element<1,0>(a);
  1454. Ta const a11 = mat_traits<A>::template read_element<1,1>(a);
  1455. Tb const b00 = mat_traits<B>::template read_element<0,0>(b);
  1456. Tb const b10 = mat_traits<B>::template read_element<1,0>(b);
  1457. typedef typename deduce_mat2<A,B,2,1>::type R;
  1458. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==2);
  1459. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==1);
  1460. R r;
  1461. mat_traits<R>::template write_element<0,0>(r)=a00*b00+a01*b10;
  1462. mat_traits<R>::template write_element<1,0>(r)=a10*b00+a11*b10;
  1463. return r;
  1464. }
  1465. namespace
  1466. sfinae
  1467. {
  1468. using ::boost::qvm::operator*;
  1469. }
  1470. namespace
  1471. qvm_detail
  1472. {
  1473. template <int R,int CR,int C>
  1474. struct mul_mm_defined;
  1475. template <>
  1476. struct
  1477. mul_mm_defined<2,2,1>
  1478. {
  1479. static bool const value=true;
  1480. };
  1481. }
  1482. template <class A,class B>
  1483. BOOST_QVM_INLINE_OPERATIONS
  1484. typename lazy_enable_if_c<
  1485. mat_traits<A>::rows==1 && mat_traits<B>::rows==2 &&
  1486. mat_traits<A>::cols==2 && mat_traits<B>::cols==2,
  1487. deduce_mat2<A,B,1,2> >::type
  1488. operator*( A const & a, B const & b )
  1489. {
  1490. typedef typename mat_traits<A>::scalar_type Ta;
  1491. typedef typename mat_traits<B>::scalar_type Tb;
  1492. Ta const a00 = mat_traits<A>::template read_element<0,0>(a);
  1493. Ta const a01 = mat_traits<A>::template read_element<0,1>(a);
  1494. Tb const b00 = mat_traits<B>::template read_element<0,0>(b);
  1495. Tb const b01 = mat_traits<B>::template read_element<0,1>(b);
  1496. Tb const b10 = mat_traits<B>::template read_element<1,0>(b);
  1497. Tb const b11 = mat_traits<B>::template read_element<1,1>(b);
  1498. typedef typename deduce_mat2<A,B,1,2>::type R;
  1499. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::rows==1);
  1500. BOOST_QVM_STATIC_ASSERT(mat_traits<R>::cols==2);
  1501. R r;
  1502. mat_traits<R>::template write_element<0,0>(r)=a00*b00+a01*b10;
  1503. mat_traits<R>::template write_element<0,1>(r)=a00*b01+a01*b11;
  1504. return r;
  1505. }
  1506. namespace
  1507. sfinae
  1508. {
  1509. using ::boost::qvm::operator*;
  1510. }
  1511. namespace
  1512. qvm_detail
  1513. {
  1514. template <int R,int CR,int C>
  1515. struct mul_mm_defined;
  1516. template <>
  1517. struct
  1518. mul_mm_defined<1,2,2>
  1519. {
  1520. static bool const value=true;
  1521. };
  1522. }
  1523. }
  1524. }
  1525. #endif