core_cpp_constexpr.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include <glm/glm.hpp>
  2. #if GLM_USE_CONSTEXP == GLM_ENABLE
  3. #include <glm/gtc/constants.hpp>
  4. #include <glm/gtc/quaternion.hpp>
  5. #include <glm/ext/vector_relational.hpp>
  6. #include <glm/ext/vec1.hpp>
  7. static int test_vec1()
  8. {
  9. int Error = 0;
  10. {
  11. constexpr glm::ivec1 O(glm::ivec1(1));
  12. static_assert(glm::ivec1(1) == O, "GLM: Failed constexpr");
  13. constexpr glm::ivec1 P(1);
  14. static_assert(glm::ivec1(1) == P, "GLM: Failed constexpr");
  15. }
  16. {
  17. constexpr glm::ivec1 L(glm::ivec2(1, 2));
  18. static_assert(glm::ivec1(1) == L, "GLM: Failed constexpr");
  19. constexpr glm::ivec1 M(glm::ivec3(1, 2, 3));
  20. static_assert(glm::ivec1(1) == M, "GLM: Failed constexpr");
  21. constexpr glm::ivec1 N(glm::ivec4(1, 2, 3, 4));
  22. static_assert(glm::ivec1(1) == N, "GLM: Failed constexpr");
  23. }
  24. {
  25. static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
  26. static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
  27. }
  28. {
  29. constexpr glm::bvec1 A1(true);
  30. constexpr glm::bvec1 A2(true);
  31. constexpr glm::bvec1 B1(false);
  32. constexpr glm::bvec1 B2(false);
  33. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  34. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  35. }
  36. return Error;
  37. }
  38. static int test_vec2()
  39. {
  40. int Error = 0;
  41. {
  42. constexpr glm::ivec2 O(glm::ivec1(1));
  43. static_assert(glm::ivec2(1) == O, "GLM: Failed constexpr");
  44. constexpr glm::ivec2 A(1);
  45. static_assert(glm::ivec2(1) == A, "GLM: Failed constexpr");
  46. }
  47. {
  48. constexpr glm::ivec2 F(glm::ivec1(1), glm::ivec1(2));
  49. static_assert(glm::ivec2(1, 2) == F, "GLM: Failed constexpr");
  50. constexpr glm::ivec2 G(1, glm::ivec1(2));
  51. static_assert(glm::ivec2(1, 2) == G, "GLM: Failed constexpr");
  52. constexpr glm::ivec2 H(glm::ivec1(1), 2);
  53. static_assert(glm::ivec2(1, 2) == H, "GLM: Failed constexpr");
  54. constexpr glm::ivec2 I(1, 2);
  55. static_assert(glm::ivec2(1, 2) == I, "GLM: Failed constexpr");
  56. }
  57. {
  58. constexpr glm::ivec2 L(glm::ivec2(1, 2));
  59. static_assert(glm::ivec2(1, 2) == L, "GLM: Failed constexpr");
  60. constexpr glm::ivec2 M(glm::ivec3(1, 2, 3));
  61. static_assert(glm::ivec2(1, 2) == M, "GLM: Failed constexpr");
  62. constexpr glm::ivec2 N(glm::ivec4(1, 2, 3, 4));
  63. static_assert(glm::ivec2(1, 2) == N, "GLM: Failed constexpr");
  64. }
  65. {
  66. static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr");
  67. static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
  68. static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
  69. static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr");
  70. }
  71. {
  72. constexpr glm::bvec2 A1(true);
  73. constexpr glm::bvec2 A2(true);
  74. constexpr glm::bvec2 B1(false);
  75. constexpr glm::bvec2 B2(false);
  76. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  77. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  78. }
  79. return Error;
  80. }
  81. static int test_vec3()
  82. {
  83. int Error = 0;
  84. {
  85. constexpr glm::ivec3 O(glm::ivec1(1));
  86. static_assert(glm::ivec3(1) == O, "GLM: Failed constexpr");
  87. constexpr glm::ivec3 A(1);
  88. static_assert(glm::ivec3(1) == A, "GLM: Failed constexpr");
  89. }
  90. {
  91. constexpr glm::ivec3 B(glm::ivec2(1, 2), 3);
  92. static_assert(glm::ivec3(1, 2, 3) == B, "GLM: Failed constexpr");
  93. constexpr glm::ivec3 C(1, glm::ivec2(2, 3));
  94. static_assert(glm::ivec3(1, 2, 3) == C, "GLM: Failed constexpr");
  95. constexpr glm::ivec3 D(glm::ivec1(1), glm::ivec2(2, 3));
  96. static_assert(glm::ivec3(1, 2, 3) == D, "GLM: Failed constexpr");
  97. constexpr glm::ivec3 E(glm::ivec2(1, 2), glm::ivec1(3));
  98. static_assert(glm::ivec3(1, 2, 3) == E, "GLM: Failed constexpr");
  99. }
  100. {
  101. constexpr glm::ivec3 F(glm::ivec1(1), glm::ivec1(2), glm::ivec1(3));
  102. static_assert(glm::ivec3(1, 2, 3) == F, "GLM: Failed constexpr");
  103. constexpr glm::ivec3 G(1, glm::ivec1(2), glm::ivec1(3));
  104. static_assert(glm::ivec3(1, 2, 3) == G, "GLM: Failed constexpr");
  105. constexpr glm::ivec3 H(glm::ivec1(1), 2, glm::ivec1(3));
  106. static_assert(glm::ivec3(1, 2, 3) == H, "GLM: Failed constexpr");
  107. constexpr glm::ivec3 I(1, 2, glm::ivec1(3));
  108. static_assert(glm::ivec3(1, 2, 3) == I, "GLM: Failed constexpr");
  109. constexpr glm::ivec3 J(glm::ivec1(1), glm::ivec1(2), 3);
  110. static_assert(glm::ivec3(1, 2, 3) == J, "GLM: Failed constexpr");
  111. constexpr glm::ivec3 K(1, glm::ivec1(2), 3);
  112. static_assert(glm::ivec3(1, 2, 3) == K, "GLM: Failed constexpr");
  113. constexpr glm::ivec3 L(glm::ivec1(1), 2, 3);
  114. static_assert(glm::ivec3(1, 2, 3) == L, "GLM: Failed constexpr");
  115. constexpr glm::ivec3 M(1, 2, 3);
  116. static_assert(glm::ivec3(1, 2, 3) == M, "GLM: Failed constexpr");
  117. }
  118. {
  119. constexpr glm::ivec3 N(glm::ivec4(1, 2, 3, 4));
  120. static_assert(glm::ivec3(1, 2, 3) == N, "GLM: Failed constexpr");
  121. }
  122. {
  123. static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr");
  124. static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
  125. static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
  126. static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr");
  127. }
  128. {
  129. constexpr glm::bvec3 A1(true);
  130. constexpr glm::bvec3 A2(true);
  131. constexpr glm::bvec3 B1(false);
  132. constexpr glm::bvec3 B2(false);
  133. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  134. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  135. }
  136. return Error;
  137. }
  138. static int test_vec4()
  139. {
  140. int Error = 0;
  141. {
  142. constexpr glm::ivec4 O(glm::ivec4(1));
  143. static_assert(glm::ivec4(1) == O, "GLM: Failed constexpr");
  144. constexpr glm::ivec4 A(1);
  145. static_assert(glm::ivec4(1) == A, "GLM: Failed constexpr");
  146. constexpr glm::ivec4 N(glm::ivec4(1, 2, 3, 4));
  147. static_assert(glm::ivec4(1, 2, 3, 4) == N, "GLM: Failed constexpr");
  148. }
  149. {
  150. constexpr glm::ivec4 A(glm::ivec3(1, 2, 3), 4);
  151. static_assert(glm::ivec4(1, 2, 3, 4) == A, "GLM: Failed constexpr");
  152. constexpr glm::ivec4 B(glm::ivec2(1, 2), glm::ivec2(3, 4));
  153. static_assert(glm::ivec4(1, 2, 3, 4) == B, "GLM: Failed constexpr");
  154. constexpr glm::ivec4 C(1, glm::ivec3(2, 3, 4));
  155. static_assert(glm::ivec4(1, 2, 3, 4) == C, "GLM: Failed constexpr");
  156. constexpr glm::ivec4 D(glm::ivec1(1), glm::ivec2(2, 3), glm::ivec1(4));
  157. static_assert(glm::ivec4(1, 2, 3, 4) == D, "GLM: Failed constexpr");
  158. constexpr glm::ivec4 E(glm::ivec2(1, 2), glm::ivec1(3), glm::ivec1(4));
  159. static_assert(glm::ivec4(1, 2, 3, 4) == E, "GLM: Failed constexpr");
  160. constexpr glm::ivec4 F(glm::ivec1(1), glm::ivec1(2), glm::ivec2(3, 4));
  161. static_assert(glm::ivec4(1, 2, 3, 4) == F, "GLM: Failed constexpr");
  162. }
  163. {
  164. static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr");
  165. static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr");
  166. static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr");
  167. static_assert(glm::ivec4::length() == 4, "GLM: Failed constexpr");
  168. }
  169. {
  170. constexpr glm::bvec4 A1(true);
  171. constexpr glm::bvec4 A2(true);
  172. constexpr glm::bvec4 B1(false);
  173. constexpr glm::bvec4 B2(false);
  174. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  175. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  176. }
  177. return Error;
  178. }
  179. static int test_quat()
  180. {
  181. int Error = 0;
  182. {
  183. static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
  184. static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
  185. static_assert(glm::quat(1.0f, 0.0f, 0.0f, 0.0f).w > 0.0f, "GLM: Failed constexpr");
  186. glm::quat constexpr Q = glm::identity<glm::quat>();
  187. static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon<float>(), "GLM: Failed constexpr");
  188. }
  189. return Error;
  190. }
  191. static int test_mat2x2()
  192. {
  193. int Error = 0;
  194. static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr");
  195. return Error;
  196. }
  197. #endif//GLM_USE_CONSTEXP == GLM_ENABLE
  198. int main()
  199. {
  200. int Error = 0;
  201. # if GLM_USE_CONSTEXP == GLM_ENABLE
  202. Error += test_vec1();
  203. Error += test_vec2();
  204. Error += test_vec3();
  205. Error += test_vec4();
  206. Error += test_quat();
  207. Error += test_mat2x2();
  208. # endif//GLM_USE_CONSTEXP == GLM_ENABLE
  209. return Error;
  210. }