func_vector_relational.hpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2008-08-03
  5. // Updated : 2008-09-09
  6. // Licence : This source is under MIT License
  7. // File : glm/core/func_vector_relational.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef glm_core_func_vector_relational
  10. #define glm_core_func_vector_relational
  11. #include "_detail.hpp"
  12. namespace glm
  13. {
  14. /// \addtogroup core_funcs
  15. /// @{
  16. //! Returns the component-wise comparison result of x < y.
  17. //!
  18. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThan.xml">GLSL lessThan man page</a>
  19. //! \li GLSL 1.30.08 specification, section 8.6
  20. template <typename T, template <typename> class vecType>
  21. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type lessThan
  22. (
  23. vecType<T> const & x,
  24. vecType<T> const & y
  25. )
  26. {
  27. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  28. "Invalid template instantiation of 'lessThan', GLM vector types required");
  29. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  30. "Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors");
  31. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  32. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  33. Result[i] = x[i] < y[i];
  34. return Result;
  35. }
  36. //! Returns the component-wise comparison of result x <= y.
  37. //!
  38. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThanEqual.xml">GLSL lessThanEqual man page</a>
  39. //! \li GLSL 1.30.08 specification, section 8.6
  40. template <typename T, template <typename> class vecType>
  41. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type lessThanEqual
  42. (
  43. vecType<T> const & x,
  44. vecType<T> const & y
  45. )
  46. {
  47. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  48. "Invalid template instantiation of 'lessThanEqual', GLM vector types required");
  49. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  50. "Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors");
  51. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  52. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  53. Result[i] = x[i] <= y[i];
  54. return Result;
  55. }
  56. //! Returns the component-wise comparison of result x > y.
  57. //!
  58. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThan.xml">GLSL greaterThan man page</a>
  59. //! \li GLSL 1.30.08 specification, section 8.6
  60. template <typename T, template <typename> class vecType>
  61. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type greaterThan
  62. (
  63. vecType<T> const & x,
  64. vecType<T> const & y
  65. )
  66. {
  67. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  68. "Invalid template instantiation of 'greaterThan', GLM vector types required");
  69. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  70. "Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors");
  71. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  72. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  73. Result[i] = x[i] > y[i];
  74. return Result;
  75. }
  76. //! Returns the component-wise comparison of result x >= y.
  77. //!
  78. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThanEqual.xml">GLSL greaterThanEqual man page</a>
  79. //! \li GLSL 1.30.08 specification, section 8.6
  80. template <typename T, template <typename> class vecType>
  81. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type greaterThanEqual
  82. (
  83. vecType<T> const & x,
  84. vecType<T> const & y
  85. )
  86. {
  87. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  88. "Invalid template instantiation of 'greaterThanEqual', GLM vector types required");
  89. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  90. "Invalid template instantiation of 'greaterThanEqual', GLM vector types required floating-point or integer value types vectors");
  91. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  92. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  93. Result[i] = x[i] >= y[i];
  94. return Result;
  95. }
  96. //! Returns the component-wise comparison of result x == y.
  97. //!
  98. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/equal.xml">GLSL equal man page</a>
  99. //! \li GLSL 1.30.08 specification, section 8.6
  100. template <typename T, template <typename> class vecType>
  101. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type equal
  102. (
  103. vecType<T> const & x,
  104. vecType<T> const & y
  105. )
  106. {
  107. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  108. "Invalid template instantiation of 'equal', GLM vector types required");
  109. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  110. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  111. Result[i] = x[i] == y[i];
  112. return Result;
  113. }
  114. //! Returns the component-wise comparison of result x != y.
  115. //!
  116. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/notEqual.xml">GLSL notEqual man page</a>
  117. //! \li GLSL 1.30.08 specification, section 8.6
  118. template <typename T, template <typename> class vecType>
  119. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type notEqual
  120. (
  121. vecType<T> const & x,
  122. vecType<T> const & y
  123. )
  124. {
  125. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  126. "Invalid template instantiation of 'notEqual', GLM vector types required");
  127. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  128. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  129. Result[i] = x[i] != y[i];
  130. return Result;
  131. }
  132. //! Returns true if any component of x is true.
  133. //!
  134. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/any.xml">GLSL any man page</a>
  135. //! \li GLSL 1.30.08 specification, section 8.6
  136. template <template <typename> class vecType>
  137. GLM_FUNC_QUALIFIER bool any(vecType<bool> const & v)
  138. {
  139. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  140. "Invalid template instantiation of 'any', GLM boolean vector types required");
  141. bool Result = false;
  142. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  143. Result = Result || v[i];
  144. return Result;
  145. }
  146. //! Returns true if all components of x are true.
  147. //!
  148. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/all.xml">GLSL all man page</a>
  149. //! \li GLSL 1.30.08 specification, section 8.6
  150. template <template <typename> class vecType>
  151. GLM_FUNC_QUALIFIER bool all(vecType<bool> const & v)
  152. {
  153. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  154. "Invalid template instantiation of 'all', GLM boolean vector types required");
  155. bool Result = true;
  156. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  157. Result = Result && v[i];
  158. return Result;
  159. }
  160. //! Returns the component-wise logical complement of x.
  161. //! /!\ Because of language incompatibilities between C++ and GLSL, GLM defines the function not but not_ instead.
  162. //!
  163. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/not.xml">GLSL not man page</a>
  164. //! \li GLSL 1.30.08 specification, section 8.6
  165. template <template <typename> class vecType>
  166. GLM_FUNC_QUALIFIER vecType<bool> not_(vecType<bool> const & v)
  167. {
  168. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  169. "Invalid template instantiation of 'not_', GLM vector types required");
  170. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  171. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  172. Result[i] = !v[i];
  173. return Result;
  174. }
  175. /// @}
  176. }//namespace glm
  177. #include "func_vector_relational.inl"
  178. #endif//glm_core_func_vector_relational