diff --git a/glm/CMakeLists.txt b/glm/CMakeLists.txt index d60a8877..df9c9ee5 100644 --- a/glm/CMakeLists.txt +++ b/glm/CMakeLists.txt @@ -9,6 +9,10 @@ file(GLOB_RECURSE CORE_SOURCE ./detail/*.cpp) file(GLOB_RECURSE CORE_INLINE ./detail/*.inl) file(GLOB_RECURSE CORE_HEADER ./detail/*.hpp) +file(GLOB_RECURSE EXT_SOURCE ./ext/*.cpp) +file(GLOB_RECURSE EXT_INLINE ./ext/*.inl) +file(GLOB_RECURSE EXT_HEADER ./ext/*.hpp) + file(GLOB_RECURSE GTC_SOURCE ./gtc/*.cpp) file(GLOB_RECURSE GTC_INLINE ./gtc/*.inl) file(GLOB_RECURSE GTC_HEADER ./gtc/*.hpp) @@ -25,6 +29,9 @@ source_group("Text Files" FILES ${ROOT_TEXT} ${ROOT_MD}) source_group("Core Files" FILES ${CORE_SOURCE}) source_group("Core Files" FILES ${CORE_INLINE}) source_group("Core Files" FILES ${CORE_HEADER}) +source_group("EXT Files" FILES ${EXT_SOURCE}) +source_group("EXT Files" FILES ${EXT_INLINE}) +source_group("EXT Files" FILES ${EXT_HEADER}) source_group("GTC Files" FILES ${GTC_SOURCE}) source_group("GTC Files" FILES ${GTC_INLINE}) source_group("GTC Files" FILES ${GTC_HEADER}) @@ -42,6 +49,7 @@ if(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE) add_library(glm_static STATIC ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT} ${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER} ${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER} + ${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER} ${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER} ${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} ${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}) @@ -51,6 +59,7 @@ if(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE) add_library(glm_shared SHARED ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT} ${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER} ${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER} + ${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER} ${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER} ${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} ${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}) @@ -60,6 +69,7 @@ else(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE) add_executable(glm_dummy ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT} ${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER} ${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER} + ${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER} ${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER} ${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} ${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}) diff --git a/glm/ext.hpp b/glm/ext.hpp index 88073b3d..d085bfd5 100644 --- a/glm/ext.hpp +++ b/glm/ext.hpp @@ -13,6 +13,8 @@ # pragma message("GLM: All extensions included (not recommanded)") #endif//GLM_MESSAGES +#include "./ext/vector_relational.hpp" + #include "./gtc/bitfield.hpp" #include "./gtc/color_space.hpp" #include "./gtc/constants.hpp" diff --git a/glm/ext/vec1.hpp b/glm/ext/vec1.hpp new file mode 100644 index 00000000..e69de29b diff --git a/glm/ext/vec1.inl b/glm/ext/vec1.inl new file mode 100644 index 00000000..e69de29b diff --git a/glm/ext/vector_relational.hpp b/glm/ext/vector_relational.hpp new file mode 100644 index 00000000..a6920eaf --- /dev/null +++ b/glm/ext/vector_relational.hpp @@ -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 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 + GLM_FUNC_DECL vec equal(vec const& x, vec 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 + GLM_FUNC_DECL vec equal(vec const& x, vec const& y, vec 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 + 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 + GLM_FUNC_DECL vec notEqual(vec const& x, vec 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 + GLM_FUNC_DECL vec notEqual(vec const& x, vec const& y, vec 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 + GLM_FUNC_DECL bool notEqual(genType const& x, genType const& y, genType const& epsilon); + + /// @} +}//namespace glm + +#include "vector_relational.inl" diff --git a/glm/ext/vector_relational.inl b/glm/ext/vector_relational.inl new file mode 100644 index 00000000..8532a022 --- /dev/null +++ b/glm/ext/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 + GLM_FUNC_QUALIFIER bool equal(genType const& x, genType const& y, genType const& epsilon) + { + return abs(x - y) < epsilon; + } + + template + GLM_FUNC_QUALIFIER vec equal(vec const& x, vec const& y, T const& epsilon) + { + return lessThan(abs(x - y), vec(epsilon)); + } + + template + GLM_FUNC_QUALIFIER vec equal(vec const& x, vec const& y, vec const& epsilon) + { + return lessThan(abs(x - y), epsilon); + } + + template + GLM_FUNC_QUALIFIER bool notEqual(genType const& x, genType const& y, genType const& epsilon) + { + return abs(x - y) >= epsilon; + } + + template + GLM_FUNC_QUALIFIER vec notEqual(vec const& x, vec const& y, T const& epsilon) + { + return greaterThanEqual(abs(x - y), vec(epsilon)); + } + + template + GLM_FUNC_QUALIFIER vec notEqual(vec const& x, vec const& y, vec const& epsilon) + { + return greaterThanEqual(abs(x - y), epsilon); + } +}//namespace glm diff --git a/glm/gtc/epsilon.inl b/glm/gtc/epsilon.inl index 796e8118..2478cabd 100644 --- a/glm/gtc/epsilon.inl +++ b/glm/gtc/epsilon.inl @@ -5,9 +5,7 @@ #include "quaternion.hpp" #include "../vector_relational.hpp" #include "../common.hpp" -#include "../vec2.hpp" -#include "../vec3.hpp" -#include "../vec4.hpp" +#include "../detail/type_vec.hpp" namespace glm { diff --git a/readme.md b/readme.md index 007851b8..36cf440e 100644 --- a/readme.md +++ b/readme.md @@ -63,6 +63,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) - Added conan packaging configuration #643 #641 - Added quatLookAt to GTX_quaternion #659 - Added fmin, fmax and fclamp to GTX_extended_min_max #372 +- Added EXT_vector_relational: extend equal and notEqual to take an epsilon argument #### Improvements: - No more default initialization of vector, matrix and quaternion types diff --git a/test/ext/CMakeLists.txt b/test/ext/CMakeLists.txt index 9e40b509..0aafbae8 100644 --- a/test/ext/CMakeLists.txt +++ b/test/ext/CMakeLists.txt @@ -1 +1,2 @@ glmCreateTestGTC(ext_vec1) +glmCreateTestGTC(ext_vector_relational) diff --git a/test/ext/ext_vec1.cpp b/test/ext/ext_vec1.cpp index 268d95e6..04ca86ce 100644 --- a/test/ext/ext_vec1.cpp +++ b/test/ext/ext_vec1.cpp @@ -1,4 +1,4 @@ -#include +#include int main() { diff --git a/test/ext/ext_vector_relational.cpp b/test/ext/ext_vector_relational.cpp new file mode 100644 index 00000000..d8b19ba6 --- /dev/null +++ b/test/ext/ext_vector_relational.cpp @@ -0,0 +1,42 @@ +#include +#include + +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; +}