Fixed swizzle functions and operators tests

This commit is contained in:
Christophe Riccio 2018-07-14 19:56:13 +02:00
parent a23dd2f800
commit 61e68f2667
9 changed files with 129 additions and 106 deletions

View File

@ -6,7 +6,7 @@
namespace glm{ namespace glm{
namespace detail namespace detail
{ {
# if GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
template<qualifier Q, int E0, int E1, int E2, int E3> template<qualifier Q, int E0, int E1, int E2, int E3>
struct _swizzle_base1<4, float, Q, E0,E1,E2,E3, true> : public _swizzle_base0<float, 4> struct _swizzle_base1<4, float, Q, E0,E1,E2,E3, true> : public _swizzle_base0<float, 4>
{ {
@ -49,7 +49,7 @@ namespace detail
return Result; return Result;
} }
}; };
# endif// GLM_SWIZZLE == GLM_ENABLE # endif// GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
template<qualifier Q> template<qualifier Q>
struct compute_vec4_add<float, Q, true> struct compute_vec4_add<float, Q, true>

View File

@ -65,10 +65,11 @@ namespace glm
}; };
# else # else
union {T x, r, s;}; union {T x, r, s;};
/*
# if GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION # if GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, Q) GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, Q)
# endif # endif
*/
# endif # endif
// -- Component accesses -- // -- Component accesses --

View File

@ -50,7 +50,7 @@ int test_vec4_ctor()
} }
#endif #endif
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw; glm::vec4 B = A.xyzw;
@ -79,7 +79,7 @@ int test_vec4_ctor()
Error += glm::all(glm::equal(A, L)) ? 0 : 1; Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1; Error += glm::all(glm::equal(A, M)) ? 0 : 1;
} }
# elif GLM_SWIZZLE == GLM_ENABLE # elif GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw(); glm::vec4 B = A.xyzw();
@ -108,7 +108,7 @@ int test_vec4_ctor()
Error += glm::all(glm::equal(A, L)) ? 0 : 1; Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1; Error += glm::all(glm::equal(A, M)) ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec4 A(1); glm::vec4 A(1);
@ -340,7 +340,7 @@ int test_vec4_swizzle_partial()
glm::vec4 A(1, 2, 3, 4); glm::vec4 A(1, 2, 3, 4);
# if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec4 B(A.xy, A.zw); glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;

View File

@ -6,7 +6,7 @@ static int test_ivec2_swizzle()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{ {
glm::ivec2 A(1, 2); glm::ivec2 A(1, 2);
glm::ivec2 B = A.yx(); glm::ivec2 B = A.yx();
@ -47,7 +47,7 @@ int test_ivec3_swizzle()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{ {
glm::ivec3 A(1, 2, 3); glm::ivec3 A(1, 2, 3);
glm::ivec3 B = A.zyx(); glm::ivec3 B = A.zyx();
@ -56,7 +56,7 @@ int test_ivec3_swizzle()
Error += A != B ? 0 : 1; Error += A != B ? 0 : 1;
Error += A == C ? 0 : 1; Error += A == C ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE # endif
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
@ -94,8 +94,16 @@ int test_ivec3_swizzle()
glm::ivec3 const I = A.xxx / A.xxx; glm::ivec3 const I = A.xxx / A.xxx;
Error += I == glm::ivec3(1) ? 0 : 1; Error += I == glm::ivec3(1) ? 0 : 1;
glm::ivec3 J(1, 2, 3);
J.xyz += glm::ivec3(1);
Error += J == glm::ivec3(2, 3, 4) ? 0 : 1;
glm::ivec3 K(1, 2, 3);
K.xyz += A.xyz;
Error += K == glm::ivec3(2, 4, 6) ? 0 : 1;
} }
# endif//GLM_SWIZZLE # endif
return Error; return Error;
} }
@ -104,14 +112,16 @@ int test_ivec4_swizzle()
{ {
int Error = 0; int Error = 0;
#if GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{
glm::ivec4 A(1, 2, 3, 4); glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 B = A.wzyx(); glm::ivec4 B = A.wzyx();
glm::ivec4 C = B.wzyx(); glm::ivec4 C = B.wzyx();
Error += A != B ? 0 : 1; Error += A != B ? 0 : 1;
Error += A == C ? 0 : 1; Error += A == C ? 0 : 1;
#endif//GLM_SWIZZLE == GLM_ENABLE }
# endif
return Error; return Error;
} }
@ -120,7 +130,8 @@ int test_vec4_swizzle()
{ {
int Error = 0; int Error = 0;
#if GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{
glm::vec4 A(1, 2, 3, 4); glm::vec4 A(1, 2, 3, 4);
glm::vec4 B = A.wzyx(); glm::vec4 B = A.wzyx();
glm::vec4 C = B.wzyx(); glm::vec4 C = B.wzyx();
@ -130,7 +141,8 @@ int test_vec4_swizzle()
float f = glm::dot(C.wzyx(), C.xyzw()); float f = glm::dot(C.wzyx(), C.xyzw());
Error += glm::abs(f - 20.f) < 0.01f ? 0 : 1; Error += glm::abs(f - 20.f) < 0.01f ? 0 : 1;
#endif//GLM_SWIZZLE == GLM_ENABLE }
# endif
return Error; return Error;
} }

