Added EXT_quaternion_relational and EXT_quaternion_geometric extensions

This commit is contained in:
Christophe Riccio
2018-08-08 18:36:20 +02:00
parent 8288f17558
commit ba8ee44b19
14 changed files with 549 additions and 229 deletions

View File

@@ -1,4 +1,6 @@
glmCreateTestGTC(ext_matrix_relational)
glmCreateTestGTC(ext_quaternion_relational)
glmCreateTestGTC(ext_quaternion_type)
glmCreateTestGTC(ext_scalar_relational)
glmCreateTestGTC(ext_vec1)
glmCreateTestGTC(ext_vector_vec1)

View File

@@ -0,0 +1,127 @@
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/ext/vector_float1.hpp>
#include <glm/ext/vector_float1_precision.hpp>
#include <glm/ext/vector_float2.hpp>
#include <glm/ext/vector_float3.hpp>
#include <glm/ext/vector_float4.hpp>
template <typename genType>
static int test_operators()
{
int Error = 0;
{
genType const A(1);
genType const B(1);
genType const C = A + B;
Error += glm::all(glm::equal(C, genType(2), glm::epsilon<float>())) ? 0 : 1;
genType const D = A - B;
Error += glm::all(glm::equal(D, genType(0), glm::epsilon<float>())) ? 0 : 1;
genType const E = A * B;
Error += glm::all(glm::equal(E, genType(1), glm::epsilon<float>())) ? 0 : 1;
genType const F = A / B;
Error += glm::all(glm::equal(F, genType(1), glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
template <typename genType>
static int test_ctor()
{
int Error = 0;
glm::vec1 const A = genType(1);
glm::vec1 const E(genType(1));
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
glm::vec1 const F(E);
Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1;
genType const B = genType(1);
genType const G(glm::vec2(1));
Error += glm::all(glm::equal(B, G, glm::epsilon<float>())) ? 0 : 1;
genType const H(glm::vec3(1));
Error += glm::all(glm::equal(B, H, glm::epsilon<float>())) ? 0 : 1;
genType const I(glm::vec4(1));
Error += glm::all(glm::equal(B, I, glm::epsilon<float>())) ? 0 : 1;
return Error;
}
template <typename genType>
static int test_size()
{
int Error = 0;
Error += sizeof(glm::vec1) == sizeof(genType) ? 0 : 1;
Error += genType().length() == 1 ? 0 : 1;
Error += genType::length() == 1 ? 0 : 1;
return Error;
}
template <typename genType>
static int test_relational()
{
int Error = 0;
genType const A(1);
genType const B(1);
genType const C(0);
Error += all(equal(A, B, glm::epsilon<float>())) ? 0 : 1;
Error += any(notEqual(A, C, glm::epsilon<float>())) ? 0 : 1;
return Error;
}
template <typename genType>
static int test_constexpr()
{
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
static_assert(genType::length() == 1, "GLM: Failed constexpr");
# endif
return 0;
}
int main()
{
int Error = 0;
Error += test_operators<glm::vec1>();
Error += test_operators<glm::lowp_vec1>();
Error += test_operators<glm::mediump_vec1>();
Error += test_operators<glm::highp_vec1>();
Error += test_ctor<glm::vec1>();
Error += test_ctor<glm::lowp_vec1>();
Error += test_ctor<glm::mediump_vec1>();
Error += test_ctor<glm::highp_vec1>();
Error += test_size<glm::vec1>();
Error += test_size<glm::lowp_vec1>();
Error += test_size<glm::mediump_vec1>();
Error += test_size<glm::highp_vec1>();
Error += test_relational<glm::vec1>();
Error += test_relational<glm::lowp_vec1>();
Error += test_relational<glm::mediump_vec1>();
Error += test_relational<glm::highp_vec1>();
Error += test_constexpr<glm::vec1>();
Error += test_constexpr<glm::lowp_vec1>();
Error += test_constexpr<glm::mediump_vec1>();
Error += test_constexpr<glm::highp_vec1>();
return Error;
}

View File

@@ -0,0 +1,113 @@
#include <glm/gtc/constants.hpp>
#include <glm/ext/quaternion_relational.hpp>
#include <glm/ext/quaternion_float.hpp>
#include <glm/ext/quaternion_float_precision.hpp>
#include <glm/ext/quaternion_double.hpp>
#include <glm/ext/quaternion_double_precision.hpp>
#include <glm/ext/vector_float3.hpp>
#include <vector>
static int test_ctr()
{
int Error(0);
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_default_constructible<glm::dquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::dquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::quat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::quat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::dquat>::value ? 0 : 1;
# endif
# if GLM_HAS_INITIALIZER_LISTS
{
glm::quat A{0, 1, 2, 3};
std::vector<glm::quat> B{
{0, 1, 2, 3},
{0, 1, 2, 3}};
}
# endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
static int test_two_axis_ctr()
{
int Error = 0;
glm::quat const q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
glm::vec3 const v1 = q1 * glm::vec3(1, 0, 0);
Error += glm::all(glm::equal(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1;
glm::quat const q2 = q1 * q1;
glm::vec3 const v2 = q2 * glm::vec3(1, 0, 0);
Error += glm::all(glm::equal(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
glm::quat const q3(glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0));
glm::vec3 const v3 = q3 * glm::vec3(1, 0, 0);
Error += glm::all(glm::equal(v3, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
glm::quat const q4(glm::vec3(0, 1, 0), glm::vec3(0, -1, 0));
glm::vec3 const v4 = q4 * glm::vec3(0, 1, 0);
Error += glm::all(glm::equal(v4, glm::vec3(0, -1, 0), 0.0001f)) ? 0 : 1;
glm::quat const q5(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1));
glm::vec3 const v5 = q5 * glm::vec3(0, 0, 1);
Error += glm::all(glm::equal(v5, glm::vec3(0, 0, -1), 0.0001f)) ? 0 : 1;
return Error;
}
static int test_size()
{
int Error = 0;
std::size_t const A = sizeof(glm::quat);
Error += 16 == A ? 0 : 1;
std::size_t const B = sizeof(glm::dquat);
Error += 32 == B ? 0 : 1;
Error += glm::quat().length() == 4 ? 0 : 1;
Error += glm::dquat().length() == 4 ? 0 : 1;
Error += glm::quat::length() == 4 ? 0 : 1;
Error += glm::dquat::length() == 4 ? 0 : 1;
return Error;
}
static int test_precision()
{
int Error = 0;
Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1;
Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1;
return Error;
}
static int test_constexpr()
{
#if GLM_HAS_CONSTEXPR
static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
#endif
return 0;
}
int main()
{
int Error = 0;
Error += test_ctr();
Error += test_two_axis_ctr();
Error += test_size();
Error += test_precision();
Error += test_constexpr();
return Error;
}

View File

@@ -73,16 +73,6 @@ int test_quat_mix()
return Error;
}
int test_quat_precision()
{
int Error = 0;
Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1;
Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1;
return Error;
}
int test_quat_normalize()
{
int Error(0);
@@ -204,7 +194,21 @@ int test_quat_slerp()
return Error;
}
int test_quat_mul()
static int test_quat_mul_vec()
{
int Error(0);
glm::quat q = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::vec3 v(1, 0, 0);
glm::vec3 u(q * v);
glm::vec3 w(u * q);
Error += glm::all(glm::equal(v, w, 0.01f)) ? 0 : 1;
return Error;
}
static int test_mul()
{
int Error = 0;
@@ -227,102 +231,6 @@ int test_quat_mul()
return Error;
}
int test_quat_two_axis_ctr()
{
int Error = 0;
glm::quat const q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
glm::vec3 const v1 = q1 * glm::vec3(1, 0, 0);
Error += glm::all(glm::equal(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1;
glm::quat const q2 = q1 * q1;
glm::vec3 const v2 = q2 * glm::vec3(1, 0, 0);
Error += glm::all(glm::equal(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
glm::quat const q3(glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0));
glm::vec3 const v3 = q3 * glm::vec3(1, 0, 0);
Error += glm::all(glm::equal(v3, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
glm::quat const q4(glm::vec3(0, 1, 0), glm::vec3(0, -1, 0));
glm::vec3 const v4 = q4 * glm::vec3(0, 1, 0);
Error += glm::all(glm::equal(v4, glm::vec3(0, -1, 0), 0.0001f)) ? 0 : 1;
glm::quat const q5(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1));
glm::vec3 const v5 = q5 * glm::vec3(0, 0, 1);
Error += glm::all(glm::equal(v5, glm::vec3(0, 0, -1), 0.0001f)) ? 0 : 1;
return Error;
}
int test_quat_mul_vec()
{
int Error(0);
glm::quat q = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::vec3 v(1, 0, 0);
glm::vec3 u(q * v);
glm::vec3 w(u * q);
Error += glm::all(glm::equal(v, w, 0.01f)) ? 0 : 1;
return Error;
}
int test_quat_ctr()
{
int Error(0);
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_default_constructible<glm::dquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::dquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::quat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::quat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::dquat>::value ? 0 : 1;
# endif
# if GLM_HAS_INITIALIZER_LISTS
{
glm::quat A{0, 1, 2, 3};
std::vector<glm::quat> B{
{0, 1, 2, 3},
{0, 1, 2, 3}};
}
# endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
int test_size()
{
int Error = 0;
std::size_t const A = sizeof(glm::quat);
Error += 16 == A ? 0 : 1;
std::size_t const B = sizeof(glm::dquat);
Error += 32 == B ? 0 : 1;
Error += glm::quat().length() == 4 ? 0 : 1;
Error += glm::dquat().length() == 4 ? 0 : 1;
Error += glm::quat::length() == 4 ? 0 : 1;
Error += glm::dquat::length() == 4 ? 0 : 1;
return Error;
}
static int test_constexpr()
{
#if GLM_HAS_CONSTEXPR
static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
#endif
return 0;
}
int test_identity()
{
int Error = 0;
@@ -344,19 +252,14 @@ int main()
{
int Error = 0;
Error += test_quat_ctr();
Error += test_mul();
Error += test_quat_mul_vec();
Error += test_quat_two_axis_ctr();
Error += test_quat_mul();
Error += test_quat_precision();
Error += test_quat_angle();
Error += test_quat_angleAxis();
Error += test_quat_mix();
Error += test_quat_normalize();
Error += test_quat_euler();
Error += test_quat_slerp();
Error += test_size();
Error += test_constexpr();
Error += test_identity();
return Error;