extended_min_max.inl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /// @ref gtx_extended_min_max
  2. namespace glm
  3. {
  4. template<typename T>
  5. GLM_FUNC_QUALIFIER T min(
  6. T const& x,
  7. T const& y,
  8. T const& z)
  9. {
  10. return glm::min(glm::min(x, y), z);
  11. }
  12. template<typename T, template<typename> class C>
  13. GLM_FUNC_QUALIFIER C<T> min
  14. (
  15. C<T> const& x,
  16. typename C<T>::T const& y,
  17. typename C<T>::T const& z
  18. )
  19. {
  20. return glm::min(glm::min(x, y), z);
  21. }
  22. template<typename T, template<typename> class C>
  23. GLM_FUNC_QUALIFIER C<T> min
  24. (
  25. C<T> const& x,
  26. C<T> const& y,
  27. C<T> const& z
  28. )
  29. {
  30. return glm::min(glm::min(x, y), z);
  31. }
  32. template<typename T>
  33. GLM_FUNC_QUALIFIER T min
  34. (
  35. T const& x,
  36. T const& y,
  37. T const& z,
  38. T const& w
  39. )
  40. {
  41. return glm::min(glm::min(x, y), glm::min(z, w));
  42. }
  43. template<typename T, template<typename> class C>
  44. GLM_FUNC_QUALIFIER C<T> min
  45. (
  46. C<T> const& x,
  47. typename C<T>::T const& y,
  48. typename C<T>::T const& z,
  49. typename C<T>::T const& w
  50. )
  51. {
  52. return glm::min(glm::min(x, y), glm::min(z, w));
  53. }
  54. template<typename T, template<typename> class C>
  55. GLM_FUNC_QUALIFIER C<T> min
  56. (
  57. C<T> const& x,
  58. C<T> const& y,
  59. C<T> const& z,
  60. C<T> const& w
  61. )
  62. {
  63. return glm::min(glm::min(x, y), glm::min(z, w));
  64. }
  65. template<typename T>
  66. GLM_FUNC_QUALIFIER T max(
  67. T const& x,
  68. T const& y,
  69. T const& z)
  70. {
  71. return glm::max(glm::max(x, y), z);
  72. }
  73. template<typename T, template<typename> class C>
  74. GLM_FUNC_QUALIFIER C<T> max
  75. (
  76. C<T> const& x,
  77. typename C<T>::T const& y,
  78. typename C<T>::T const& z
  79. )
  80. {
  81. return glm::max(glm::max(x, y), z);
  82. }
  83. template<typename T, template<typename> class C>
  84. GLM_FUNC_QUALIFIER C<T> max
  85. (
  86. C<T> const& x,
  87. C<T> const& y,
  88. C<T> const& z
  89. )
  90. {
  91. return glm::max(glm::max(x, y), z);
  92. }
  93. template<typename T>
  94. GLM_FUNC_QUALIFIER T max
  95. (
  96. T const& x,
  97. T const& y,
  98. T const& z,
  99. T const& w
  100. )
  101. {
  102. return glm::max(glm::max(x, y), glm::max(z, w));
  103. }
  104. template<typename T, template<typename> class C>
  105. GLM_FUNC_QUALIFIER C<T> max
  106. (
  107. C<T> const& x,
  108. typename C<T>::T const& y,
  109. typename C<T>::T const& z,
  110. typename C<T>::T const& w
  111. )
  112. {
  113. return glm::max(glm::max(x, y), glm::max(z, w));
  114. }
  115. template<typename T, template<typename> class C>
  116. GLM_FUNC_QUALIFIER C<T> max
  117. (
  118. C<T> const& x,
  119. C<T> const& y,
  120. C<T> const& z,
  121. C<T> const& w
  122. )
  123. {
  124. return glm::max(glm::max(x, y), glm::max(z, w));
  125. }
  126. // fmin
  127. # if GLM_HAS_CXX11_STL
  128. using std::fmin;
  129. # else
  130. template<typename genType>
  131. GLM_FUNC_QUALIFIER genType fmin(genType x, genType y)
  132. {
  133. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fmin' only accept floating-point input");
  134. if (isnan(x))
  135. return y;
  136. if (isnan(y))
  137. return x;
  138. return min(x, y);
  139. }
  140. # endif
  141. template<length_t L, typename T, qualifier Q>
  142. GLM_FUNC_QUALIFIER vec<L, T, Q> fmin(vec<L, T, Q> const& a, T b)
  143. {
  144. return detail::functor2<vec, L, T, Q>::call(fmin, a, vec<L, T, Q>(b));
  145. }
  146. template<length_t L, typename T, qualifier Q>
  147. GLM_FUNC_QUALIFIER vec<L, T, Q> fmin(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
  148. {
  149. return detail::functor2<vec, L, T, Q>::call(fmin, a, b);
  150. }
  151. // fmax
  152. # if GLM_HAS_CXX11_STL
  153. using std::fmax;
  154. # else
  155. template<typename genType>
  156. GLM_FUNC_QUALIFIER genType fmax(genType x, genType y)
  157. {
  158. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fmax' only accept floating-point input");
  159. if (isnan(x))
  160. return y;
  161. if (isnan(y))
  162. return x;
  163. return max(x, y);
  164. }
  165. # endif
  166. template<length_t L, typename T, qualifier Q>
  167. GLM_FUNC_QUALIFIER vec<L, T, Q> fmax(vec<L, T, Q> const& a, T b)
  168. {
  169. return detail::functor2<vec, L, T, Q>::call(fmax, a, vec<L, T, Q>(b));
  170. }
  171. template<length_t L, typename T, qualifier Q>
  172. GLM_FUNC_QUALIFIER vec<L, T, Q> fmax(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
  173. {
  174. return detail::functor2<vec, L, T, Q>::call(fmax, a, b);
  175. }
  176. // fclamp
  177. template<typename genType>
  178. GLM_FUNC_QUALIFIER genType fclamp(genType x, genType minVal, genType maxVal)
  179. {
  180. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fclamp' only accept floating-point or integer inputs");
  181. return fmin(fmax(x, minVal), maxVal);
  182. }
  183. template<length_t L, typename T, qualifier Q>
  184. GLM_FUNC_QUALIFIER vec<L, T, Q> fclamp(vec<L, T, Q> const& x, T minVal, T maxVal)
  185. {
  186. return fmin(fmax(x, vec<L, T, Q>(minVal)), vec<L, T, Q>(maxVal));
  187. }
  188. template<length_t L, typename T, qualifier Q>
  189. GLM_FUNC_QUALIFIER vec<L, T, Q> fclamp(vec<L, T, Q> const& x, vec<L, T, Q> const& minVal, vec<L, T, Q> const& maxVal)
  190. {
  191. return fmin(fmax(x, minVal), maxVal);
  192. }
  193. }//namespace glm