9
3

epsilon.inl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /// @ref gtc_epsilon
  2. // Dependency:
  3. #include "../vector_relational.hpp"
  4. #include "../common.hpp"
  5. namespace glm
  6. {
  7. template<>
  8. GLM_FUNC_QUALIFIER bool epsilonEqual
  9. (
  10. float const& x,
  11. float const& y,
  12. float const& epsilon
  13. )
  14. {
  15. return abs(x - y) < epsilon;
  16. }
  17. template<>
  18. GLM_FUNC_QUALIFIER bool epsilonEqual
  19. (
  20. double const& x,
  21. double const& y,
  22. double const& epsilon
  23. )
  24. {
  25. return abs(x - y) < epsilon;
  26. }
  27. template<length_t L, typename T, qualifier Q>
  28. GLM_FUNC_QUALIFIER vec<L, bool, Q> epsilonEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T const& epsilon)
  29. {
  30. return lessThan(abs(x - y), vec<L, T, Q>(epsilon));
  31. }
  32. template<length_t L, typename T, qualifier Q>
  33. GLM_FUNC_QUALIFIER vec<L, bool, Q> epsilonEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon)
  34. {
  35. return lessThan(abs(x - y), vec<L, T, Q>(epsilon));
  36. }
  37. template<>
  38. GLM_FUNC_QUALIFIER bool epsilonNotEqual(float const& x, float const& y, float const& epsilon)
  39. {
  40. return abs(x - y) >= epsilon;
  41. }
  42. template<>
  43. GLM_FUNC_QUALIFIER bool epsilonNotEqual(double const& x, double const& y, double const& epsilon)
  44. {
  45. return abs(x - y) >= epsilon;
  46. }
  47. template<length_t L, typename T, qualifier Q>
  48. GLM_FUNC_QUALIFIER vec<L, bool, Q> epsilonNotEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T const& epsilon)
  49. {
  50. return greaterThanEqual(abs(x - y), vec<L, T, Q>(epsilon));
  51. }
  52. template<length_t L, typename T, qualifier Q>
  53. GLM_FUNC_QUALIFIER vec<L, bool, Q> epsilonNotEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& epsilon)
  54. {
  55. return greaterThanEqual(abs(x - y), vec<L, T, Q>(epsilon));
  56. }
  57. template<typename T, qualifier Q>
  58. GLM_FUNC_QUALIFIER vec<4, bool, Q> epsilonEqual(qua<T, Q> const& x, qua<T, Q> const& y, T const& epsilon)
  59. {
  60. vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w);
  61. return lessThan(abs(v), vec<4, T, Q>(epsilon));
  62. }
  63. template<typename T, qualifier Q>
  64. GLM_FUNC_QUALIFIER vec<4, bool, Q> epsilonNotEqual(qua<T, Q> const& x, qua<T, Q> const& y, T const& epsilon)
  65. {
  66. vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w);
  67. return greaterThanEqual(abs(v), vec<4, T, Q>(epsilon));
  68. }
  69. }//namespace glm