View File

@ -129,7 +129,7 @@ static int test_swizzle()
{ {
int Error = 0; int Error = 0;
#if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec1 A = glm::vec1(1.0f); glm::vec1 A = glm::vec1(1.0f);
//glm::vec1 B = A.x; //glm::vec1 B = A.x;
@ -138,7 +138,7 @@ static int test_swizzle()
//Error += glm::all(glm::equal(A, B)) ? 0 : 1; //Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1; Error += glm::all(glm::equal(A, C)) ? 0 : 1;
} }
#endif//GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
return Error; return Error;
} }

View File

@ -348,7 +348,7 @@ static int test_swizzle()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec2 A = glm::vec2(1.0f, 2.0f); glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy; glm::vec2 B = A.xy;
@ -359,7 +359,9 @@ static int test_swizzle()
Error += glm::all(glm::equal(A, C)) ? 0 : 1; Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1; Error += glm::all(glm::equal(A, D)) ? 0 : 1;
} }
# elif GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{ {
glm::vec2 A = glm::vec2(1.0f, 2.0f); glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy(); glm::vec2 B = A.xy();
@ -368,7 +370,7 @@ static int test_swizzle()
Error += glm::all(glm::equal(A, B)) ? 0 : 1; Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1; Error += glm::all(glm::equal(A, C)) ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
return Error; return Error;
} }

View File

