func_vector_relational.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2010 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. namespace glm
  12. {
  13. namespace test{
  14. void main_core_func_vector_relational();
  15. }//namespace test
  16. namespace core{
  17. namespace function{
  18. //! Define vector relational functions from Section 8.3 of GLSL 1.30.8 specification.
  19. //! Included in glm namespace.
  20. namespace vector_relational
  21. {
  22. //! Returns the component-wise comparison result of x < y.
  23. //! (From GLSL 1.30.08 specification, section 8.6)
  24. template <typename T, template <typename> class vecType>
  25. inline typename vecType<T>::bool_type lessThan
  26. (
  27. vecType<T> const & x,
  28. vecType<T> const & y
  29. )
  30. {
  31. GLM_STATIC_ASSERT(
  32. detail::type<T>::is_float ||
  33. detail::type<T>::is_int ||
  34. detail::type<T>::is_uint);
  35. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  36. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  37. Result[i] = x[i] < y[i];
  38. return Result;
  39. }
  40. //! Returns the component-wise comparison of result x <= y.
  41. //! (From GLSL 1.30.08 specification, section 8.6)
  42. template <typename T, template <typename> class vecType>
  43. inline typename vecType<T>::bool_type lessThanEqual
  44. (
  45. vecType<T> const & x,
  46. vecType<T> const & y
  47. )
  48. {
  49. GLM_STATIC_ASSERT(
  50. detail::type<T>::is_float ||
  51. detail::type<T>::is_int ||
  52. detail::type<T>::is_uint);
  53. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  54. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  55. Result[i] = x[i] <= y[i];
  56. return Result;
  57. }
  58. //! Returns the component-wise comparison of result x > y.
  59. //! (From GLSL 1.30.08 specification, section 8.6)
  60. template <typename T, template <typename> class vecType>
  61. inline typename vecType<T>::bool_type greaterThan
  62. (
  63. vecType<T> const & x,
  64. vecType<T> const & y
  65. )
  66. {
  67. GLM_STATIC_ASSERT(
  68. detail::type<T>::is_float ||
  69. detail::type<T>::is_int ||
  70. detail::type<T>::is_uint);
  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. //! (From GLSL 1.30.08 specification, section 8.6)
  78. template <typename T, template <typename> class vecType>
  79. inline typename vecType<T>::bool_type greaterThanEqual
  80. (
  81. vecType<T> const & x,
  82. vecType<T> const & y
  83. )
  84. {
  85. GLM_STATIC_ASSERT(
  86. detail::type<T>::is_float ||
  87. detail::type<T>::is_int ||
  88. detail::type<T>::is_uint);
  89. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  90. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  91. Result[i] = x[i] >= y[i];
  92. return Result;
  93. }
  94. //! Returns the component-wise comparison of result x == y.
  95. //! (From GLSL 1.30.08 specification, section 8.6)
  96. template <typename T, template <typename> class vecType>
  97. inline typename vecType<T>::bool_type equal
  98. (
  99. vecType<T> const & x,
  100. vecType<T> const & y
  101. )
  102. {
  103. GLM_STATIC_ASSERT(
  104. detail::type<T>::is_float ||
  105. detail::type<T>::is_int ||
  106. detail::type<T>::is_uint ||
  107. detail::type<T>::is_bool);
  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. inline typename vecType<T>::bool_type notEqual
  117. (
  118. vecType<T> const & x,
  119. vecType<T> const & y
  120. )
  121. {
  122. GLM_STATIC_ASSERT(
  123. detail::type<T>::is_float ||
  124. detail::type<T>::is_int ||
  125. detail::type<T>::is_uint ||
  126. detail::type<T>::is_bool);
  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. //! (From GLSL 1.30.08 specification, section 8.6)
  134. template <template <typename> class vecType>
  135. inline bool any(vecType<bool> const & v)
  136. {
  137. bool Result = false;
  138. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  139. Result = Result || v[i];
  140. return Result;
  141. }
  142. //! Returns true if all components of x are true.
  143. //! (From GLSL 1.30.08 specification, section 8.6)
  144. template <template <typename> class vecType>
  145. inline bool all(vecType<bool> const & v)
  146. {
  147. bool Result = true;
  148. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  149. Result = Result && v[i];
  150. return Result;
  151. }
  152. //! Returns the component-wise logical complement of x.
  153. //! (From GLSL 1.30.08 specification, section 8.6)
  154. template <template <typename> class vecType>
  155. inline vecType<bool> not_(vecType<bool> const & v)
  156. {
  157. typename vecType<bool>::bool_type Result(vecType<bool>::null);
  158. for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
  159. Result[i] = !v[i];
  160. return Result;
  161. }
  162. }//namespace vector_relational
  163. }//namespace function
  164. }//namespace core
  165. using namespace core::function::vector_relational;
  166. }//namespace glm
  167. #include "func_vector_relational.inl"
  168. #endif//glm_core_func_vector_relational