ext_matrix_relational.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include <glm/ext/matrix_relational.hpp>
  2. #include <glm/ext/matrix_double2x2.hpp>
  3. #include <glm/ext/matrix_double2x3.hpp>
  4. #include <glm/ext/matrix_double2x4.hpp>
  5. #include <glm/ext/matrix_double3x2.hpp>
  6. #include <glm/ext/matrix_double3x3.hpp>
  7. #include <glm/ext/matrix_double3x4.hpp>
  8. #include <glm/ext/matrix_double4x2.hpp>
  9. #include <glm/ext/matrix_double4x3.hpp>
  10. #include <glm/ext/matrix_double4x4.hpp>
  11. #include <glm/ext/vector_double2.hpp>
  12. #include <glm/ext/vector_double3.hpp>
  13. #include <glm/ext/vector_double4.hpp>
  14. #include <glm/ext/matrix_float2x2.hpp>
  15. #include <glm/ext/matrix_float2x3.hpp>
  16. #include <glm/ext/matrix_float2x4.hpp>
  17. #include <glm/ext/matrix_float3x2.hpp>
  18. #include <glm/ext/matrix_float3x3.hpp>
  19. #include <glm/ext/matrix_float3x4.hpp>
  20. #include <glm/ext/matrix_float4x2.hpp>
  21. #include <glm/ext/matrix_float4x3.hpp>
  22. #include <glm/ext/matrix_float4x4.hpp>
  23. #include <glm/ext/vector_float2.hpp>
  24. #include <glm/ext/vector_float3.hpp>
  25. #include <glm/ext/vector_float4.hpp>
  26. #include <glm/ext/scalar_ulp.hpp>
  27. template <typename matType, typename vecType>
  28. static int test_equal()
  29. {
  30. typedef typename matType::value_type valType;
  31. valType const Epsilon = static_cast<valType>(0.001f);
  32. valType const One = static_cast<valType>(1);
  33. valType const Two = static_cast<valType>(2);
  34. int Error = 0;
  35. Error += glm::all(glm::equal(matType(One), matType(One), Epsilon)) ? 0 : 1;
  36. Error += glm::all(glm::equal(matType(One), matType(Two), vecType(Epsilon))) ? 1 : 0;
  37. return Error;
  38. }
  39. template <typename matType, typename vecType>
  40. static int test_notEqual()
  41. {
  42. typedef typename matType::value_type valType;
  43. valType const Epsilon = static_cast<valType>(0.001f);
  44. valType const One = static_cast<valType>(1);
  45. valType const Two = static_cast<valType>(2);
  46. int Error = 0;
  47. Error += !glm::any(glm::notEqual(matType(One), matType(One), Epsilon)) ? 0 : 1;
  48. Error += !glm::any(glm::notEqual(matType(One), matType(Two), vecType(Epsilon))) ? 1 : 0;
  49. return Error;
  50. }
  51. template <typename T>
  52. static int test_equal_ulps()
  53. {
  54. typedef glm::mat<4, 4, T, glm::defaultp> mat4;
  55. T const One(1);
  56. mat4 const Ones(1);
  57. int Error = 0;
  58. T const ULP1Plus = glm::nextFloat(One);
  59. Error += glm::all(glm::equal(Ones, mat4(ULP1Plus), 1)) ? 0 : 1;
  60. T const ULP2Plus = glm::nextFloat(ULP1Plus);
  61. Error += !glm::all(glm::equal(Ones, mat4(ULP2Plus), 1)) ? 0 : 1;
  62. T const ULP1Minus = glm::prevFloat(One);
  63. Error += glm::all(glm::equal(Ones, mat4(ULP1Minus), 1)) ? 0 : 1;
  64. T const ULP2Minus = glm::prevFloat(ULP1Minus);
  65. Error += !glm::all(glm::equal(Ones, mat4(ULP2Minus), 1)) ? 0 : 1;
  66. return Error;
  67. }
  68. template <typename T>
  69. static int test_notEqual_ulps()
  70. {
  71. typedef glm::mat<4, 4, T, glm::defaultp> mat4;
  72. T const One(1);
  73. mat4 const Ones(1);
  74. int Error = 0;
  75. T const ULP1Plus = glm::nextFloat(One);
  76. Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Plus), 1)) ? 0 : 1;
  77. T const ULP2Plus = glm::nextFloat(ULP1Plus);
  78. Error += glm::all(glm::notEqual(Ones, mat4(ULP2Plus), 1)) ? 0 : 1;
  79. T const ULP1Minus = glm::prevFloat(One);
  80. Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Minus), 1)) ? 0 : 1;
  81. T const ULP2Minus = glm::prevFloat(ULP1Minus);
  82. Error += glm::all(glm::notEqual(Ones, mat4(ULP2Minus), 1)) ? 0 : 1;
  83. return Error;
  84. }
  85. int main()
  86. {
  87. int Error = 0;
  88. Error += test_equal_ulps<float>();
  89. Error += test_equal_ulps<double>();
  90. Error += test_notEqual_ulps<float>();
  91. Error += test_notEqual_ulps<double>();
  92. Error += test_equal<glm::mat2x2, glm::vec2>();
  93. Error += test_equal<glm::mat2x3, glm::vec2>();
  94. Error += test_equal<glm::mat2x4, glm::vec2>();
  95. Error += test_equal<glm::mat3x2, glm::vec3>();
  96. Error += test_equal<glm::mat3x3, glm::vec3>();
  97. Error += test_equal<glm::mat3x4, glm::vec3>();
  98. Error += test_equal<glm::mat4x2, glm::vec4>();
  99. Error += test_equal<glm::mat4x3, glm::vec4>();
  100. Error += test_equal<glm::mat4x4, glm::vec4>();
  101. Error += test_equal<glm::dmat2x2, glm::dvec2>();
  102. Error += test_equal<glm::dmat2x3, glm::dvec2>();
  103. Error += test_equal<glm::dmat2x4, glm::dvec2>();
  104. Error += test_equal<glm::dmat3x2, glm::dvec3>();
  105. Error += test_equal<glm::dmat3x3, glm::dvec3>();
  106. Error += test_equal<glm::dmat3x4, glm::dvec3>();
  107. Error += test_equal<glm::dmat4x2, glm::dvec4>();
  108. Error += test_equal<glm::dmat4x3, glm::dvec4>();
  109. Error += test_equal<glm::dmat4x4, glm::dvec4>();
  110. Error += test_notEqual<glm::mat2x2, glm::vec2>();
  111. Error += test_notEqual<glm::mat2x3, glm::vec2>();
  112. Error += test_notEqual<glm::mat2x4, glm::vec2>();
  113. Error += test_notEqual<glm::mat3x2, glm::vec3>();
  114. Error += test_notEqual<glm::mat3x3, glm::vec3>();
  115. Error += test_notEqual<glm::mat3x4, glm::vec3>();
  116. Error += test_notEqual<glm::mat4x2, glm::vec4>();
  117. Error += test_notEqual<glm::mat4x3, glm::vec4>();
  118. Error += test_notEqual<glm::mat4x4, glm::vec4>();
  119. Error += test_notEqual<glm::dmat2x2, glm::dvec2>();
  120. Error += test_notEqual<glm::dmat2x3, glm::dvec2>();
  121. Error += test_notEqual<glm::dmat2x4, glm::dvec2>();
  122. Error += test_notEqual<glm::dmat3x2, glm::dvec3>();
  123. Error += test_notEqual<glm::dmat3x3, glm::dvec3>();
  124. Error += test_notEqual<glm::dmat3x4, glm::dvec3>();
  125. Error += test_notEqual<glm::dmat4x2, glm::dvec4>();
  126. Error += test_notEqual<glm::dmat4x3, glm::dvec4>();
  127. Error += test_notEqual<glm::dmat4x4, glm::dvec4>();
  128. return Error;
  129. }