vec_operations2.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. #ifndef BOOST_QVM_GEN_VEC_OPERATIONS2_HPP_INCLUDED
  2. #define BOOST_QVM_GEN_VEC_OPERATIONS2_HPP_INCLUDED
  3. /// Copyright (c) 2008-2021 Emil Dotchevski and Reverge Studios, Inc.
  4. /// Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. /// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /// This file was generated by a program. Do not edit manually.
  7. #include <boost/qvm/deduce_scalar.hpp>
  8. #include <boost/qvm/deduce_vec.hpp>
  9. #include <boost/qvm/error.hpp>
  10. #include <boost/qvm/gen/vec_assign2.hpp>
  11. #include <boost/qvm/math.hpp>
  12. #include <boost/qvm/static_assert.hpp>
  13. #include <boost/qvm/throw_exception.hpp>
  14. namespace boost { namespace qvm {
  15. template <class A,class B>
  16. BOOST_QVM_INLINE_OPERATIONS
  17. typename lazy_enable_if_c<
  18. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  19. deduce_vec2<A,B,2> >::type
  20. operator+( A const & a, B const & b )
  21. {
  22. typedef typename deduce_vec2<A,B,2>::type R;
  23. BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==2);
  24. R r;
  25. vec_traits<R>::template write_element<0>(r)=vec_traits<A>::template read_element<0>(a)+vec_traits<B>::template read_element<0>(b);
  26. vec_traits<R>::template write_element<1>(r)=vec_traits<A>::template read_element<1>(a)+vec_traits<B>::template read_element<1>(b);
  27. return r;
  28. }
  29. namespace
  30. sfinae
  31. {
  32. using ::boost::qvm::operator+;
  33. }
  34. namespace
  35. qvm_detail
  36. {
  37. template <int D>
  38. struct plus_vv_defined;
  39. template <>
  40. struct
  41. plus_vv_defined<2>
  42. {
  43. static bool const value=true;
  44. };
  45. }
  46. template <class A,class B>
  47. BOOST_QVM_INLINE_OPERATIONS
  48. typename lazy_enable_if_c<
  49. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  50. deduce_vec2<A,B,2> >::type
  51. operator-( A const & a, B const & b )
  52. {
  53. typedef typename deduce_vec2<A,B,2>::type R;
  54. BOOST_QVM_STATIC_ASSERT(vec_traits<R>::dim==2);
  55. R r;
  56. vec_traits<R>::template write_element<0>(r)=vec_traits<A>::template read_element<0>(a)-vec_traits<B>::template read_element<0>(b);
  57. vec_traits<R>::template write_element<1>(r)=vec_traits<A>::template read_element<1>(a)-vec_traits<B>::template read_element<1>(b);
  58. return r;
  59. }
  60. namespace
  61. sfinae
  62. {
  63. using ::boost::qvm::operator-;
  64. }
  65. namespace
  66. qvm_detail
  67. {
  68. template <int D>
  69. struct minus_vv_defined;
  70. template <>
  71. struct
  72. minus_vv_defined<2>
  73. {
  74. static bool const value=true;
  75. };
  76. }
  77. template <class A,class B>
  78. BOOST_QVM_INLINE_OPERATIONS
  79. typename enable_if_c<
  80. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  81. A &>::type
  82. operator+=( A & a, B const & b )
  83. {
  84. vec_traits<A>::template write_element<0>(a)+=vec_traits<B>::template read_element<0>(b);
  85. vec_traits<A>::template write_element<1>(a)+=vec_traits<B>::template read_element<1>(b);
  86. return a;
  87. }
  88. namespace
  89. sfinae
  90. {
  91. using ::boost::qvm::operator+=;
  92. }
  93. namespace
  94. qvm_detail
  95. {
  96. template <int D>
  97. struct plus_eq_vv_defined;
  98. template <>
  99. struct
  100. plus_eq_vv_defined<2>
  101. {
  102. static bool const value=true;
  103. };
  104. }
  105. template <class A,class B>
  106. BOOST_QVM_INLINE_OPERATIONS
  107. typename enable_if_c<
  108. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  109. A &>::type
  110. operator-=( A & a, B const & b )
  111. {
  112. vec_traits<A>::template write_element<0>(a)-=vec_traits<B>::template read_element<0>(b);
  113. vec_traits<A>::template write_element<1>(a)-=vec_traits<B>::template read_element<1>(b);
  114. return a;
  115. }
  116. namespace
  117. sfinae
  118. {
  119. using ::boost::qvm::operator-=;
  120. }
  121. namespace
  122. qvm_detail
  123. {
  124. template <int D>
  125. struct minus_eq_vv_defined;
  126. template <>
  127. struct
  128. minus_eq_vv_defined<2>
  129. {
  130. static bool const value=true;
  131. };
  132. }
  133. template <class A,class B>
  134. BOOST_QVM_INLINE_OPERATIONS
  135. typename lazy_enable_if_c<
  136. vec_traits<A>::dim==2 && is_scalar<B>::value,
  137. deduce_vec2<A,B,vec_traits<A>::dim> >::type
  138. operator*( A const & a, B b )
  139. {
  140. typedef typename deduce_vec2<A,B,vec_traits<A>::dim>::type R;
  141. R r;
  142. vec_traits<R>::template write_element<0>(r)=vec_traits<A>::template read_element<0>(a)*b;
  143. vec_traits<R>::template write_element<1>(r)=vec_traits<A>::template read_element<1>(a)*b;
  144. return r;
  145. }
  146. namespace
  147. sfinae
  148. {
  149. using ::boost::qvm::operator*;
  150. }
  151. namespace
  152. qvm_detail
  153. {
  154. template <int D>
  155. struct mul_vs_defined;
  156. template <>
  157. struct
  158. mul_vs_defined<2>
  159. {
  160. static bool const value=true;
  161. };
  162. }
  163. template <class A,class B>
  164. BOOST_QVM_INLINE_OPERATIONS
  165. typename lazy_enable_if_c<
  166. is_scalar<A>::value && vec_traits<B>::dim==2,
  167. deduce_vec2<A,B,vec_traits<B>::dim> >::type
  168. operator*( A a, B const & b )
  169. {
  170. typedef typename deduce_vec2<A,B,vec_traits<B>::dim>::type R;
  171. R r;
  172. vec_traits<R>::template write_element<0>(r)=a*vec_traits<B>::template read_element<0>(b);
  173. vec_traits<R>::template write_element<1>(r)=a*vec_traits<B>::template read_element<1>(b);
  174. return r;
  175. }
  176. namespace
  177. sfinae
  178. {
  179. using ::boost::qvm::operator*;
  180. }
  181. namespace
  182. qvm_detail
  183. {
  184. template <int D>
  185. struct mul_sv_defined;
  186. template <>
  187. struct
  188. mul_sv_defined<2>
  189. {
  190. static bool const value=true;
  191. };
  192. }
  193. template <class A,class B>
  194. BOOST_QVM_INLINE_OPERATIONS
  195. typename enable_if_c<
  196. vec_traits<A>::dim==2 && is_scalar<B>::value,
  197. A &>::type
  198. operator*=( A & a, B b )
  199. {
  200. vec_traits<A>::template write_element<0>(a)*=b;
  201. vec_traits<A>::template write_element<1>(a)*=b;
  202. return a;
  203. }
  204. namespace
  205. sfinae
  206. {
  207. using ::boost::qvm::operator*=;
  208. }
  209. namespace
  210. qvm_detail
  211. {
  212. template <int D>
  213. struct mul_eq_vs_defined;
  214. template <>
  215. struct
  216. mul_eq_vs_defined<2>
  217. {
  218. static bool const value=true;
  219. };
  220. }
  221. template <class A,class B>
  222. BOOST_QVM_INLINE_OPERATIONS
  223. typename lazy_enable_if_c<
  224. vec_traits<A>::dim==2 && is_scalar<B>::value,
  225. deduce_vec2<A,B,vec_traits<A>::dim> >::type
  226. operator/( A const & a, B b )
  227. {
  228. typedef typename deduce_vec2<A,B,vec_traits<A>::dim>::type R;
  229. R r;
  230. vec_traits<R>::template write_element<0>(r)=vec_traits<A>::template read_element<0>(a)/b;
  231. vec_traits<R>::template write_element<1>(r)=vec_traits<A>::template read_element<1>(a)/b;
  232. return r;
  233. }
  234. namespace
  235. sfinae
  236. {
  237. using ::boost::qvm::operator/;
  238. }
  239. namespace
  240. qvm_detail
  241. {
  242. template <int D>
  243. struct div_vs_defined;
  244. template <>
  245. struct
  246. div_vs_defined<2>
  247. {
  248. static bool const value=true;
  249. };
  250. }
  251. template <class A,class B>
  252. BOOST_QVM_INLINE_OPERATIONS
  253. typename enable_if_c<
  254. vec_traits<A>::dim==2 && is_scalar<B>::value,
  255. A &>::type
  256. operator/=( A & a, B b )
  257. {
  258. vec_traits<A>::template write_element<0>(a)/=b;
  259. vec_traits<A>::template write_element<1>(a)/=b;
  260. return a;
  261. }
  262. namespace
  263. sfinae
  264. {
  265. using ::boost::qvm::operator/=;
  266. }
  267. namespace
  268. qvm_detail
  269. {
  270. template <int D>
  271. struct div_eq_vs_defined;
  272. template <>
  273. struct
  274. div_eq_vs_defined<2>
  275. {
  276. static bool const value=true;
  277. };
  278. }
  279. template <class R,class A>
  280. BOOST_QVM_INLINE_OPERATIONS
  281. typename enable_if_c<
  282. is_vec<A>::value &&
  283. vec_traits<R>::dim==2 && vec_traits<A>::dim==2,
  284. R>::type
  285. convert_to( A const & a )
  286. {
  287. R r;
  288. vec_traits<R>::template write_element<0>(r)=vec_traits<A>::template read_element<0>(a);
  289. vec_traits<R>::template write_element<1>(r)=vec_traits<A>::template read_element<1>(a);
  290. return r;
  291. }
  292. namespace
  293. sfinae
  294. {
  295. using ::boost::qvm::convert_to;
  296. }
  297. namespace
  298. qvm_detail
  299. {
  300. template <int D>
  301. struct convert_to_v_defined;
  302. template <>
  303. struct
  304. convert_to_v_defined<2>
  305. {
  306. static bool const value=true;
  307. };
  308. }
  309. template <class A,class B>
  310. BOOST_QVM_INLINE_OPERATIONS
  311. typename enable_if_c<
  312. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  313. bool>::type
  314. operator==( A const & a, B const & b )
  315. {
  316. return
  317. vec_traits<A>::template read_element<0>(a)==vec_traits<B>::template read_element<0>(b) &&
  318. vec_traits<A>::template read_element<1>(a)==vec_traits<B>::template read_element<1>(b);
  319. }
  320. namespace
  321. sfinae
  322. {
  323. using ::boost::qvm::operator==;
  324. }
  325. namespace
  326. qvm_detail
  327. {
  328. template <int D>
  329. struct eq_vv_defined;
  330. template <>
  331. struct
  332. eq_vv_defined<2>
  333. {
  334. static bool const value=true;
  335. };
  336. }
  337. template <class A,class B>
  338. BOOST_QVM_INLINE_OPERATIONS
  339. typename enable_if_c<
  340. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  341. bool>::type
  342. operator!=( A const & a, B const & b )
  343. {
  344. return
  345. !(vec_traits<A>::template read_element<0>(a)==vec_traits<B>::template read_element<0>(b)) ||
  346. !(vec_traits<A>::template read_element<1>(a)==vec_traits<B>::template read_element<1>(b));
  347. }
  348. namespace
  349. sfinae
  350. {
  351. using ::boost::qvm::operator!=;
  352. }
  353. namespace
  354. qvm_detail
  355. {
  356. template <int D>
  357. struct neq_vv_defined;
  358. template <>
  359. struct
  360. neq_vv_defined<2>
  361. {
  362. static bool const value=true;
  363. };
  364. }
  365. template <class A>
  366. BOOST_QVM_INLINE_OPERATIONS
  367. typename lazy_enable_if_c<
  368. vec_traits<A>::dim==2,
  369. deduce_vec<A> >::type
  370. operator-( A const & a )
  371. {
  372. typedef typename deduce_vec<A>::type R;
  373. R r;
  374. vec_traits<R>::template write_element<0>(r)=-vec_traits<A>::template read_element<0>(a);
  375. vec_traits<R>::template write_element<1>(r)=-vec_traits<A>::template read_element<1>(a);
  376. return r;
  377. }
  378. namespace
  379. sfinae
  380. {
  381. using ::boost::qvm::operator-;
  382. }
  383. namespace
  384. qvm_detail
  385. {
  386. template <int D>
  387. struct minus_v_defined;
  388. template <>
  389. struct
  390. minus_v_defined<2>
  391. {
  392. static bool const value=true;
  393. };
  394. }
  395. template <class A>
  396. BOOST_QVM_INLINE_OPERATIONS
  397. typename enable_if_c<
  398. is_vec<A>::value && vec_traits<A>::dim==2,
  399. typename vec_traits<A>::scalar_type>::type
  400. mag( A const & a )
  401. {
  402. typedef typename vec_traits<A>::scalar_type T;
  403. T const a0=vec_traits<A>::template read_element<0>(a);
  404. T const a1=vec_traits<A>::template read_element<1>(a);
  405. T const m2=a0*a0+a1*a1;
  406. T const mag=sqrt<T>(m2);
  407. return mag;
  408. }
  409. namespace
  410. sfinae
  411. {
  412. using ::boost::qvm::mag;
  413. }
  414. namespace
  415. qvm_detail
  416. {
  417. template <int D>
  418. struct mag_v_defined;
  419. template <>
  420. struct
  421. mag_v_defined<2>
  422. {
  423. static bool const value=true;
  424. };
  425. }
  426. template <class A>
  427. BOOST_QVM_INLINE_OPERATIONS
  428. typename enable_if_c<
  429. is_vec<A>::value && vec_traits<A>::dim==2,
  430. typename vec_traits<A>::scalar_type>::type
  431. mag_sqr( A const & a )
  432. {
  433. typedef typename vec_traits<A>::scalar_type T;
  434. T const a0=vec_traits<A>::template read_element<0>(a);
  435. T const a1=vec_traits<A>::template read_element<1>(a);
  436. T const m2=a0*a0+a1*a1;
  437. return m2;
  438. }
  439. namespace
  440. sfinae
  441. {
  442. using ::boost::qvm::mag_sqr;
  443. }
  444. namespace
  445. qvm_detail
  446. {
  447. template <int D>
  448. struct mag_sqr_v_defined;
  449. template <>
  450. struct
  451. mag_sqr_v_defined<2>
  452. {
  453. static bool const value=true;
  454. };
  455. }
  456. template <class A>
  457. BOOST_QVM_INLINE_OPERATIONS
  458. typename lazy_enable_if_c<
  459. vec_traits<A>::dim==2,
  460. deduce_vec<A> >::type
  461. normalized( A const & a )
  462. {
  463. typedef typename vec_traits<A>::scalar_type T;
  464. T const a0=vec_traits<A>::template read_element<0>(a);
  465. T const a1=vec_traits<A>::template read_element<1>(a);
  466. T const m2=a0*a0+a1*a1;
  467. if( m2==scalar_traits<typename vec_traits<A>::scalar_type>::value(0) )
  468. BOOST_QVM_THROW_EXCEPTION(zero_magnitude_error());
  469. T const rm=scalar_traits<T>::value(1)/sqrt<T>(m2);
  470. typedef typename deduce_vec<A>::type R;
  471. R r;
  472. vec_traits<R>::template write_element<0>(r)=a0*rm;
  473. vec_traits<R>::template write_element<1>(r)=a1*rm;
  474. return r;
  475. }
  476. namespace
  477. sfinae
  478. {
  479. using ::boost::qvm::normalized;
  480. }
  481. template <class A>
  482. BOOST_QVM_INLINE_OPERATIONS
  483. typename enable_if_c<
  484. vec_traits<A>::dim==2,
  485. void>::type
  486. normalize( A & a )
  487. {
  488. typedef typename vec_traits<A>::scalar_type T;
  489. T const a0=vec_traits<A>::template read_element<0>(a);
  490. T const a1=vec_traits<A>::template read_element<1>(a);
  491. T const m2=a0*a0+a1*a1;
  492. if( m2==scalar_traits<typename vec_traits<A>::scalar_type>::value(0) )
  493. BOOST_QVM_THROW_EXCEPTION(zero_magnitude_error());
  494. T const rm=scalar_traits<T>::value(1)/sqrt<T>(m2);
  495. vec_traits<A>::template write_element<0>(a)*=rm;
  496. vec_traits<A>::template write_element<1>(a)*=rm;
  497. }
  498. namespace
  499. sfinae
  500. {
  501. using ::boost::qvm::normalize;
  502. }
  503. namespace
  504. qvm_detail
  505. {
  506. template <int D>
  507. struct normalize_v_defined;
  508. template <>
  509. struct
  510. normalize_v_defined<2>
  511. {
  512. static bool const value=true;
  513. };
  514. }
  515. template <class A,class B>
  516. BOOST_QVM_INLINE_OPERATIONS
  517. typename lazy_enable_if_c<
  518. vec_traits<A>::dim==2 && vec_traits<B>::dim==2,
  519. deduce_scalar<typename vec_traits<A>::scalar_type,typename vec_traits<B>::scalar_type> >::type
  520. dot( A const & a, B const & b )
  521. {
  522. typedef typename vec_traits<A>::scalar_type Ta;
  523. typedef typename vec_traits<B>::scalar_type Tb;
  524. typedef typename deduce_scalar<Ta,Tb>::type Tr;
  525. Ta const a0=vec_traits<A>::template read_element<0>(a);
  526. Ta const a1=vec_traits<A>::template read_element<1>(a);
  527. Tb const b0=vec_traits<B>::template read_element<0>(b);
  528. Tb const b1=vec_traits<B>::template read_element<1>(b);
  529. Tr const dot=a0*b0+a1*b1;
  530. return dot;
  531. }
  532. namespace
  533. sfinae
  534. {
  535. using ::boost::qvm::dot;
  536. }
  537. namespace
  538. qvm_detail
  539. {
  540. template <int D>
  541. struct dot_vv_defined;
  542. template <>
  543. struct
  544. dot_vv_defined<2>
  545. {
  546. static bool const value=true;
  547. };
  548. }
  549. } }
  550. #endif