Browse Source

Added missing bvec* && and || operators

Christophe Riccio 10 years ago
parent
commit
a257beb5de

+ 6 - 0
glm/detail/type_vec1.hpp

@@ -314,6 +314,12 @@ namespace glm
 	template <typename T, precision P>
 	GLM_FUNC_DECL bool operator!=(tvec1<T, P> const & v1, tvec1<T, P> const & v2);
 
+	template <precision P>
+	GLM_FUNC_DECL bool operator&&(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2);
+
+	template <precision P>
+	GLM_FUNC_DECL bool operator||(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2);
+
 	// -- Is type --
 
 	template <typename T, precision P>

+ 12 - 0
glm/detail/type_vec1.inl

@@ -601,4 +601,16 @@ namespace glm
 	{
 		return (v1.x != v2.x);
 	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec1<bool, P> operator&&(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2)
+	{
+		return tvec1<bool, P>(v1.x && v2.x);
+	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec1<bool, P> operator||(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2)
+	{
+		return tvec1<bool, P>(v1.x || v2.x);
+	}
 }//namespace glm

+ 6 - 0
glm/detail/type_vec2.hpp

@@ -406,6 +406,12 @@ namespace glm
 	template <typename T, precision P>
 	GLM_FUNC_DECL bool operator!=(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
 
+	template <precision P>
+	GLM_FUNC_DECL bool operator&&(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2);
+
+	template <precision P>
+	GLM_FUNC_DECL bool operator||(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2);
+
 	// -- Is type --
 
 	template <typename T, precision P>

+ 12 - 0
glm/detail/type_vec2.inl

@@ -926,4 +926,16 @@ namespace glm
 	{
 		return (v1.x != v2.x) || (v1.y != v2.y);
 	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec2<bool, P> operator&&(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2)
+	{
+		return tvec2<bool, P>(v1.x && v2.x, v1.y && v2.y);
+	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec2<bool, P> operator||(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2)
+	{
+		return tvec2<bool, P>(v1.x || v2.x, v1.y || v2.y);
+	}
 }//namespace glm

+ 6 - 0
glm/detail/type_vec3.hpp

@@ -429,6 +429,12 @@ namespace glm
 	template <typename T, precision P>
 	GLM_FUNC_DECL bool operator!=(tvec3<T, P> const & v1, tvec3<T, P> const & v2);
 
+	template <precision P>
+	GLM_FUNC_DECL bool operator&&(tvec3<bool, P> const & v1, tvec3<bool, P> const & v2);
+
+	template <precision P>
+	GLM_FUNC_DECL bool operator||(tvec3<bool, P> const & v1, tvec3<bool, P> const & v2);
+
 	// -- Is type --
 
 	template <typename T, precision P>

+ 12 - 0
glm/detail/type_vec3.inl

@@ -1058,4 +1058,16 @@ namespace glm
 	{
 		return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z);
 	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec3<bool, P> operator&&(tvec3<bool, P> const & v1, tvec3<bool, P> const & v2)
+	{
+		return tvec3<bool, P>(v1.x && v2.x, v1.y && v2.y, v1.z && v2.z);
+	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec3<bool, P> operator||(tvec3<bool, P> const & v1, tvec3<bool, P> const & v2)
+	{
+		return tvec3<bool, P>(v1.x || v2.x, v1.y || v2.y, v1.z || v2.z);
+	}
 }//namespace glm

+ 6 - 0
glm/detail/type_vec4.hpp

@@ -542,6 +542,12 @@ namespace detail
 	template <typename T, precision P>
 	GLM_FUNC_DECL bool operator!=(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
 
+	template <precision P>
+	GLM_FUNC_DECL bool operator&&(tvec4<bool, P> const & v1, tvec4<bool, P> const & v2);
+
+	template <precision P>
+	GLM_FUNC_DECL bool operator||(tvec4<bool, P> const & v1, tvec4<bool, P> const & v2);
+
 	// -- Is type --
 
 	template <typename T, precision P>

+ 12 - 0
glm/detail/type_vec4.inl

@@ -1168,6 +1168,18 @@ namespace glm
 	{
 		return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z) || (v1.w != v2.w);
 	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec4<bool, P> operator&&(tvec4<bool, P> const & v1, tvec4<bool, P> const & v2)
+	{
+		return tvec4<bool, P>(v1.x && v2.x, v1.y && v2.y, v1.z && v2.z, v1.w && v2.w);
+	}
+
+	template <precision P>
+	GLM_FUNC_QUALIFIER tvec4<bool, P> operator||(tvec4<bool, P> const & v1, tvec4<bool, P> const & v2)
+	{
+		return tvec4<bool, P>(v1.x || v2.x, v1.y || v2.y, v1.z || v2.z, v1.w || v2.w);
+	}
 }//namespace glm
 
 #if GLM_HAS_ANONYMOUS_UNION && GLM_NOT_BUGGY_VC32BITS

+ 1 - 0
readme.md

@@ -59,6 +59,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
 - Added (un)packUnorm and (un)packSnorm to GTC_packing
 - Added 16bit pack and unpack to GTC_packing
 - Added 8bit pack and unpack to GTC_packing
+- Added missing bvec* && and || operators
 
 ##### Improvements:
 - Improved GTC_random linearRand documentation

+ 21 - 0
test/core/core_type_vec4.cpp

@@ -159,6 +159,26 @@ int test_vec4_ctor()
 	return Error;
 }
 
+int test_bvec4_ctor()
+{
+	int Error = 0;
+
+	glm::bvec4 const A(true);
+	glm::bvec4 const B(true);
+	glm::bvec4 const C(false);
+	glm::bvec4 const D = A && B;
+	glm::bvec4 const E = A && C;
+	glm::bvec4 const F = A || C;
+	bool const G = A == C;
+	bool const H = A != C;
+
+	Error += D == glm::bvec4(true) ? 0 : 1;
+	Error += E == glm::bvec4(false) ? 0 : 1;
+	Error += F == glm::bvec4(true) ? 0 : 1;
+
+	return Error;
+}
+
 int test_vec4_operators()
 {
 	int Error = 0;
@@ -511,6 +531,7 @@ int main()
 
 	Error += test_vec4_static_const();
 	Error += test_vec4_ctor();
+	Error += test_bvec4_ctor();
 	Error += test_vec4_size();
 	Error += test_vec4_operators();
 	Error += test_vec4_swizzle_partial();

+ 1 - 0
test/gtc/gtc_packing.cpp

@@ -438,6 +438,7 @@ int test_packSnorm1x8()
 	std::vector<glm::vec1> A;
 	A.push_back(glm::vec1( 1.0f));
 	A.push_back(glm::vec1(-0.7f));
+	A.push_back(glm::vec1(-1.0f));
 	
 	for(std::size_t i = 0; i < A.size(); ++i)
 	{