gtx_range.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <glm/gtc/constants.hpp>
  2. #include <glm/ext/scalar_relational.hpp>
  3. #include <glm/ext/vector_relational.hpp>
  4. #include <glm/glm.hpp>
  5. #define GLM_ENABLE_EXPERIMENTAL
  6. #include <glm/gtx/range.hpp>
  7. static int test_vec()
  8. {
  9. int Error = 0;
  10. {
  11. glm::ivec3 const v(1, 2, 3);
  12. int count = 0;
  13. glm::ivec3 Result(0);
  14. for(int x : v)
  15. {
  16. Result[count] = x;
  17. count++;
  18. }
  19. Error += count == 3 ? 0 : 1;
  20. Error += v == Result ? 0 : 1;
  21. }
  22. {
  23. glm::ivec3 v(1, 2, 3);
  24. for(int& x : v)
  25. x = 0;
  26. Error += glm::all(glm::equal(v, glm::ivec3(0))) ? 0 : 1;
  27. }
  28. return Error;
  29. }
  30. static int test_mat()
  31. {
  32. int Error = 0;
  33. {
  34. glm::mat4x3 m(1.0f);
  35. int count = 0;
  36. float Sum = 0.0f;
  37. for(float x : m)
  38. {
  39. count++;
  40. Sum += x;
  41. }
  42. Error += count == 12 ? 0 : 1;
  43. Error += glm::equal(Sum, 3.0f, 0.001f) ? 0 : 1;
  44. }
  45. {
  46. glm::mat4x3 m(1.0f);
  47. for (float& x : m) { x = 0; }
  48. glm::vec4 v(1, 1, 1, 1);
  49. Error += glm::all(glm::equal(m*v, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
  50. }
  51. return Error;
  52. }
  53. int main()
  54. {
  55. int Error = 0;
  56. Error += test_vec();
  57. Error += test_mat();
  58. return Error;
  59. }