ext_vec1.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #define GLM_FORCE_SWIZZLE
  2. #include <glm/vector_relational.hpp>
  3. #include <glm/gtc/vec1.hpp>
  4. #include <vector>
  5. #if GLM_COMPILER & GLM_COMPILER_CLANG
  6. # pragma clang diagnostic push
  7. # pragma clang diagnostic ignored "-Wglobal-constructors"
  8. # pragma clang diagnostic ignored "-Wunused-variable"
  9. #endif
  10. static glm::vec1 g1;
  11. static glm::vec1 g2(1);
  12. #if GLM_COMPILER & GLM_COMPILER_CLANG
  13. # pragma clang diagnostic pop
  14. #endif
  15. static int test_vec1_operators()
  16. {
  17. int Error(0);
  18. glm::ivec1 A(1);
  19. glm::ivec1 B(1);
  20. {
  21. bool R = A != B;
  22. bool S = A == B;
  23. Error += (S && !R) ? 0 : 1;
  24. }
  25. {
  26. A *= 1;
  27. B *= 1;
  28. A += 1;
  29. B += 1;
  30. bool R = A != B;
  31. bool S = A == B;
  32. Error += (S && !R) ? 0 : 1;
  33. }
  34. return Error;
  35. }
  36. static int test_vec1_ctor()
  37. {
  38. int Error = 0;
  39. {
  40. // Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
  41. // Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;
  42. Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1;
  43. Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1;
  44. Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1;
  45. Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1;
  46. Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1;
  47. }
  48. {
  49. glm::ivec1 A = glm::vec1(2.0f);
  50. glm::ivec1 E(glm::dvec1(2.0));
  51. Error += A == E ? 0 : 1;
  52. glm::ivec1 F(glm::ivec1(2));
  53. Error += A == F ? 0 : 1;
  54. }
  55. return Error;
  56. }
  57. static int test_vec1_size()
  58. {
  59. int Error = 0;
  60. Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1;
  61. Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1;
  62. Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1;
  63. Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
  64. Error += glm::vec1().length() == 1 ? 0 : 1;
  65. Error += glm::dvec1().length() == 1 ? 0 : 1;
  66. Error += glm::vec1::length() == 1 ? 0 : 1;
  67. Error += glm::dvec1::length() == 1 ? 0 : 1;
  68. GLM_CONSTEXPR glm::length_t Length = glm::vec1::length();
  69. Error += Length == 1 ? 0 : 1;
  70. return Error;
  71. }
  72. static int test_vec1_operator_increment()
  73. {
  74. int Error(0);
  75. glm::ivec1 v0(1);
  76. glm::ivec1 v1(v0);
  77. glm::ivec1 v2(v0);
  78. glm::ivec1 v3 = ++v1;
  79. glm::ivec1 v4 = v2++;
  80. Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
  81. Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
  82. Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
  83. int i0(1);
  84. int i1(i0);
  85. int i2(i0);
  86. int i3 = ++i1;
  87. int i4 = i2++;
  88. Error += i0 == i4 ? 0 : 1;
  89. Error += i1 == i2 ? 0 : 1;
  90. Error += i1 == i3 ? 0 : 1;
  91. return Error;
  92. }
  93. static int test_bvec1_ctor()
  94. {
  95. int Error = 0;
  96. glm::bvec1 A(true);
  97. glm::bvec1 B(true);
  98. glm::bvec1 C(false);
  99. glm::bvec1 D = A && B;
  100. glm::bvec1 E = A && C;
  101. glm::bvec1 F = A || C;
  102. Error += D == glm::bvec1(true) ? 0 : 1;
  103. Error += E == glm::bvec1(false) ? 0 : 1;
  104. Error += F == glm::bvec1(true) ? 0 : 1;
  105. bool G = A == C;
  106. bool H = A != C;
  107. Error += !G ? 0 : 1;
  108. Error += H ? 0 : 1;
  109. return Error;
  110. }
  111. int main()
  112. {
  113. // Suppress unused variable warnings
  114. (void)g1;
  115. (void)g2;
  116. int Error = 0;
  117. Error += test_vec1_size();
  118. Error += test_vec1_ctor();
  119. Error += test_bvec1_ctor();
  120. Error += test_vec1_operators();
  121. Error += test_vec1_operator_increment();
  122. return Error;
  123. }