Browse Source

Added EXT_vector_relational: extend equal and notEqual to take an epsilon argument

Christophe Riccio 8 years ago
parent
commit
de28722e36

+ 10 - 0
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})

+ 2 - 0
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"

+ 0 - 0
glm/ext/vec1.hpp


+ 0 - 0
glm/ext/vec1.inl


+ 93 - 0
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 <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"

+ 46 - 0
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<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 - 3
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
 {

+ 1 - 0
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

+ 1 - 0
test/ext/CMakeLists.txt

@@ -1 +1,2 @@
 glmCreateTestGTC(ext_vec1)
+glmCreateTestGTC(ext_vector_relational)

+ 1 - 1
test/ext/ext_vec1.cpp

@@ -1,4 +1,4 @@
-#include <glm/gtc/vec1.hpp>
+#include <glm/ext/vec1.hpp>
 
 int main()
 {

+ 42 - 0
test/ext/ext_vector_relational.cpp

@@ -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;
+}