ext_vec1.cpp 2.8 KB

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