From 8f0b7c13732b018339697d182ea3a9f437ccaa71 Mon Sep 17 00:00:00 2001 From: Groove Date: Wed, 25 Jul 2018 22:16:16 +0200 Subject: [PATCH] Added missing equal and notEqual with epsilon for quaternion types --- glm/gtc/quaternion.hpp | 17 +++++++++++++ glm/gtc/quaternion.inl | 14 +++++++++++ readme.md | 1 + test/gtc/gtc_quaternion.cpp | 50 +++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 7d74717f..83158a5d 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -379,6 +379,14 @@ namespace glm template GLM_FUNC_DECL vec<4, bool, Q> equal(tquat const& x, tquat const& y); + /// Returns the component-wise comparison of |x - y| < epsilon. + /// + /// @tparam T Floating-point scalar types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL vec<4, bool, Q> equal(tquat const& x, tquat const& y, T epsilon); + /// Returns the component-wise comparison of result x != y. /// /// @tparam T Floating-point scalar types. @@ -387,6 +395,15 @@ namespace glm template GLM_FUNC_DECL vec<4, bool, Q> notEqual(tquat const& x, tquat const& y); + /// Returns the component-wise comparison of |x - y| >= epsilon. + /// + /// @tparam T Floating-point scalar types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL vec<4, bool, Q> notEqual(tquat const& x, tquat const& y, T epsilon); + + /// Returns true if x holds a NaN (not a number) /// representation in the underlying implementation's set of /// floating point representations. Returns false otherwise, diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 0ea87f09..36cf5b8f 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -773,6 +773,13 @@ namespace detail return Result; } + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> equal(tquat const& x, tquat const& y, T epsilon) + { + vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); + return lessThan(abs(v), vec<4, T, Q>(epsilon)); + } + template GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(tquat const& x, tquat const& y) { @@ -782,6 +789,13 @@ namespace detail return Result; } + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(tquat const& x, tquat const& y, T epsilon) + { + vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); + return greaterThanEqual(abs(v), vec<4, T, Q>(epsilon)); + } + template GLM_FUNC_QUALIFIER vec<4, bool, Q> isnan(tquat const& q) { diff --git a/readme.md b/readme.md index c338aa56..94e8ff3b 100644 --- a/readme.md +++ b/readme.md @@ -61,6 +61,7 @@ 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 #### Fixes: - Fixed build problems due to printf and std::clock_t #778 diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 0c16ca2e..be78f198 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -317,6 +317,55 @@ static int test_constexpr() return 0; } +using namespace glm; + +/* +template class matType> +struct init_mat +{ + static matType identity() + { + return matType(1, 0, 0, 0); + } +}; +*/ + +template +struct init_quat +{ + static tquat identity() + { + return tquat(1, 0, 0, 0); + } +}; + +template +struct init +{ + static genType identity() + { + return init_quat::identity(); + } +}; + +template +inline genType identity() +{ + return init::identity(); +} + +int test_identity() +{ + int Error = 0; + + glm::quat const Q = identity(); + + Error += glm::all(glm::equal(Q, glm::quat(1, 0, 0, 0), 0.0001f)) ? 0 : 1; + Error += glm::any(glm::notEqual(Q, glm::quat(1, 0, 0, 0), 0.0001f)) ? 1 : 0; + + return Error; +} + int main() { int Error = 0; @@ -334,6 +383,7 @@ int main() Error += test_quat_slerp(); Error += test_size(); Error += test_constexpr(); + Error += test_identity(); return Error; }