parent
68a829e7ed
commit
de28722e36
11 changed files with 197 additions and 4 deletions
@ -0,0 +1,93 @@ |
||||
/// @ref ext_vector_relational
|
||||
/// @file glm/ext/vector_relational.hpp
|
||||
///
|
||||
/// @see core (dependence)
|
||||
///
|
||||
/// @defgroup ext_vector_relational GLM_EXT_vector_relational
|
||||
/// @ingroup ext
|
||||
///
|
||||
/// Include <glm/ext/vector_relational.hpp> to use the features of this extension.
|
||||
///
|
||||
/// Comparison functions for a user defined epsilon values.
|
||||
|
||||
#pragma once |
||||
|
||||
// Dependencies
|
||||
#include "../detail/setup.hpp" |
||||
#include "../detail/qualifier.hpp" |
||||
|
||||
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) |
||||
# pragma message("GLM: GLM_EXT_vector_relational extension included") |
||||
#endif |
||||
|
||||
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 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); |
||||
|
||||
/// 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 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, vec<L, T, Q> const& epsilon); |
||||
|
||||
/// Returns the component-wise comparison of |x - y| < epsilon.
|
||||
/// True if this expression is satisfied.
|
||||
///
|
||||
/// @tparam genType Floating-point or integer scalar types
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<typename genType> |
||||
GLM_FUNC_DECL bool equal(genType const& x, genType const& y, genType 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 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, vec<L, T, Q> const& epsilon); |
||||
|
||||
/// Returns the component-wise comparison of |x - y| >= epsilon.
|
||||
/// True if this expression is not satisfied.
|
||||
///
|
||||
/// @tparam genType Floating-point or integer scalar types
|
||||
///
|
||||
/// @see ext_vector_relational
|
||||
template<typename genType> |
||||
GLM_FUNC_DECL bool notEqual(genType const& x, genType const& y, genType const& epsilon); |
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
#include "vector_relational.inl" |
@ -0,0 +1,46 @@ |
||||
/// @ref ext_vector_relational |
||||
/// @file glm/ext/vector_relational.inl |
||||
|
||||
// Dependency: |
||||
#include "../vector_relational.hpp" |
||||
#include "../common.hpp" |
||||
#include "../detail/type_vec.hpp" |
||||
|
||||
namespace glm |
||||
{ |
||||
template<typename genType> |
||||
GLM_FUNC_QUALIFIER bool equal(genType const& x, genType const& y, genType const& epsilon) |
||||
{ |
||||
return abs(x - y) < epsilon; |
||||
} |
||||
|
||||
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) |
||||
{ |
||||
return lessThan(abs(x - y), vec<L, T, Q>(epsilon)); |
||||
} |
||||
|
||||
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, vec<L, T, Q> const& epsilon) |
||||
{ |
||||
return lessThan(abs(x - y), epsilon); |
||||
} |
||||
|
||||
template<typename genType> |
||||
GLM_FUNC_QUALIFIER bool notEqual(genType const& x, genType const& y, genType const& epsilon) |
||||
{ |
||||
return abs(x - y) >= epsilon; |
||||
} |
||||
|
||||
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) |
||||
{ |
||||
return greaterThanEqual(abs(x - y), vec<L, T, Q>(epsilon)); |
||||
} |
||||
|
||||
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, vec<L, T, Q> const& epsilon) |
||||
{ |
||||
return greaterThanEqual(abs(x - y), epsilon); |
||||
} |
||||
}//namespace glm |
@ -1 +1,2 @@ |
||||
glmCreateTestGTC(ext_vec1) |
||||
glmCreateTestGTC(ext_vector_relational) |
||||
|
@ -0,0 +1,42 @@ |
||||
#include <glm/ext/vector_relational.hpp> |
||||
#include <glm/vec2.hpp> |
||||
|
||||
int test_equal() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
Error += glm::equal(1.01f, 1.02f, 0.1f) ? 0 : 1; |
||||
Error += glm::all(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), 0.1f)) ? 0 : 1; |
||||
Error += glm::all(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.1f))) ? 0 : 1; |
||||
|
||||
Error += !glm::equal(1.01f, 1.02f, 0.001f) ? 0 : 1; |
||||
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; |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int test_notEqual() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
Error += glm::notEqual(1.01f, 1.02f, 0.001f) ? 0 : 1; |
||||
Error += glm::all(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), 0.001f)) ? 0 : 1; |
||||
Error += glm::all(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.001f))) ? 0 : 1; |
||||
|
||||
Error += !glm::notEqual(1.01f, 1.02f, 0.1f) ? 0 : 1; |
||||
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; |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int main() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
Error += test_equal(); |
||||
Error += test_notEqual(); |
||||
|
||||
return Error; |
||||
} |
Loading…
Reference in New Issue