Browse Source

Added swizzle contructor tests

Christophe Riccio 11 years ago
parent
commit
fa6bec2f3d

+ 1 - 1
glm/detail/type_vec2.hpp

@@ -115,7 +115,7 @@ namespace detail
 
 #		if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
 			template <int E0, int E1>
-			GLM_FUNC_DECL tvec2(_swizzle<2,T, P, tvec2<T, P>, E0, E1,-1,-2> const & that)
+			GLM_FUNC_DECL tvec2(_swizzle<2, T, P, tvec2<T, P>, E0, E1,-1,-2> const & that)
 			{
 				*this = that();
 			}

+ 26 - 31
glm/detail/type_vec3.hpp

@@ -104,17 +104,35 @@ namespace detail
 		template <precision Q>
 		GLM_FUNC_DECL tvec3(tvec3<T, Q> const & v);
 
+		//////////////////////////////////////
+		// Swizzle constructors
+
+#		if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+			template <int E0, int E1, int E2>
+			GLM_FUNC_DECL tvec3(_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & that)
+			{
+				*this = that();
+			}
+
+			template <int E0, int E1>
+			GLM_FUNC_DECL tvec3(_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & s)
+			{
+				*this = tvec3<T, P>(v(), s);
+			}
+
+			template <int E0, int E1>
+			GLM_FUNC_DECL tvec3(T const & s, _swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v)
+			{
+				*this = tvec3<T, P>(s, v());
+			}
+#		endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+
 		//////////////////////////////////////
 		// Explicit basic constructors
 
-		GLM_FUNC_DECL explicit tvec3(
-			ctor);
-		GLM_FUNC_DECL explicit tvec3(
-			T const & s);
-		GLM_FUNC_DECL tvec3(
-			T const & s1,
-			T const & s2,
-			T const & s3);
+		GLM_FUNC_DECL explicit tvec3(ctor);
+		GLM_FUNC_DECL explicit tvec3(T const & s);
+		GLM_FUNC_DECL tvec3(T const & s1, T const & s2, T const & s3);
 
 		//////////////////////////////////////
 		// Conversion scalar constructors
@@ -142,29 +160,6 @@ namespace detail
 		template <typename U, precision Q>
 		GLM_FUNC_DECL explicit tvec3(tvec4<U, Q> const & v);
 
-		//////////////////////////////////////
-		// Swizzle constructors
-
-#		if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
-			template <int E0, int E1, int E2>
-			GLM_FUNC_DECL tvec3(_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & that)
-			{
-				*this = that();
-			}
-
-			template <int E0, int E1>
-			GLM_FUNC_DECL tvec3(_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & s)
-			{
-				*this = tvec3<T, P>(v(), s);
-			}
-
-			template <int E0, int E1>
-			GLM_FUNC_DECL tvec3(T const & s, _swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v)
-			{
-				*this = tvec3<T, P>(s, v());
-			}
-#		endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
-
 		//////////////////////////////////////
 		// Unary arithmetic operators
 

+ 1 - 0
test/core/core_type_vec1.cpp

@@ -7,6 +7,7 @@
 // File    : test/core/type_vec1.cpp
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+#define GLM_SWIZZLE
 #define GLM_FORCE_RADIANS
 #include <glm/gtx/vec1.hpp>
 

+ 14 - 0
test/core/core_type_vec2.cpp

@@ -7,6 +7,7 @@
 // File    : test/core/type_vec2.cpp
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+#define GLM_SWIZZLE
 #define GLM_FORCE_RADIANS
 #include <glm/vector_relational.hpp>
 #include <glm/vec2.hpp>
@@ -219,6 +220,19 @@ int test_vec2_ctor()
 	}
 #endif
 
+#if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+	{
+		glm::vec2 A = glm::vec2(1.0f, 2.0f);
+		glm::vec2 B = A.xy;
+		glm::vec2 C(A.xy);
+		glm::vec2 D(A.xy());
+
+		Error += glm::all(glm::equal(A, B)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, C)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, D)) ? 0 : 1;
+	}
+#endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+
 	{
 		glm::vec2 A = glm::vec2(2.0f);
 		glm::vec2 B = glm::vec2(2.0f, 3.0f);

+ 21 - 0
test/core/core_type_vec3.cpp

@@ -39,6 +39,27 @@ int test_vec3_ctor()
 	}
 #endif
 
+#if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+	{
+		glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
+		glm::vec3 B = A.xyz;
+		glm::vec3 C(A.xyz);
+		glm::vec3 D(A.xyz());
+		glm::vec3 E(A.x, A.yz);
+		glm::vec3 F(A.x, A.yz());
+		glm::vec3 G(A.xy, A.z);
+		glm::vec3 H(A.xy(), A.z);
+
+		Error += glm::all(glm::equal(A, B)) ? 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, E)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, F)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, G)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, H)) ? 0 : 1;
+	}
+#endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+
 	{
 		glm::vec3 A(1);
 		glm::vec3 B(1, 1, 1);

+ 32 - 0
test/core/core_type_vec4.cpp

@@ -7,6 +7,7 @@
 // File    : test/core/type_vec4.cpp
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+#define GLM_SWIZZLE
 #define GLM_FORCE_RADIANS
 #include <glm/vector_relational.hpp>
 #include <glm/vec2.hpp>
@@ -60,6 +61,37 @@ int test_vec4_ctor()
 	}
 #endif
 
+#if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+	{
+		glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
+		glm::vec4 B = A.xyzw;
+		glm::vec4 C(A.xyzw);
+		glm::vec4 D(A.xyzw());
+		glm::vec4 E(A.x, A.yzw);
+		glm::vec4 F(A.x, A.yzw());
+		glm::vec4 G(A.xyz, A.w);
+		glm::vec4 H(A.xyz(), A.w);
+		glm::vec4 I(A.xy, A.zw);
+		glm::vec4 J(A.xy(), A.zw());
+		glm::vec4 K(A.x, A.y, A.zw);
+		glm::vec4 L(A.x, A.yz, A.w);
+		glm::vec4 M(A.xy, A.z, A.w);
+
+		Error += glm::all(glm::equal(A, B)) ? 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, E)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, F)) ? 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, I)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, J)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, K)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, L)) ? 0 : 1;
+		Error += glm::all(glm::equal(A, M)) ? 0 : 1;
+	}
+#endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
+
 	{
 		glm::vec4 A(1);
 		glm::vec4 B(1, 1, 1, 1);