vec_operations3.hpp 15 KB

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