Collection of DPF-based plugins for packaging
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.

127 lines
3.4KB

  1. /// @ref gtx_common
  2. /// @file glm/gtx/common.inl
  3. #include <cmath>
  4. #include "../gtc/epsilon.hpp"
  5. #include "../gtc/constants.hpp"
  6. namespace glm{
  7. namespace detail
  8. {
  9. template<length_t L, typename T, qualifier Q, bool isFloat = true>
  10. struct compute_fmod
  11. {
  12. GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
  13. {
  14. return detail::functor2<L, T, Q>::call(std::fmod, a, b);
  15. }
  16. };
  17. template<length_t L, typename T, qualifier Q>
  18. struct compute_fmod<L, T, Q, false>
  19. {
  20. GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
  21. {
  22. return a % b;
  23. }
  24. };
  25. }//namespace detail
  26. template<typename T>
  27. GLM_FUNC_QUALIFIER bool isdenormal(T const& x)
  28. {
  29. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  30. # if GLM_HAS_CXX11_STL
  31. return std::fpclassify(x) == FP_SUBNORMAL;
  32. # else
  33. return epsilonNotEqual(x, static_cast<T>(0), epsilon<T>()) && std::fabs(x) < std::numeric_limits<T>::min();
  34. # endif
  35. }
  36. template<typename T, qualifier Q>
  37. GLM_FUNC_QUALIFIER typename vec<1, T, Q>::bool_type isdenormal
  38. (
  39. vec<1, T, Q> const& x
  40. )
  41. {
  42. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  43. return typename vec<1, T, Q>::bool_type(
  44. isdenormal(x.x));
  45. }
  46. template<typename T, qualifier Q>
  47. GLM_FUNC_QUALIFIER typename vec<2, T, Q>::bool_type isdenormal
  48. (
  49. vec<2, T, Q> const& x
  50. )
  51. {
  52. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  53. return typename vec<2, T, Q>::bool_type(
  54. isdenormal(x.x),
  55. isdenormal(x.y));
  56. }
  57. template<typename T, qualifier Q>
  58. GLM_FUNC_QUALIFIER typename vec<3, T, Q>::bool_type isdenormal
  59. (
  60. vec<3, T, Q> const& x
  61. )
  62. {
  63. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  64. return typename vec<3, T, Q>::bool_type(
  65. isdenormal(x.x),
  66. isdenormal(x.y),
  67. isdenormal(x.z));
  68. }
  69. template<typename T, qualifier Q>
  70. GLM_FUNC_QUALIFIER typename vec<4, T, Q>::bool_type isdenormal
  71. (
  72. vec<4, T, Q> const& x
  73. )
  74. {
  75. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  76. return typename vec<4, T, Q>::bool_type(
  77. isdenormal(x.x),
  78. isdenormal(x.y),
  79. isdenormal(x.z),
  80. isdenormal(x.w));
  81. }
  82. // fmod
  83. template<typename genType>
  84. GLM_FUNC_QUALIFIER genType fmod(genType x, genType y)
  85. {
  86. return fmod(vec<1, genType>(x), y).x;
  87. }
  88. template<length_t L, typename T, qualifier Q>
  89. GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, T y)
  90. {
  91. return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, vec<L, T, Q>(y));
  92. }
  93. template<length_t L, typename T, qualifier Q>
  94. GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
  95. {
  96. return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, y);
  97. }
  98. template <length_t L, typename T, qualifier Q>
  99. GLM_FUNC_QUALIFIER vec<L, bool, Q> openBounded(vec<L, T, Q> const& Value, vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
  100. {
  101. return greaterThan(Value, Min) && lessThan(Value, Max);
  102. }
  103. template <length_t L, typename T, qualifier Q>
  104. GLM_FUNC_QUALIFIER vec<L, bool, Q> closeBounded(vec<L, T, Q> const& Value, vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
  105. {
  106. return greaterThanEqual(Value, Min) && lessThanEqual(Value, Max);
  107. }
  108. }//namespace glm