quat_traits_array.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //Copyright (c) 2008-2016 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 UUID_6D6B1EE2119A11E291554FEE6188709B
  5. #define UUID_6D6B1EE2119A11E291554FEE6188709B
  6. #include <boost/qvm/inline.hpp>
  7. #include <boost/qvm/deduce_quat.hpp>
  8. #include <boost/qvm/detail/remove_const.hpp>
  9. #include <boost/qvm/assert.hpp>
  10. namespace
  11. boost
  12. {
  13. namespace
  14. qvm
  15. {
  16. template <class T,int D>
  17. struct
  18. quat_traits<T[D]>
  19. {
  20. typedef void scalar_type;
  21. };
  22. template <class T,int D>
  23. struct
  24. quat_traits<T[D][4]>
  25. {
  26. typedef void scalar_type;
  27. };
  28. template <class T,int D>
  29. struct
  30. quat_traits<T[4][D]>
  31. {
  32. typedef void scalar_type;
  33. };
  34. template <class T>
  35. struct
  36. quat_traits<T[4][4]>
  37. {
  38. typedef void scalar_type;
  39. };
  40. template <class T,int M,int N>
  41. struct
  42. quat_traits<T[M][N]>
  43. {
  44. typedef void scalar_type;
  45. };
  46. template <class T>
  47. struct
  48. quat_traits<T[4]>
  49. {
  50. typedef T this_quaternion[4];
  51. typedef typename qvm_detail::remove_const<T>::type scalar_type;
  52. template <int I>
  53. static
  54. BOOST_QVM_INLINE_CRITICAL
  55. scalar_type
  56. read_element( this_quaternion const & x )
  57. {
  58. BOOST_QVM_STATIC_ASSERT(I>=0);
  59. BOOST_QVM_STATIC_ASSERT(I<4);
  60. return x[I];
  61. }
  62. template <int I>
  63. static
  64. BOOST_QVM_INLINE_CRITICAL
  65. scalar_type &
  66. write_element( this_quaternion & x )
  67. {
  68. BOOST_QVM_STATIC_ASSERT(I>=0);
  69. BOOST_QVM_STATIC_ASSERT(I<4);
  70. return x[I];
  71. }
  72. static
  73. BOOST_QVM_INLINE_CRITICAL
  74. scalar_type
  75. read_element_idx( int i, this_quaternion const & x )
  76. {
  77. BOOST_QVM_ASSERT(i>=0);
  78. BOOST_QVM_ASSERT(i<4);
  79. return x[i];
  80. }
  81. static
  82. BOOST_QVM_INLINE_CRITICAL
  83. scalar_type &
  84. write_element_idx( int i, this_quaternion & x )
  85. {
  86. BOOST_QVM_ASSERT(i>=0);
  87. BOOST_QVM_ASSERT(i<4);
  88. return x[i];
  89. }
  90. };
  91. template <class T>
  92. struct
  93. deduce_quat<T[4]>
  94. {
  95. typedef quat<T> type;
  96. };
  97. template <class T>
  98. struct
  99. deduce_quat<T const[4]>
  100. {
  101. typedef quat<T> type;
  102. };
  103. template <class T1,class T2>
  104. struct
  105. deduce_quat2<T1[4],T2[4]>
  106. {
  107. typedef quat<typename deduce_scalar<T1,T2>::type> type;
  108. };
  109. template <class T>
  110. T (&ptr_qref( T * ptr ))[4]
  111. {
  112. return *reinterpret_cast<T (*)[4]>(ptr);
  113. }
  114. }
  115. }
  116. #endif