@ -317,8 +317,8 @@ int test_vec3_swizzle3_2()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{
glm::vec3 v(1, 2, 3); glm::vec3 v(1, 2, 3);
glm::vec2 u; glm::vec2 u;
@ -371,8 +371,8 @@ int test_vec3_swizzle3_2()
v.zx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 1.0f) ? 0 : 1; v.zx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 1.0f) ? 0 : 1;
v.zy = u; Error += (v.x == 2.0f && v.y == 2.0f && v.z == 1.0f) ? 0 : 1; v.zy = u; Error += (v.x == 2.0f && v.y == 2.0f && v.z == 1.0f) ? 0 : 1;
//v.zz = u; //Illegal //v.zz = u; //Illegal
}
# endif//GLM_LANG # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
return Error; return Error;
} }
@ -381,7 +381,8 @@ int test_vec3_swizzle3_3()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{
glm::vec3 v(1, 2, 3); glm::vec3 v(1, 2, 3);
glm::vec3 u; glm::vec3 u;
@ -398,6 +399,7 @@ int test_vec3_swizzle3_3()
u = v.stp; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1; u = v.stp; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.pts; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; u = v.pts; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.pts = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; u.pts = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
}
# endif//GLM_LANG # endif//GLM_LANG
return Error; return Error;
@ -410,7 +412,8 @@ int test_vec3_swizzle_operators()
glm::vec3 u = glm::vec3(1, 2, 3); glm::vec3 u = glm::vec3(1, 2, 3);
glm::vec3 v = glm::vec3(10, 20, 30); glm::vec3 v = glm::vec3(10, 20, 30);
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{
glm::vec3 q; glm::vec3 q;
// Swizzle, swizzle binary operators // Swizzle, swizzle binary operators
@ -434,6 +437,7 @@ int test_vec3_swizzle_operators()
q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1; q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1;
q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1; q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1;
q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1; q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1;
}
# endif//GLM_LANG # endif//GLM_LANG
// Compile errors // Compile errors
@ -447,8 +451,8 @@ int test_vec3_swizzle_functions()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{
// NOTE: template functions cannot pick up the implicit conversion from // NOTE: template functions cannot pick up the implicit conversion from
// a swizzle to the unswizzled type, therefore the operator() must be // a swizzle to the unswizzled type, therefore the operator() must be
// used. E.g.: // used. E.g.:
@ -480,8 +484,8 @@ int test_vec3_swizzle_functions()
r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1; r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1; r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1; r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1;
}
#endif//GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
return Error; return Error;
} }
@ -490,25 +494,25 @@ int test_vec3_swizzle_partial()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
glm::vec3 A(1, 2, 3);
{ {
glm::vec3 const A(1, 2, 3);
glm::vec3 B(A.xy, 3.0f); glm::vec3 B(A.xy, 3.0f);
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;
} }
{ {
glm::vec3 B(1.0f, A.yz); glm::vec3 const A(1, 2, 3);
glm::vec3 const B(1.0f, A.yz);
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;
} }
{ {
glm::vec3 B(A.xyz); glm::vec3 const A(1, 2, 3);
glm::vec3 const B(A.xyz);
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
return Error; return Error;
} }
@ -544,7 +548,7 @@ static int test_swizzle()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f); glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
glm::vec3 B = A.xyz; glm::vec3 B = A.xyz;
@ -563,7 +567,9 @@ static int test_swizzle()
Error += glm::all(glm::equal(A, G)) ? 0 : 1; Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1; Error += glm::all(glm::equal(A, H)) ? 0 : 1;
} }
# elif GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{ {
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f); glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
glm::vec3 B = A.xyz(); glm::vec3 B = A.xyz();
@ -582,7 +588,7 @@ static int test_swizzle()
Error += glm::all(glm::equal(A, G)) ? 0 : 1; Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1; Error += glm::all(glm::equal(A, H)) ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
return Error; return Error;
} }

View File

@ -485,7 +485,7 @@ static int test_swizzle_partial()
glm::vec4 A(1, 2, 3, 4); glm::vec4 A(1, 2, 3, 4);
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec4 B(A.xy, A.zw); glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;
@ -511,7 +511,7 @@ static int test_swizzle_partial()
glm::vec4 B(1.0f, A.yzw); glm::vec4 B(1.0f, A.yzw);
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
return Error; return Error;
} }
@ -520,7 +520,7 @@ static int test_swizzle()
{ {
int Error = 0; int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{ {
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw; glm::vec4 B = A.xyzw;
@ -549,7 +549,9 @@ static int test_swizzle()
Error += glm::all(glm::equal(A, L)) ? 0 : 1; Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1; Error += glm::all(glm::equal(A, M)) ? 0 : 1;
} }
# elif GLM_SWIZZLE == GLM_ENABLE # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
{ {
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw(); glm::vec4 B = A.xyzw();
@ -578,7 +580,7 @@ static int test_swizzle()
Error += glm::all(glm::equal(A, L)) ? 0 : 1; Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1; Error += glm::all(glm::equal(A, M)) ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
return Error; return Error;
} }