vec_operations4.hpp 17 KB

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