func_vector_relational.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. namespace test{
  15. void main_core_func_vector_relational();
  16. }//namespace test
  17. namespace core{
  18. namespace function{
  19. //! Define vector relational functions from Section 8.3 of GLSL 1.30.8 specification.
  20. //! Included in glm namespace.
  21. namespace vector_relational
  22. {
  23. /// \addtogroup core_funcs
  24. ///@{
  25. //! Returns the component-wise comparison result of x < y.
  26. //! (From GLSL 1.30.08 specification, section 8.6)
  27. template <typename T, template <typename> class vecType>
  28. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type lessThan
  29. (
  30. vecType<T> const & x,
  31. vecType<T> const & y
  32. )
  33. {
  34. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  35. "Invalid template instantiation of 'lessThan', GLM vector types required");
  36. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  37. "Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors");
  38. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  39. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  40. Result[i] = x[i] < y[i];
  41. return Result;
  42. }
  43. //! Returns the component-wise comparison of result x <= y.
  44. //! (From GLSL 1.30.08 specification, section 8.6)
  45. template <typename T, template <typename> class vecType>
  46. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type lessThanEqual
  47. (
  48. vecType<T> const & x,
  49. vecType<T> const & y
  50. )
  51. {
  52. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  53. "Invalid template instantiation of 'lessThanEqual', GLM vector types required");
  54. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  55. "Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors");
  56. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  57. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  58. Result[i] = x[i] <= y[i];
  59. return Result;
  60. }
  61. //! Returns the component-wise comparison of result x > y.
  62. //! (From GLSL 1.30.08 specification, section 8.6)
  63. template <typename T, template <typename> class vecType>
  64. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type greaterThan
  65. (
  66. vecType<T> const & x,
  67. vecType<T> const & y
  68. )
  69. {
  70. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  71. "Invalid template instantiation of 'greaterThan', GLM vector types required");
  72. GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
  73. "Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors");
  74. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  75. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  76. Result[i] = x[i] > y[i];
  77. return Result;
  78. }
  79. //! Returns the component-wise comparison of result x >= y.
  80. //! (From GLSL 1.30.08 specification, section 8.6)
  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. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  93. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  94. Result[i] = x[i] >= y[i];
  95. return Result;
  96. }
  97. //! Returns the component-wise comparison of result x == y.
  98. //! (From GLSL 1.30.08 specification, section 8.6)
  99. template <typename T, template <typename> class vecType>
  100. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type equal
  101. (
  102. vecType<T> const & x,
  103. vecType<T> const & y
  104. )
  105. {
  106. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  107. "Invalid template instantiation of 'equal', GLM vector types required");
  108. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  109. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  110. Result[i] = x[i] == y[i];
  111. return Result;
  112. }
  113. //! Returns the component-wise comparison of result x != y.
  114. //! (From GLSL 1.30.08 specification, section 8.6)
  115. template <typename T, template <typename> class vecType>
  116. GLM_FUNC_QUALIFIER typename vecType<T>::bool_type notEqual
  117. (
  118. vecType<T> const & x,
  119. vecType<T> const & y
  120. )
  121. {
  122. GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
  123. "Invalid template instantiation of 'notEqual', GLM vector types required");
  124. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  125. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  126. Result[i] = x[i] != y[i];
  127. return Result;
  128. }
  129. //! Returns true if any component of x is true.
  130. //! (From GLSL 1.30.08 specification, section 8.6)
  131. template <template <typename> class vecType>
  132. GLM_FUNC_QUALIFIER bool any(vecType<bool> const & v)
  133. {
  134. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  135. "Invalid template instantiation of 'any', GLM boolean vector types required");
  136. bool Result = false;
  137. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  138. Result = Result || v[i];
  139. return Result;
  140. }
  141. //! Returns true if all components of x are true.
  142. //! (From GLSL 1.30.08 specification, section 8.6)
  143. template <template <typename> class vecType>
  144. GLM_FUNC_QUALIFIER bool all(vecType<bool> const & v)
  145. {
  146. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  147. "Invalid template instantiation of 'all', GLM boolean vector types required");
  148. bool Result = true;
  149. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  150. Result = Result && v[i];
  151. return Result;
  152. }
  153. //! Returns the component-wise logical complement of x.
  154. //! (From GLSL 1.30.08 specification, section 8.6)
  155. template <template <typename> class vecType>
  156. GLM_FUNC_QUALIFIER vecType<bool> not_(vecType<bool> const & v)
  157. {
  158. GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
  159. "Invalid template instantiation of 'not_', GLM vector types required");
  160. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  161. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  162. Result[i] = !v[i];
  163. return Result;
  164. }
  165. ///@}
  166. }//namespace vector_relational
  167. }//namespace function
  168. }//namespace core
  169. using namespace core::function::vector_relational;
  170. }//namespace glm
  171. #include "func_vector_relational.inl"
  172. #endif//glm_core_func_vector_relational