mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 02:04:35 +00:00
Added matrix relationak function taking ULPs
This commit is contained in:
parent
6b622f2ed4
commit
0f4a597f10
@ -36,6 +36,16 @@ namespace glm
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> equal(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y);
|
||||
|
||||
/// Perform a component-wise not-equal-to comparison of two matrices.
|
||||
/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix
|
||||
/// @tparam T Floating-point or integer scalar types
|
||||
/// @tparam Q Value from qualifier enum
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y);
|
||||
|
||||
/// Returns the component-wise comparison of |x - y| < epsilon.
|
||||
/// True if this expression is satisfied.
|
||||
///
|
||||
@ -56,16 +66,6 @@ namespace glm
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> equal(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, vec<C, T, Q> const& epsilon);
|
||||
|
||||
/// Perform a component-wise not-equal-to comparison of two matrices.
|
||||
/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix
|
||||
/// @tparam T Floating-point or integer scalar types
|
||||
/// @tparam Q Value from qualifier enum
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y);
|
||||
|
||||
/// Returns the component-wise comparison of |x - y| < epsilon.
|
||||
/// True if this expression is not satisfied.
|
||||
///
|
||||
@ -86,6 +86,46 @@ namespace glm
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, vec<C, T, Q> const& epsilon);
|
||||
|
||||
/// Returns the component-wise comparison between two vectors in term of ULPs.
|
||||
/// True if this expression is satisfied.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix
|
||||
/// @tparam T Floating-point
|
||||
/// @tparam Q Value from qualifier enum
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> equal(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, int ULPs);
|
||||
|
||||
/// Returns the component-wise comparison between two vectors in term of ULPs.
|
||||
/// True if this expression is satisfied.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix
|
||||
/// @tparam T Floating-point
|
||||
/// @tparam Q Value from qualifier enum
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> equal(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, vec<C, int, Q> const& ULPs);
|
||||
|
||||
/// Returns the component-wise comparison between two vectors in term of ULPs.
|
||||
/// True if this expression is not satisfied.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix
|
||||
/// @tparam T Floating-point
|
||||
/// @tparam Q Value from qualifier enum
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, int ULPs);
|
||||
|
||||
/// Returns the component-wise comparison between two vectors in term of ULPs.
|
||||
/// True if this expression is not satisfied.
|
||||
///
|
||||
/// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix
|
||||
/// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix
|
||||
/// @tparam T Floating-point
|
||||
/// @tparam Q Value from qualifier enum
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, vec<C, int, Q> const& ULPs);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
|
@ -48,4 +48,35 @@ namespace glm
|
||||
Result[i] = any(notEqual(a[i], b[i], Epsilon[i]));
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<C, bool, Q> equal(mat<C, R, T, Q> const& a, mat<C, R, T, Q> const& b, int MaxULPs)
|
||||
{
|
||||
return equal(a, b, vec<C, int, Q>(MaxULPs));
|
||||
}
|
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<C, bool, Q> equal(mat<C, R, T, Q> const& a, mat<C, R, T, Q> const& b, vec<C, int, Q> const& MaxULPs)
|
||||
{
|
||||
vec<C, bool, Q> Result(true);
|
||||
for(length_t i = 0; i < C; ++i)
|
||||
Result[i] = all(equal(a[i], b[i], MaxULPs[i]));
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, int MaxULPs)
|
||||
{
|
||||
return notEqual(x, y, vec<C, int, Q>(MaxULPs));
|
||||
}
|
||||
|
||||
template<length_t C, length_t R, typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& a, mat<C, R, T, Q> const& b, vec<C, int, Q> const& MaxULPs)
|
||||
{
|
||||
vec<C, bool, Q> Result(true);
|
||||
for(length_t i = 0; i < C; ++i)
|
||||
Result[i] = any(notEqual(a[i], b[i], MaxULPs[i]));
|
||||
return Result;
|
||||
}
|
||||
|
||||
}//namespace glm
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/gtc/ulp.hpp>
|
||||
|
||||
template <typename matType, typename vecType>
|
||||
static int test_equal()
|
||||
@ -58,10 +59,66 @@ static int test_notEqual()
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static int test_equal_ulps()
|
||||
{
|
||||
typedef glm::mat<4, 4, T, glm::defaultp> mat4;
|
||||
|
||||
T const One(1);
|
||||
mat4 const Ones(1);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
T const ULP1Plus = glm::next_float(One);
|
||||
Error += glm::all(glm::equal(Ones, mat4(ULP1Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Plus = glm::next_float(ULP1Plus);
|
||||
Error += !glm::all(glm::equal(Ones, mat4(ULP2Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP1Minus = glm::prev_float(One);
|
||||
Error += glm::all(glm::equal(Ones, mat4(ULP1Minus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Minus = glm::prev_float(ULP1Minus);
|
||||
Error += !glm::all(glm::equal(Ones, mat4(ULP2Minus), 1)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_notEqual_ulps()
|
||||
{
|
||||
typedef glm::mat<4, 4, T, glm::defaultp> mat4;
|
||||
|
||||
T const One(1);
|
||||
mat4 const Ones(1);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
T const ULP1Plus = glm::next_float(One);
|
||||
Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Plus = glm::next_float(ULP1Plus);
|
||||
Error += glm::all(glm::notEqual(Ones, mat4(ULP2Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP1Minus = glm::prev_float(One);
|
||||
Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Minus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Minus = glm::prev_float(ULP1Minus);
|
||||
Error += glm::all(glm::notEqual(Ones, mat4(ULP2Minus), 1)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_equal_ulps<float>();
|
||||
Error += test_equal_ulps<double>();
|
||||
Error += test_notEqual_ulps<float>();
|
||||
Error += test_notEqual_ulps<double>();
|
||||
|
||||
Error += test_equal<glm::mat2x2, glm::vec2>();
|
||||
Error += test_equal<glm::mat2x3, glm::vec2>();
|
||||
Error += test_equal<glm::mat2x4, glm::vec2>();
|
||||
|
Loading…
Reference in New Issue
Block a user