From a257beb5de12c66df5ce154da69d69c89441afdf Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 15 Oct 2015 04:28:08 +0200 Subject: [PATCH] Added missing bvec* && and || operators --- glm/detail/type_vec1.hpp | 6 ++++++ glm/detail/type_vec1.inl | 12 ++++++++++++ glm/detail/type_vec2.hpp | 6 ++++++ glm/detail/type_vec2.inl | 12 ++++++++++++ glm/detail/type_vec3.hpp | 6 ++++++ glm/detail/type_vec3.inl | 12 ++++++++++++ glm/detail/type_vec4.hpp | 6 ++++++ glm/detail/type_vec4.inl | 12 ++++++++++++ readme.md | 1 + test/core/core_type_vec4.cpp | 21 +++++++++++++++++++++ test/gtc/gtc_packing.cpp | 1 + 11 files changed, 95 insertions(+) diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index f59e1c96..4da5cd93 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -314,6 +314,12 @@ namespace glm template GLM_FUNC_DECL bool operator!=(tvec1 const & v1, tvec1 const & v2); + template + GLM_FUNC_DECL bool operator&&(tvec1 const & v1, tvec1 const & v2); + + template + GLM_FUNC_DECL bool operator||(tvec1 const & v1, tvec1 const & v2); + // -- Is type -- template diff --git a/glm/detail/type_vec1.inl b/glm/detail/type_vec1.inl index 0da79982..dde1e0de 100644 --- a/glm/detail/type_vec1.inl +++ b/glm/detail/type_vec1.inl @@ -601,4 +601,16 @@ namespace glm { return (v1.x != v2.x); } + + template + GLM_FUNC_QUALIFIER tvec1 operator&&(tvec1 const & v1, tvec1 const & v2) + { + return tvec1(v1.x && v2.x); + } + + template + GLM_FUNC_QUALIFIER tvec1 operator||(tvec1 const & v1, tvec1 const & v2) + { + return tvec1(v1.x || v2.x); + } }//namespace glm diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index ddd45564..196cff85 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -406,6 +406,12 @@ namespace glm template GLM_FUNC_DECL bool operator!=(tvec2 const & v1, tvec2 const & v2); + template + GLM_FUNC_DECL bool operator&&(tvec2 const & v1, tvec2 const & v2); + + template + GLM_FUNC_DECL bool operator||(tvec2 const & v1, tvec2 const & v2); + // -- Is type -- template diff --git a/glm/detail/type_vec2.inl b/glm/detail/type_vec2.inl index 1bcaf772..6a8153e6 100644 --- a/glm/detail/type_vec2.inl +++ b/glm/detail/type_vec2.inl @@ -926,4 +926,16 @@ namespace glm { return (v1.x != v2.x) || (v1.y != v2.y); } + + template + GLM_FUNC_QUALIFIER tvec2 operator&&(tvec2 const & v1, tvec2 const & v2) + { + return tvec2(v1.x && v2.x, v1.y && v2.y); + } + + template + GLM_FUNC_QUALIFIER tvec2 operator||(tvec2 const & v1, tvec2 const & v2) + { + return tvec2(v1.x || v2.x, v1.y || v2.y); + } }//namespace glm diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index d08b7c29..18ffb44d 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -429,6 +429,12 @@ namespace glm template GLM_FUNC_DECL bool operator!=(tvec3 const & v1, tvec3 const & v2); + template + GLM_FUNC_DECL bool operator&&(tvec3 const & v1, tvec3 const & v2); + + template + GLM_FUNC_DECL bool operator||(tvec3 const & v1, tvec3 const & v2); + // -- Is type -- template diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index f231a682..629214c4 100644 --- a/glm/detail/type_vec3.inl +++ b/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 + GLM_FUNC_QUALIFIER tvec3 operator&&(tvec3 const & v1, tvec3 const & v2) + { + return tvec3(v1.x && v2.x, v1.y && v2.y, v1.z && v2.z); + } + + template + GLM_FUNC_QUALIFIER tvec3 operator||(tvec3 const & v1, tvec3 const & v2) + { + return tvec3(v1.x || v2.x, v1.y || v2.y, v1.z || v2.z); + } }//namespace glm diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 489ef6f8..7589acfd 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -542,6 +542,12 @@ namespace detail template GLM_FUNC_DECL bool operator!=(tvec4 const & v1, tvec4 const & v2); + template + GLM_FUNC_DECL bool operator&&(tvec4 const & v1, tvec4 const & v2); + + template + GLM_FUNC_DECL bool operator||(tvec4 const & v1, tvec4 const & v2); + // -- Is type -- template diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 23b8c8b3..eaaa4fc3 100644 --- a/glm/detail/type_vec4.inl +++ b/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 + GLM_FUNC_QUALIFIER tvec4 operator&&(tvec4 const & v1, tvec4 const & v2) + { + return tvec4(v1.x && v2.x, v1.y && v2.y, v1.z && v2.z, v1.w && v2.w); + } + + template + GLM_FUNC_QUALIFIER tvec4 operator||(tvec4 const & v1, tvec4 const & v2) + { + return tvec4(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 diff --git a/readme.md b/readme.md index 67b4566f..6d769eda 100644 --- a/readme.md +++ b/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 diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 5c48eccd..143fbb99 100644 --- a/test/core/core_type_vec4.cpp +++ b/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(); diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 2f7a1c3e..dff652a0 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -438,6 +438,7 @@ int test_packSnorm1x8() std::vector 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) {