From f5e27805af6261f9e6747a869f87f0471a1fa223 Mon Sep 17 00:00:00 2001 From: Groove Date: Fri, 6 Jul 2018 21:08:06 +0200 Subject: [PATCH] Added vec1 based constructors to vec3 with tests and fixed build --- glm/detail/type_vec2.hpp | 4 ++- glm/detail/type_vec2.inl | 12 ++++--- glm/detail/type_vec3.hpp | 3 ++ glm/detail/type_vec3.inl | 32 +++++++++++------- test/core/core_type_vec2.cpp | 19 +++++++++++ test/core/core_type_vec3.cpp | 63 ++++++++++++++++++++++++++++++++++-- 6 files changed, 113 insertions(+), 20 deletions(-) diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 40e0ca64..9d91b5ed 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -94,11 +94,13 @@ namespace glm // -- Explicit basic constructors -- GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(T scalar); - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(vec<1, T, P> const& v); GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(T x, T y); // -- Conversion constructors -- + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(vec<1, U, P> const& v); + /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A x, B y); diff --git a/glm/detail/type_vec2.inl b/glm/detail/type_vec2.inl index e8080e08..6c848abc 100644 --- a/glm/detail/type_vec2.inl +++ b/glm/detail/type_vec2.inl @@ -34,11 +34,6 @@ namespace glm : x(scalar), y(scalar) {} - template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(vec<1, T, P> const& v) - : x(v.x), y(v.x) - {} - template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(T _x, T _y) : x(_x), y(_y) @@ -46,6 +41,13 @@ namespace glm // -- Conversion scalar constructors -- + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(vec<1, U, P> const& v) + : x(static_cast(v.x)) + , y(static_cast(v.x)) + {} + template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(A _x, B _y) diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 0dfff4a4..d31aa5bc 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -98,6 +98,9 @@ namespace glm // -- Conversion scalar constructors -- + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(vec<1, U, P> const& v); + /// Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X x, Y y, Z z); diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index f0a187d6..b79c8ecc 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -41,6 +41,14 @@ namespace glm // -- Conversion scalar constructors -- + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, U, P> const& v) + : x(static_cast(v.x)) + , y(static_cast(v.x)) + , z(static_cast(v.x)) + {} + template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(X _x, Y _y, Z _z) @@ -52,7 +60,7 @@ namespace glm template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, Z _z) - : x(static_cast(_x)) + : x(static_cast(_x.x)) , y(static_cast(_y)) , z(static_cast(_z)) {} @@ -61,15 +69,15 @@ namespace glm template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, Z _z) : x(static_cast(_x)) - , y(static_cast(_y)) + , y(static_cast(_y.x)) , z(static_cast(_z)) {} template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, Z _z) - : x(static_cast(_x)) - , y(static_cast(_y)) + : x(static_cast(_x.x)) + , y(static_cast(_y.x)) , z(static_cast(_z)) {} @@ -78,31 +86,31 @@ namespace glm GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(X _x, Y _y, vec<1, Z, Q> const& _z) : x(static_cast(_x)) , y(static_cast(_y)) - , z(static_cast(_z)) + , z(static_cast(_z.x)) {} template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, vec<1, Z, Q> const& _z) - : x(static_cast(_x)) + : x(static_cast(_x.x)) , y(static_cast(_y)) - , z(static_cast(_z)) + , z(static_cast(_z.x)) {} template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z) : x(static_cast(_x)) - , y(static_cast(_y)) - , z(static_cast(_z)) + , y(static_cast(_y.x)) + , z(static_cast(_z.x)) {} template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z) - : x(static_cast(_x)) - , y(static_cast(_y)) - , z(static_cast(_z)) + : x(static_cast(_x.x)) + , y(static_cast(_y.x)) + , z(static_cast(_z.x)) {} // -- Conversion vector constructors -- diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 539691ea..a0e69a01 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -277,6 +277,25 @@ int test_vec2_ctor() Error += glm::all(glm::equal(E, O)) ? 0 : 1; } + { + glm::vec1 const R(1.0f); + glm::dvec1 const S(2.0); + glm::vec2 const O(1.0, 2.0); + + glm::vec2 const A(R); + glm::vec2 const B(1.0); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + + glm::vec2 const C(R, S); + Error += glm::all(glm::equal(C, O)) ? 0 : 1; + + glm::vec2 const D(R, 2.0); + Error += glm::all(glm::equal(D, O)) ? 0 : 1; + + glm::vec2 const E(1.0, S); + Error += glm::all(glm::equal(E, O)) ? 0 : 1; + } + return Error; } diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index 0b7c68d8..e581cc4c 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -1,4 +1,5 @@ #define GLM_FORCE_SWIZZLE +#include #include #include #include @@ -71,7 +72,7 @@ int test_vec3_ctor() Error += A == B ? 0 : 1; } - + { std::vector Tests; Tests.push_back(glm::vec3(glm::vec2(1, 2), 3)); @@ -82,7 +83,65 @@ int test_vec3_ctor() for(std::size_t i = 0; i < Tests.size(); ++i) Error += Tests[i] == glm::vec3(1, 2, 3) ? 0 : 1; } - + + { + glm::vec1 const R(1.0f); + glm::vec1 const S(2.0f); + glm::vec1 const T(3.0f); + glm::vec3 const O(1.0f, 2.0f, 3.0f); + + glm::vec3 const A(R); + glm::vec3 const B(1.0f); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + + glm::vec3 const C(R, S, T); + Error += glm::all(glm::equal(C, O)) ? 0 : 1; + + glm::vec3 const D(R, 2.0f, 3.0f); + Error += glm::all(glm::equal(D, O)) ? 0 : 1; + + glm::vec3 const E(1.0f, S, 3.0f); + Error += glm::all(glm::equal(E, O)) ? 0 : 1; + + glm::vec3 const F(1.0f, S, T); + Error += glm::all(glm::equal(F, O)) ? 0 : 1; + + glm::vec3 const G(R, 2.0f, T); + Error += glm::all(glm::equal(G, O)) ? 0 : 1; + + glm::vec3 const H(R, S, 3.0f); + Error += glm::all(glm::equal(H, O)) ? 0 : 1; + } + + { + glm::vec1 const R(1.0); + glm::dvec1 const S(2.0); + glm::vec1 const T(3.0); + glm::vec3 const O(1.0f, 2.0f, 3.0f); + + glm::vec3 const A(R); + glm::vec3 const B(1.0); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + + glm::vec3 const C(R, S, T); + Error += glm::all(glm::equal(C, O)) ? 0 : 1; + + glm::vec3 const D(R, 2.0, 3.0); + Error += glm::all(glm::equal(D, O)) ? 0 : 1; + + glm::vec3 const E(1.0f, S, 3.0); + Error += glm::all(glm::equal(E, O)) ? 0 : 1; + + glm::vec3 const F(1.0, S, T); + Error += glm::all(glm::equal(F, O)) ? 0 : 1; + + glm::vec3 const G(R, 2.0, T); + Error += glm::all(glm::equal(G, O)) ? 0 : 1; + + glm::vec3 const H(R, S, 3.0); + Error += glm::all(glm::equal(H, O)) ? 0 : 1; + } + return Error; }