You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
6.5 KiB

4 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/func_vector_relational.inl
  25. /// @date 2008-08-03 / 2011-09-09
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. namespace glm
  29. {
  30. template <typename T, template <typename> class vecType>
  31. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type lessThan
  32. (
  33. vecType<T> const & x,
  34. vecType<T> const & y
  35. )
  36. {
  37. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  38. "Invalid template instantiation of 'lessThan', GLM vector types required");
  39. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  40. "Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors");
  41. assert(x.length() == y.length());
  42. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  43. for(typename vecType<bool>::size_type i = 0; i < x.length(); ++i)
  44. Result[i] = x[i] < y[i];
  45. return Result;
  46. }
  47. template <typename T, template <typename> class vecType>
  48. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type lessThanEqual
  49. (
  50. vecType<T> const & x,
  51. vecType<T> const & y
  52. )
  53. {
  54. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  55. "Invalid template instantiation of 'lessThanEqual', GLM vector types required");
  56. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  57. "Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors");
  58. assert(x.length() == y.length());
  59. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  60. for(typename vecType<bool>::size_type i = 0; i < x.length(); ++i)
  61. Result[i] = x[i] <= y[i];
  62. return Result;
  63. }
  64. template <typename T, template <typename> class vecType>
  65. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type greaterThan
  66. (
  67. vecType<T> const & x,
  68. vecType<T> const & y
  69. )
  70. {
  71. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  72. "Invalid template instantiation of 'greaterThan', GLM vector types required");
  73. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  74. "Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors");
  75. assert(x.length() == y.length());
  76. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  77. for(typename vecType<bool>::size_type i = 0; i < x.length(); ++i)
  78. Result[i] = x[i] > y[i];
  79. return Result;
  80. }
  81. template <typename T, template <typename> class vecType>
  82. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type greaterThanEqual
  83. (
  84. vecType<T> const & x,
  85. vecType<T> const & y
  86. )
  87. {
  88. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  89. "Invalid template instantiation of 'greaterThanEqual', GLM vector types required");
  90. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  91. "Invalid template instantiation of 'greaterThanEqual', GLM vector types required floating-point or integer value types vectors");
  92. assert(x.length() == y.length());
  93. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  94. for(typename vecType<bool>::size_type i = 0; i < x.length(); ++i)
  95. Result[i] = x[i] >= y[i];
  96. return Result;
  97. }
  98. template <typename T, template <typename> class vecType>
  99. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type equal
  100. (
  101. vecType<T> const & x,
  102. vecType<T> const & y
  103. )
  104. {
  105. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  106. "Invalid template instantiation of 'equal', GLM vector types required");
  107. assert(x.length() == y.length());
  108. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  109. for(typename vecType<bool>::size_type i = 0; i < x.length(); ++i)
  110. Result[i] = x[i] == y[i];
  111. return Result;
  112. }
  113. template <typename T, template <typename> class vecType>
  114. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type notEqual
  115. (
  116. vecType<T> const & x,
  117. vecType<T> const & y
  118. )
  119. {
  120. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  121. "Invalid template instantiation of 'notEqual', GLM vector types required");
  122. assert(x.length() == y.length());
  123. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  124. for(typename vecType<bool>::size_type i = 0; i < x.length(); ++i)
  125. Result[i] = x[i] != y[i];
  126. return Result;
  127. }
  128. template <template <typename> class vecType>
  129. GLM_FUNC_QUALIFIER bool any(vecType<bool> const & v)
  130. {
  131. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  132. "Invalid template instantiation of 'any', GLM boolean vector types required");
  133. bool Result = false;
  134. for(typename vecType<bool>::size_type i = 0; i < v.length(); ++i)
  135. Result = Result || v[i];
  136. return Result;
  137. }
  138. template <template <typename> class vecType>
  139. GLM_FUNC_QUALIFIER bool all(vecType<bool> const & v)
  140. {
  141. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  142. "Invalid template instantiation of 'all', GLM boolean vector types required");
  143. bool Result = true;
  144. for(typename vecType<bool>::size_type i = 0; i < v.length(); ++i)
  145. Result = Result && v[i];
  146. return Result;
  147. }
  148. template <template <typename> class vecType>
  149. GLM_FUNC_QUALIFIER vecType<bool> not_(vecType<bool> const & v)
  150. {
  151. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  152. "Invalid template instantiation of 'not_', GLM vector types required");
  153. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  154. for(typename vecType<bool>::size_type i = 0; i < v.length(); ++i)
  155. Result[i] = !v[i];
  156. return Result;
  157. }
  158. }//namespace glm