Added vec1 based constructors to vec3 with tests and fixed build

This commit is contained in:
Groove 2018-07-06 21:08:06 +02:00
parent 97ad14cf82
commit f5e27805af
6 changed files with 113 additions and 20 deletions

View File

@ -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<typename U, qualifier P>
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<typename A, typename B>
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A x, B y);

View File

@ -34,11 +34,6 @@ namespace glm
: x(scalar), y(scalar)
{}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(vec<1, T, P> const& v)
: x(v.x), y(v.x)
{}
template<typename T, qualifier Q>
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<typename T, qualifier Q>
template<typename U, qualifier P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(vec<1, U, P> const& v)
: x(static_cast<T>(v.x))
, y(static_cast<T>(v.x))
{}
template<typename T, qualifier Q>
template<typename A, typename B>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, Q>::vec(A _x, B _y)

View File

@ -98,6 +98,9 @@ namespace glm
// -- Conversion scalar constructors --
template<typename U, qualifier P>
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<typename X, typename Y, typename Z>
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X x, Y y, Z z);

View File

@ -41,6 +41,14 @@ namespace glm
// -- Conversion scalar constructors --
template<typename T, qualifier Q>
template<typename U, qualifier P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, U, P> const& v)
: x(static_cast<T>(v.x))
, y(static_cast<T>(v.x))
, z(static_cast<T>(v.x))
{}
template<typename T, qualifier Q>
template<typename X, typename Y, typename Z>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(X _x, Y _y, Z _z)
@ -52,7 +60,7 @@ namespace glm
template<typename T, qualifier Q>
template<typename X, typename Y, typename Z>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, Z _z)
: x(static_cast<T>(_x))
: x(static_cast<T>(_x.x))
, y(static_cast<T>(_y))
, z(static_cast<T>(_z))
{}
@ -61,15 +69,15 @@ namespace glm
template<typename X, typename Y, typename Z>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, Z _z)
: x(static_cast<T>(_x))
, y(static_cast<T>(_y))
, y(static_cast<T>(_y.x))
, z(static_cast<T>(_z))
{}
template<typename T, qualifier Q>
template<typename X, typename Y, typename Z>
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<T>(_x))
, y(static_cast<T>(_y))
: x(static_cast<T>(_x.x))
, y(static_cast<T>(_y.x))
, z(static_cast<T>(_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<T>(_x))
, y(static_cast<T>(_y))
, z(static_cast<T>(_z))
, z(static_cast<T>(_z.x))
{}
template<typename T, qualifier Q>
template<typename X, typename Y, typename Z>
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<T>(_x))
: x(static_cast<T>(_x.x))
, y(static_cast<T>(_y))
, z(static_cast<T>(_z))
, z(static_cast<T>(_z.x))
{}
template<typename T, qualifier Q>
template<typename X, typename Y, typename Z>
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<T>(_x))
, y(static_cast<T>(_y))
, z(static_cast<T>(_z))
, y(static_cast<T>(_y.x))
, z(static_cast<T>(_z.x))
{}
template<typename T, qualifier Q>
template<typename X, typename Y, typename Z>
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<T>(_x))
, y(static_cast<T>(_y))
, z(static_cast<T>(_z))
: x(static_cast<T>(_x.x))
, y(static_cast<T>(_y.x))
, z(static_cast<T>(_z.x))
{}
// -- Conversion vector constructors --

View File

@ -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;
}

View File

@ -1,4 +1,5 @@
#define GLM_FORCE_SWIZZLE
#include <glm/ext/vec1.hpp>
#include <glm/vector_relational.hpp>
#include <glm/geometric.hpp>
#include <glm/vec2.hpp>
@ -83,6 +84,64 @@ int test_vec3_ctor()
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;
}