Added GLM_FORCE_EXPLICIT_CTOR to require explicit type conversions #269

master
Christophe Riccio ago%!(EXTRA string=11 years)
parent 9c62eee507
commit 3adf263341
  1. BIN
      doc/glm.docx
  2. 6
      glm/detail/type_mat2x2.hpp
  3. 7
      glm/detail/type_mat2x3.hpp
  4. 6
      glm/detail/type_mat2x4.hpp
  5. 8
      glm/detail/type_mat3x2.hpp
  6. 8
      glm/detail/type_mat3x3.hpp
  7. 7
      glm/detail/type_mat3x4.hpp
  8. 7
      glm/detail/type_mat4x2.hpp
  9. 7
      glm/detail/type_mat4x3.hpp
  10. 7
      glm/detail/type_mat4x4.hpp
  11. 9
      glm/gtc/quaternion.hpp
  12. 9
      glm/gtc/quaternion.inl
  13. 8
      glm/gtx/dual_quaternion.hpp
  14. 11
      glm/gtx/dual_quaternion.inl
  15. 1
      readme.txt
  16. 137
      test/core/core_func_common.cpp
  17. 11
      test/core/core_type_mat4x4.cpp

Binary file not shown.

@ -92,8 +92,14 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x2(tmat2x2<U, Q> const & m); GLM_FUNC_DECL explicit tmat2x2(tmat2x2<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat2x2(tmat2x2<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat2x2(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat2x2(tmat3x3<T, P> const & x);
GLM_FUNC_DECL explicit tmat2x2(tmat4x4<T, P> const & x); GLM_FUNC_DECL explicit tmat2x2(tmat4x4<T, P> const & x);

@ -75,6 +75,7 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Conversions // Conversions
template <typename X1, typename Y1, typename Z1, typename X2, typename Y2, typename Z2> template <typename X1, typename Y1, typename Z1, typename X2, typename Y2, typename Z2>
GLM_FUNC_DECL tmat2x3( GLM_FUNC_DECL tmat2x3(
X1 const & x1, Y1 const & y1, Z1 const & z1, X1 const & x1, Y1 const & y1, Z1 const & z1,
@ -87,8 +88,14 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Matrix conversion // Matrix conversion
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x3(tmat2x3<U, Q> const & m); GLM_FUNC_DECL explicit tmat2x3(tmat2x3<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat2x3(tmat2x3<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat2x3(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat2x3(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat2x3(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat2x3(tmat3x3<T, P> const & x);

@ -89,8 +89,14 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x4(tmat2x4<U, Q> const & m); GLM_FUNC_DECL explicit tmat2x4(tmat2x4<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat2x4(tmat2x4<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat2x4(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat2x4(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat2x4(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat2x4(tmat3x3<T, P> const & x);

@ -77,6 +77,7 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Conversions // Conversions
template< template<
typename X1, typename Y1, typename X1, typename Y1,
typename X2, typename Y2, typename X2, typename Y2,
@ -92,9 +93,16 @@ namespace glm
tvec2<V2, P> const & v2, tvec2<V2, P> const & v2,
tvec2<V3, P> const & v3); tvec2<V3, P> const & v3);
//////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x2(tmat3x2<U, Q> const & m); GLM_FUNC_DECL explicit tmat3x2(tmat3x2<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat3x2(tmat3x2<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat3x2(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat3x2(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat3x2(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat3x2(tmat3x3<T, P> const & x);

@ -81,6 +81,7 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Conversions // Conversions
template< template<
typename X1, typename Y1, typename Z1, typename X1, typename Y1, typename Z1,
typename X2, typename Y2, typename Z2, typename X2, typename Y2, typename Z2,
@ -96,9 +97,16 @@ namespace glm
tvec3<V2, P> const & v2, tvec3<V2, P> const & v2,
tvec3<V3, P> const & v3); tvec3<V3, P> const & v3);
//////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x3(tmat3x3<U, Q> const & m); GLM_FUNC_DECL explicit tmat3x3(tmat3x3<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat3x3(tmat3x3<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat3x3(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat3x3(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat3x3(tmat4x4<T, P> const & x); GLM_FUNC_DECL explicit tmat3x3(tmat4x4<T, P> const & x);

@ -92,9 +92,16 @@ namespace glm
tvec4<V2, P> const & v2, tvec4<V2, P> const & v2,
tvec4<V3, P> const & v3); tvec4<V3, P> const & v3);
//////////////////////////////////////
// Matrix conversion // Matrix conversion
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x4(tmat3x4<U, Q> const & m); GLM_FUNC_DECL explicit tmat3x4(tmat3x4<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat3x4(tmat3x4<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat3x4(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat3x4(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat3x4(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat3x4(tmat3x3<T, P> const & x);

@ -98,9 +98,16 @@ namespace glm
tvec2<V3, P> const & v3, tvec2<V3, P> const & v3,
tvec2<V4, P> const & v4); tvec2<V4, P> const & v4);
//////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x2(tmat4x2<U, Q> const & m); GLM_FUNC_DECL explicit tmat4x2(tmat4x2<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat4x2(tmat4x2<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat4x2(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat4x2(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x2(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat4x2(tmat3x3<T, P> const & x);

@ -97,9 +97,16 @@ namespace glm
tvec3<V3, P> const & v3, tvec3<V3, P> const & v3,
tvec3<V4, P> const & v4); tvec3<V4, P> const & v4);
//////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x3(tmat4x3<U, Q> const & m); GLM_FUNC_DECL explicit tmat4x3(tmat4x3<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat4x3(tmat4x3<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat4x3(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat4x3(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x3(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat4x3(tmat3x3<T, P> const & x);

@ -103,9 +103,16 @@ namespace glm
tvec4<V3, P> const & v3, tvec4<V3, P> const & v3,
tvec4<V4, P> const & v4); tvec4<V4, P> const & v4);
//////////////////////////////////////
// Matrix conversions // Matrix conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x4(tmat4x4<U, Q> const & m); GLM_FUNC_DECL explicit tmat4x4(tmat4x4<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat4x4(tmat4x4<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat4x4(tmat2x2<T, P> const & x); GLM_FUNC_DECL explicit tmat4x4(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x4(tmat3x3<T, P> const & x); GLM_FUNC_DECL explicit tmat4x4(tmat3x3<T, P> const & x);

@ -95,6 +95,14 @@ namespace glm
////////////////////////////////////// //////////////////////////////////////
// Convertions // Convertions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tquat(tquat<U, Q> const & q);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tquat(tquat<U, Q> const & q);
# endif
/// Create a quaternion from two normalized axis /// Create a quaternion from two normalized axis
/// ///
/// @param u A first normalized axis /// @param u A first normalized axis
@ -102,6 +110,7 @@ namespace glm
/// @see gtc_quaternion /// @see gtc_quaternion
/// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors /// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
GLM_FUNC_DECL explicit tquat(tvec3<T, P> const & u, tvec3<T, P> const & v); GLM_FUNC_DECL explicit tquat(tvec3<T, P> const & u, tvec3<T, P> const & v);
/// Build a quaternion from euler angles (pitch, yaw, roll), in radians. /// Build a quaternion from euler angles (pitch, yaw, roll), in radians.
GLM_FUNC_DECL explicit tquat(tvec3<T, P> const & eulerAngles); GLM_FUNC_DECL explicit tquat(tvec3<T, P> const & eulerAngles);
GLM_FUNC_DECL explicit tquat(tmat3x3<T, P> const & m); GLM_FUNC_DECL explicit tquat(tmat3x3<T, P> const & m);

@ -112,6 +112,15 @@ namespace detail
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// Conversions // Conversions
template <typename T, precision P>
template <typename U, precision Q>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tquat<U, Q> const & q)
: x(static_cast<T>(q.x))
, y(static_cast<T>(q.y))
, z(static_cast<T>(q.z))
, w(static_cast<T>(q.w))
{}
//template <typename valType> //template <typename valType>
//GLM_FUNC_QUALIFIER tquat<valType>::tquat //GLM_FUNC_QUALIFIER tquat<valType>::tquat
//( //(

@ -89,6 +89,14 @@ namespace glm
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// tdualquat conversions // tdualquat conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tdualquat(tdualquat<U, Q> const & q);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tdualquat(tdualquat<U, Q> const & q);
# endif
GLM_FUNC_DECL explicit tdualquat(tmat2x4<T, P> const & holder_mat); GLM_FUNC_DECL explicit tdualquat(tmat2x4<T, P> const & holder_mat);
GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat); GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat);

@ -56,7 +56,8 @@ namespace glm
template <typename T, precision P> template <typename T, precision P>
template <precision Q> template <precision Q>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<T, Q> const & d) GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<T, Q> const & d)
: real(d.real), dual(d.dual) : real(d.real)
, dual(d.dual)
{} {}
////////////////////////////////////// //////////////////////////////////////
@ -87,6 +88,14 @@ namespace glm
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// tdualquat conversions // tdualquat conversions
template <typename T, precision P>
template <typename U, precision Q>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<U, Q> const & q)
: real(q.real)
, dual(q.dual)
{}
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat2x4<T, P> const & m) GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat2x4<T, P> const & m)
{ {

@ -57,6 +57,7 @@ Features:
- Added GTC_bitfield extension, promoted GTX_bit - Added GTC_bitfield extension, promoted GTX_bit
- Added GTC_integer extension, promoted GTX_bit - Added GTC_integer extension, promoted GTX_bit
- Added GTC_round extension, promoted GTX_bit - Added GTC_round extension, promoted GTX_bit
- Added GLM_FORCE_EXPLICIT_CTOR to require explicit type conversions #269
Improvements: Improvements:
- Rely on C++11 to implement isinf and isnan - Rely on C++11 to implement isinf and isnan

@ -7,6 +7,8 @@
// File : test/core/func_common.cpp // File : test/core/func_common.cpp
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_FORCE_EXPLICIT_CTOR
#include <glm/common.hpp>
#include <glm/gtc/constants.hpp> #include <glm/gtc/constants.hpp>
#include <glm/gtc/epsilon.hpp> #include <glm/gtc/epsilon.hpp>
#include <glm/gtc/vec1.hpp> #include <glm/gtc/vec1.hpp>
@ -16,7 +18,9 @@
#include <cmath> #include <cmath>
#include <ctime> #include <ctime>
int test_floor() namespace floor_
{
int test()
{ {
int Error(0); int Error(0);
@ -88,8 +92,11 @@ int test_floor()
return Error; return Error;
} }
}//namespace floor
int test_modf() namespace modf_
{
int test()
{ {
int Error(0); int Error(0);
@ -131,8 +138,11 @@ int test_modf()
return Error; return Error;
} }
}//namespace modf
int test_floatBitsToInt() namespace floatBitsToInt
{
int test()
{ {
int Error = 0; int Error = 0;
@ -177,8 +187,11 @@ int test_floatBitsToInt()
return Error; return Error;
} }
}//namespace floatBitsToInt
int test_floatBitsToUint() namespace floatBitsToUint
{
int test()
{ {
int Error = 0; int Error = 0;
@ -222,8 +235,11 @@ int test_floatBitsToUint()
return Error; return Error;
} }
}//namespace floatBitsToUint
int test_min() namespace min_
{
int test()
{ {
int Error = 0; int Error = 0;
@ -246,8 +262,11 @@ int test_min()
return Error; return Error;
} }
}//namespace min_
int test_max() namespace max_
{
int test()
{ {
int Error = 0; int Error = 0;
@ -270,18 +289,22 @@ int test_max()
return Error; return Error;
} }
}//namespace max_
int test_clamp() namespace clamp_
{
int test()
{ {
int Error = 0; int Error = 0;
return Error; return Error;
} }
}//namespace clamp_
namespace test_mix namespace mix_
{ {
template <typename T, typename B> template <typename T, typename B>
struct test struct entry
{ {
T x; T x;
T y; T y;
@ -289,7 +312,7 @@ namespace test_mix
T Result; T Result;
}; };
test<float, bool> TestBool[] = entry<float, bool> TestBool[] =
{ {
{0.0f, 1.0f, false, 0.0f}, {0.0f, 1.0f, false, 0.0f},
{0.0f, 1.0f, true, 1.0f}, {0.0f, 1.0f, true, 1.0f},
@ -297,7 +320,7 @@ namespace test_mix
{-1.0f, 1.0f, true, 1.0f} {-1.0f, 1.0f, true, 1.0f}
}; };
test<float, float> TestFloat[] = entry<float, float> TestFloat[] =
{ {
{0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 1.0f, 1.0f, 1.0f},
@ -305,7 +328,7 @@ namespace test_mix
{-1.0f, 1.0f, 1.0f, 1.0f} {-1.0f, 1.0f, 1.0f, 1.0f}
}; };
test<glm::vec2, bool> TestVec2Bool[] = entry<glm::vec2, bool> TestVec2Bool[] =
{ {
{glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)}, {glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)},
{glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}, {glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)},
@ -313,7 +336,7 @@ namespace test_mix
{glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)} {glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}
}; };
test<glm::vec2, glm::bvec2> TestBVec2[] = entry<glm::vec2, glm::bvec2> TestBVec2[] =
{ {
{glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)}, {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)},
{glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)}, {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
@ -322,7 +345,7 @@ namespace test_mix
{glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)} {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)}
}; };
test<glm::vec3, bool> TestVec3Bool[] = entry<glm::vec3, bool> TestVec3Bool[] =
{ {
{glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)}, {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)},
{glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}, {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)},
@ -330,7 +353,7 @@ namespace test_mix
{glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)} {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}
}; };
test<glm::vec3, glm::bvec3> TestBVec3[] = entry<glm::vec3, glm::bvec3> TestBVec3[] =
{ {
{glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)}, {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)},
{glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)}, {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
@ -339,7 +362,7 @@ namespace test_mix
{glm::vec3(1.0f, 2.0f, 3.0f), glm::vec3(4.0f, 5.0f, 6.0f), glm::bvec3(true, false, true), glm::vec3(4.0f, 2.0f, 6.0f)} {glm::vec3(1.0f, 2.0f, 3.0f), glm::vec3(4.0f, 5.0f, 6.0f), glm::bvec3(true, false, true), glm::vec3(4.0f, 2.0f, 6.0f)}
}; };
test<glm::vec4, bool> TestVec4Bool[] = entry<glm::vec4, bool> TestVec4Bool[] =
{ {
{glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)}, {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)},
{glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}, {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)},
@ -347,7 +370,7 @@ namespace test_mix
{glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)} {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}
}; };
test<glm::vec4, glm::bvec4> TestBVec4[] = entry<glm::vec4, glm::bvec4> TestBVec4[] =
{ {
{glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(0.0f)}, {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(0.0f)},
{glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)}, {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
@ -356,13 +379,13 @@ namespace test_mix
{glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(5.0f, 6.0f, 7.0f, 8.0f), glm::bvec4(true, false, true, false), glm::vec4(5.0f, 2.0f, 7.0f, 4.0f)} {glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(5.0f, 6.0f, 7.0f, 8.0f), glm::bvec4(true, false, true, false), glm::vec4(5.0f, 2.0f, 7.0f, 4.0f)}
}; };
int run() int test()
{ {
int Error = 0; int Error = 0;
// Float with bool // Float with bool
{ {
for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(test<float, bool>); ++i) for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(entry<float, bool>); ++i)
{ {
float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a); float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a);
Error += glm::epsilonEqual(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1;
@ -371,7 +394,7 @@ namespace test_mix
// Float with float // Float with float
{ {
for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(test<float, float>); ++i) for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(entry<float, float>); ++i)
{ {
float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a); float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a);
Error += glm::epsilonEqual(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1;
@ -380,7 +403,7 @@ namespace test_mix
// vec2 with bool // vec2 with bool
{ {
for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(test<glm::vec2, bool>); ++i) for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(entry<glm::vec2, bool>); ++i)
{ {
glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a); glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a);
Error += glm::epsilonEqual(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
@ -390,7 +413,7 @@ namespace test_mix
// vec2 with bvec2 // vec2 with bvec2
{ {
for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(test<glm::vec2, glm::bvec2>); ++i) for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(entry<glm::vec2, glm::bvec2>); ++i)
{ {
glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a); glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a);
Error += glm::epsilonEqual(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
@ -400,7 +423,7 @@ namespace test_mix
// vec3 with bool // vec3 with bool
{ {
for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(test<glm::vec3, bool>); ++i) for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(entry<glm::vec3, bool>); ++i)
{ {
glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a); glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a);
Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
@ -411,7 +434,7 @@ namespace test_mix
// vec3 with bvec3 // vec3 with bvec3
{ {
for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(test<glm::vec3, glm::bvec3>); ++i) for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(entry<glm::vec3, glm::bvec3>); ++i)
{ {
glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a); glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a);
Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
@ -422,7 +445,7 @@ namespace test_mix
// vec4 with bool // vec4 with bool
{ {
for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(test<glm::vec4, bool>); ++i) for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(entry<glm::vec4, bool>); ++i)
{ {
glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a); glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a);
Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
@ -434,7 +457,7 @@ namespace test_mix
// vec4 with bvec4 // vec4 with bvec4
{ {
for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(test<glm::vec4, glm::bvec4>); ++i) for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(entry<glm::vec4, glm::bvec4>); ++i)
{ {
glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a); glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a);
Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1; Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
@ -446,26 +469,26 @@ namespace test_mix
return Error; return Error;
} }
}//namespace test_mix }//namespace mix_
namespace test_step namespace step_
{ {
template <typename EDGE, typename VEC> template <typename EDGE, typename VEC>
struct test struct entry
{ {
EDGE edge; EDGE edge;
VEC x; VEC x;
VEC result; VEC result;
}; };
test<float, glm::vec4> TestVec4Scalar [] = entry<float, glm::vec4> TestVec4Scalar [] =
{ {
{ 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) }, { 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
{ 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) }, { 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
{ 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) } { 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
}; };
test<glm::vec4, glm::vec4> TestVec4Vector [] = entry<glm::vec4, glm::vec4> TestVec4Vector [] =
{ {
{ glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) }, { glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
{ glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) }, { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
@ -473,13 +496,13 @@ namespace test_step
{ glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) } { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
}; };
int run() int test()
{ {
int Error = 0; int Error = 0;
// vec4 and float // vec4 and float
{ {
for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(test<float, glm::vec4>); ++i) for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(entry<float, glm::vec4>); ++i)
{ {
glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x); glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1; Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
@ -488,7 +511,7 @@ namespace test_step
// vec4 and vec4 // vec4 and vec4
{ {
for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(test<glm::vec4, glm::vec4>); ++i) for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(entry<glm::vec4, glm::vec4>); ++i)
{ {
glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x); glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1; Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
@ -497,9 +520,11 @@ namespace test_step
return Error; return Error;
} }
}//namespace test_step }//namespace step_
int test_round() namespace round_
{
int test()
{ {
int Error = 0; int Error = 0;
@ -539,8 +564,11 @@ int test_round()
return Error; return Error;
} }
}//namespace round_
int test_roundEven() namespace roundEven
{
int test()
{ {
int Error = 0; int Error = 0;
@ -682,8 +710,11 @@ int test_roundEven()
return Error; return Error;
} }
}//namespace roundEven
int test_isnan() namespace isnan_
{
int test()
{ {
int Error = 0; int Error = 0;
@ -706,8 +737,11 @@ int test_isnan()
return Error; return Error;
} }
}//namespace isnan_
int test_isinf() namespace isinf_
{
int test()
{ {
int Error = 0; int Error = 0;
@ -738,6 +772,7 @@ int test_isinf()
return Error; return Error;
} }
}//namespace isinf_
namespace sign namespace sign
{ {
@ -1018,18 +1053,18 @@ int main()
int Error(0); int Error(0);
Error += sign::test(); Error += sign::test();
Error += test_floor(); Error += floor_::test();
Error += test_modf(); Error += modf_::test();
Error += test_floatBitsToInt(); Error += floatBitsToInt::test();
Error += test_floatBitsToUint(); Error += floatBitsToUint::test();
Error += test_step::run(); Error += step_::test();
Error += test_max(); Error += max_::test();
Error += test_min(); Error += min_::test();
Error += test_mix::run(); Error += mix_::test();
Error += test_round(); Error += round_::test();
Error += test_roundEven(); Error += roundEven::test();
Error += test_isnan(); Error += isnan_::test();
Error += test_isinf(); Error += isinf_::test();
# ifdef GLM_TEST_ENABLE_PERF # ifdef GLM_TEST_ENABLE_PERF
Error += sign::perf(); Error += sign::perf();

@ -13,16 +13,9 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
void print(glm::dmat4 const & Mat0)
{
printf("mat4(\n");
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[1][0], Mat0[1][1], Mat0[1][2], Mat0[1][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[2][0], Mat0[2][1], Mat0[2][2], Mat0[2][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f))\n\n", Mat0[3][0], Mat0[3][1], Mat0[3][2], Mat0[3][3]);
}
void print(glm::mat4 const & Mat0) template <typename genType>
void print(genType const & Mat0)
{ {
printf("mat4(\n"); printf("mat4(\n");
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]); printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);

Loading…
Cancel
Save