Browse Source

Added assert for initilizer lists to match sizes

Christophe Riccio 12 years ago
parent
commit
4acd5b087d

+ 9 - 7
glm/core/type_mat2x2.inl

@@ -144,21 +144,23 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
-
-		typename std::initializer_list<U>::iterator p = m.begin();
+		assert(l.size() == this->length() * this->value[0].length());
+		
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec2<T, P>(*(p +  0), *(p +  1));
 		this->value[1] = tvec2<T, P>(*(p +  2), *(p +  3));
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<tvec2<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<tvec2<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 8 - 6
glm/core/type_mat2x3.inl

@@ -143,21 +143,23 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec3<T, P>(*(p +  0), *(p +  1), *(p +  2));
 		this->value[1] = tvec3<T, P>(*(p +  3), *(p +  4), *(p +  5));
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<tvec3<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<tvec3<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
+		assert(l.size() == this->length());
+		
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 8 - 6
glm/core/type_mat2x4.inl

@@ -146,21 +146,23 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec4<T, P>(*(p +  0), *(p +  1), *(p +  2), *(p +  3));
 		this->value[1] = tvec4<T, P>(*(p +  4), *(p +  5), *(p +  6), *(p +  7));
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<tvec4<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<tvec4<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 2 - 2
glm/core/type_mat3x2.hpp

@@ -80,9 +80,9 @@ namespace detail
 
 #if(GLM_HAS_INITIALIZER_LISTS)
 		template <typename U>
-		GLM_FUNC_DECL tmat3x2(std::initializer_list<U> m);
+		GLM_FUNC_DECL tmat3x2(std::initializer_list<U> l);
 
-		GLM_FUNC_DECL tmat3x2(std::initializer_list<tvec2<T, P> > m);
+		GLM_FUNC_DECL tmat3x2(std::initializer_list<tvec2<T, P> > l);
 #endif//GLM_HAS_INITIALIZER_LISTS
 
 		//////////////////////////////////////

+ 9 - 7
glm/core/type_mat3x2.inl

@@ -151,11 +151,11 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
 		this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
@@ -163,11 +163,13 @@ namespace detail
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<tvec2<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<tvec2<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
-		this->value[2] = m.begin()[2];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
+		this->value[2] = l.begin()[2];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 9 - 7
glm/core/type_mat3x3.inl

@@ -154,11 +154,11 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2));
 		this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5));
@@ -166,11 +166,13 @@ namespace detail
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<tvec3<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<tvec3<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
-		this->value[2] = m.begin()[2];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
+		this->value[2] = l.begin()[2];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 9 - 7
glm/core/type_mat3x4.inl

@@ -198,11 +198,11 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec4<T, P>(*(p +  0), *(p +  1), *(p +  2), *(p +  3));
 		this->value[1] = tvec4<T, P>(*(p +  4), *(p +  5), *(p +  6), *(p +  7));
@@ -210,11 +210,13 @@ namespace detail
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<tvec4<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<tvec4<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
-		this->value[2] = m.begin()[2];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
+		this->value[2] = l.begin()[2];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 	

+ 10 - 8
glm/core/type_mat4x2.inl

@@ -209,11 +209,11 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
 		this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
@@ -222,12 +222,14 @@ namespace detail
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<tvec2<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<tvec2<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
-		this->value[2] = m.begin()[2];
-		this->value[3] = m.begin()[3];
+		assert(l.size() == this->length());
+		
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
+		this->value[2] = l.begin()[2];
+		this->value[3] = l.begin()[3];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 10 - 8
glm/core/type_mat4x3.inl

@@ -155,11 +155,11 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec3<T, P>(*(p +  0), *(p +  1), *(p +  2));
 		this->value[1] = tvec3<T, P>(*(p +  3), *(p +  4), *(p +  5));
@@ -168,12 +168,14 @@ namespace detail
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<tvec3<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<tvec3<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
-		this->value[2] = m.begin()[2];
-		this->value[3] = m.begin()[3];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
+		this->value[2] = l.begin()[2];
+		this->value[3] = l.begin()[3];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 10 - 8
glm/core/type_mat4x4.inl

@@ -177,11 +177,11 @@ namespace detail
 #if(GLM_HAS_INITIALIZER_LISTS)
 	template <typename T, precision P>
 	template <typename U>
-	GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<U> m)
+	GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<U> l)
 	{
-		assert(m.size() >= this->length());
+		assert(l.size() == this->length() * this->value[0].length());
 
-		typename std::initializer_list<U>::iterator p = m.begin();
+		typename std::initializer_list<U>::iterator p = l.begin();
 
 		this->value[0] = tvec4<T, P>(*(p +  0), *(p +  1), *(p +  2), *(p +  3));
 		this->value[1] = tvec4<T, P>(*(p +  4), *(p +  5), *(p +  6), *(p +  7));
@@ -190,12 +190,14 @@ namespace detail
 	}
 
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<tvec4<T, P> > m)
+	GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<tvec4<T, P> > l)
 	{
-		this->value[0] = m.begin()[0];
-		this->value[1] = m.begin()[1];
-		this->value[2] = m.begin()[2];
-		this->value[3] = m.begin()[3];
+		assert(l.size() == this->length());
+
+		this->value[0] = l.begin()[0];
+		this->value[1] = l.begin()[1];
+		this->value[2] = l.begin()[2];
+		this->value[3] = l.begin()[3];
 	}
 #endif//GLM_HAS_INITIALIZER_LISTS
 

+ 2 - 2
test/core/core_type_mat3x2.cpp

@@ -54,8 +54,8 @@ int test_ctr()
 		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
 	
 	std::vector<glm::mat3x2> v1{
-		{0, 1, 2, 3, 4, 5, 6, 7, 8},
-		{0, 1, 2, 3, 4, 5, 6, 7, 8}
+		{0, 1, 2, 3, 4, 5},
+		{0, 1, 2, 3, 4, 5}
 	};
 	
 	std::vector<glm::mat3x2> v2{