quat_traits_array.hpp 2.4 KB

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