- Added missing equal and notEqual with epsilon for matrix types in EXT_vector_relational

This commit is contained in:
Groove 2018-07-26 00:03:31 +02:00
parent afde3b4645
commit 751bc4f7f7
4 changed files with 91 additions and 9 deletions

View File

@ -25,6 +25,28 @@ namespace glm
/// @addtogroup ext_vector_relational
/// @{
/// Returns the component-wise comparison of |x - y| < epsilon.
/// True if this expression is satisfied.
///
/// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
/// @tparam T Floating-point or integer scalar types
/// @tparam Q Value from qualifier enum
///
/// @see ext_vector_relational
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_DECL vec<C, bool, Q> equal(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, T epsilon);
/// Returns the component-wise comparison of |x - y| < epsilon.
/// True if this expression is satisfied.
///
/// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
/// @tparam T Floating-point or integer scalar types
/// @tparam Q Value from qualifier enum
///
/// @see ext_vector_relational
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_DECL 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);
/// Returns the component-wise comparison of |x - y| < epsilon.
/// True if this expression is satisfied.
///
@ -34,7 +56,7 @@ namespace glm
///
/// @see ext_vector_relational
template<length_t L, typename T, qualifier Q>
GLM_FUNC_DECL vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T const& epsilon);
GLM_FUNC_DECL vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon);
/// Returns the component-wise comparison of |x - y| < epsilon.
/// True if this expression is satisfied.
@ -64,10 +86,32 @@ namespace glm
/// @tparam Q Value from qualifier enum
///
/// @see ext_vector_relational
template<length_t L, typename T, qualifier Q>
GLM_FUNC_DECL vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T const& epsilon);
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_DECL vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, T epsilon);
/// Returns the component-wise comparison of |x - y| < epsilon.
/// Returns the component-wise comparison of |x - y| >= epsilon.
/// True if this expression is not satisfied.
///
/// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
/// @tparam T Floating-point or integer scalar types
/// @tparam Q Value from qualifier enum
///
/// @see ext_vector_relational
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_DECL 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 of |x - y| >= epsilon.
/// True if this expression is not satisfied.
///
/// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
/// @tparam T Floating-point or integer scalar types
/// @tparam Q Value from qualifier enum
///
/// @see ext_vector_relational
template<length_t L, typename T, qualifier Q>
GLM_FUNC_DECL vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon);
/// Returns the component-wise comparison of |x - y| >= epsilon.
/// True if this expression is not satisfied.
///
/// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector

View File

@ -15,9 +15,9 @@ namespace glm
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T const& epsilon)
GLM_FUNC_QUALIFIER vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon)
{
return lessThan(abs(x - y), vec<L, T, Q>(epsilon));
return equal(x, y, vec<L, T, Q>(epsilon));
}
template<length_t L, typename T, qualifier Q>
@ -26,6 +26,21 @@ namespace glm
return lessThan(abs(x - y), epsilon);
}
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<C, bool, Q> equal(mat<C, R, T, Q> const& a, mat<C, R, T, Q> const& b, T epsilon)
{
return equal(a, b, vec<C, T, Q>(epsilon));
}
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<C, bool, Q> equal(mat<C, R, T, Q> const& a, mat<C, R, T, Q> const& b, vec<C, T, Q> const& epsilon)
{
vec<C, bool, Q> Result;
for(length_t i = 0, n = C; i < n; ++i)
Result[i] = all(equal(a[i], b[i], epsilon[i]));
return Result;
}
template<typename genType>
GLM_FUNC_QUALIFIER bool notEqual(genType const& x, genType const& y, genType const& epsilon)
{
@ -33,9 +48,9 @@ namespace glm
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T const& epsilon)
GLM_FUNC_QUALIFIER vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T epsilon)
{
return greaterThanEqual(abs(x - y), vec<L, T, Q>(epsilon));
return notEqual(x, y, vec<L, T, Q>(epsilon));
}
template<length_t L, typename T, qualifier Q>
@ -43,4 +58,19 @@ namespace glm
{
return greaterThanEqual(abs(x - y), epsilon);
}
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& x, mat<C, R, T, Q> const& y, T epsilon)
{
return notEqual(x, y, vec<C, T, Q>(epsilon));
}
template<length_t C, length_t R, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<C, bool, Q> notEqual(mat<C, R, T, Q> const& a, mat<C, R, T, Q> const& b, vec<C, T, Q> const& epsilon)
{
vec<C, bool, Q> Result;
for(length_t i = 0, n = C; i < n; ++i)
Result[i] = any(notEqual(a[i], b[i], epsilon[i]));
return Result;
}
}//namespace glm

View File

@ -61,7 +61,8 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
- Added missing vec1 based constructors
- Redesigned constexpr support which excludes both SIMD and constexpr #783
- Added detection of Visual C++ 2017 toolsets
- Added missing equal and notEqual with epsilon for quaternion types
- Added missing equal and notEqual with epsilon for quaternion types in EXT_vector_relational
- Added missing equal and notEqual with epsilon for matrix types in EXT_vector_relational
#### Fixes:
- Fixed build problems due to printf and std::clock_t #778

View File

@ -1,5 +1,6 @@
#include <glm/ext/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <glm/mat4x3.hpp>
int test_equal()
{
@ -13,6 +14,9 @@ int test_equal()
Error += !glm::any(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), 0.001f)) ? 0 : 1;
Error += !glm::any(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.001f))) ? 0 : 1;
Error += glm::all(glm::equal(glm::mat4x3(1), glm::mat4x3(1), 0.001f)) ? 0 : 1;
Error += glm::all(glm::equal(glm::mat4x3(1), glm::mat4x3(2), glm::vec4(0.001f))) ? 1 : 0;
return Error;
}
@ -28,6 +32,9 @@ int test_notEqual()
Error += !glm::any(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), 0.1f)) ? 0 : 1;
Error += !glm::any(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.1f))) ? 0 : 1;
Error += !glm::any(glm::notEqual(glm::mat4x3(1), glm::mat4x3(1), 0.001f)) ? 0 : 1;
Error += !glm::any(glm::notEqual(glm::mat4x3(1), glm::mat4x3(2), glm::vec4(0.001f))) ? 1 : 0;
return Error;
}