glm/test/gtc/gtc_epsilon.cpp

89 lines
2.3 KiB
C++
Raw Permalink Normal View History

2012-09-19 13:34:23 +00:00
///////////////////////////////////////////////////////////////////////////////////////////////////
2013-02-20 15:21:56 +00:00
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
2012-09-19 13:34:23 +00:00
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2012-09-19
// Updated : 2012-09-19
// Licence : This source is under MIT licence
// File : test/gtc/epsilon.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/half_float.hpp>
2012-09-19 13:34:23 +00:00
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
2012-09-19 13:34:23 +00:00
int test_defined()
{
glm::epsilonEqual(glm::vec2(), glm::vec2(), glm::vec2());
glm::epsilonEqual(glm::vec3(), glm::vec3(), glm::vec3());
glm::epsilonEqual(glm::vec4(), glm::vec4(), glm::vec4());
glm::epsilonNotEqual(glm::vec2(), glm::vec2(), glm::vec2());
glm::epsilonNotEqual(glm::vec3(), glm::vec3(), glm::vec3());
glm::epsilonNotEqual(glm::vec4(), glm::vec4(), glm::vec4());
2012-12-22 13:30:46 +00:00
glm::epsilonEqual(glm::vec2(), glm::vec2(), 0.0f);
glm::epsilonEqual(glm::vec3(), glm::vec3(), 0.0f);
glm::epsilonEqual(glm::vec4(), glm::vec4(), 0.0f);
glm::epsilonEqual(glm::quat(), glm::quat(), 0.0f);
glm::epsilonNotEqual(glm::vec2(), glm::vec2(), 0.0f);
glm::epsilonNotEqual(glm::vec3(), glm::vec3(), 0.0f);
glm::epsilonNotEqual(glm::vec4(), glm::vec4(), 0.0f);
glm::epsilonNotEqual(glm::quat(), glm::quat(), 0.0f);
return 0;
}
template <typename T>
int test_equal()
2012-09-19 13:34:23 +00:00
{
int Error(0);
2012-11-05 23:44:48 +00:00
{
T A = glm::epsilon<T>();
T B = glm::epsilon<T>();
2012-11-06 01:26:31 +00:00
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
2012-11-05 23:44:48 +00:00
}
{
T A(0);
T B = T(0) + glm::epsilon<T>();
2012-11-06 01:26:31 +00:00
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
2012-11-05 23:44:48 +00:00
}
{
T A(0);
T B = T(0) - glm::epsilon<T>();
2012-11-06 01:26:31 +00:00
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
2012-11-05 23:44:48 +00:00
}
{
T A = T(0) + glm::epsilon<T>();
T B = T(0);
2012-11-06 01:26:31 +00:00
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
2012-11-05 23:44:48 +00:00
}
{
T A = T(0) - glm::epsilon<T>();
T B = T(0);
2012-11-06 01:26:31 +00:00
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
2012-11-05 23:44:48 +00:00
}
return Error;
}
2012-09-19 13:34:23 +00:00
int main()
{
int Error(0);
2012-09-19 13:34:23 +00:00
Error += test_defined();
2012-11-05 23:44:48 +00:00
Error += test_equal<glm::half>();
Error += test_equal<float>();
Error += test_equal<double>();
2012-09-19 13:34:23 +00:00
return Error;
}