From 2400954df2dd218b635d11c427a694d61f9b9544 Mon Sep 17 00:00:00 2001 From: Liam Adams Date: Fri, 19 Jul 2019 18:10:29 +0100 Subject: [PATCH 1/2] Add lMaxNorm for computing the max norm. --- glm/gtx/norm.hpp | 12 ++++++++++++ glm/gtx/norm.inl | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/glm/gtx/norm.hpp b/glm/gtx/norm.hpp index cdf60e05..dfaebb7a 100644 --- a/glm/gtx/norm.hpp +++ b/glm/gtx/norm.hpp @@ -3,6 +3,7 @@ /// /// @see core (dependence) /// @see gtx_quaternion (dependence) +/// @see gtx_component_wise (dependence) /// /// @defgroup gtx_norm GLM_GTX_norm /// @ingroup gtx @@ -16,6 +17,7 @@ // Dependency: #include "../geometric.hpp" #include "../gtx/quaternion.hpp" +#include "../gtx/component_wise.hpp" #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) # ifndef GLM_ENABLE_EXPERIMENTAL @@ -70,6 +72,16 @@ namespace glm template GLM_FUNC_DECL T lxNorm(vec<3, T, Q> const& x, unsigned int Depth); + //! Returns the LMax norm between x and y. + //! From GLM_GTX_norm extension. + template + GLM_FUNC_DECL T lMaxNorm(vec<3, T, Q> const& x, vec<3, T, Q> const& y); + + //! Returns the LMax norm of v. + //! From GLM_GTX_norm extension. + template + GLM_FUNC_DECL T lMaxNorm(vec<3, T, Q> const& x); + /// @} }//namespace glm diff --git a/glm/gtx/norm.inl b/glm/gtx/norm.inl index c3f468c3..59b79ac2 100644 --- a/glm/gtx/norm.inl +++ b/glm/gtx/norm.inl @@ -80,4 +80,16 @@ namespace detail return pow(pow(v.x, T(Depth)) + pow(v.y, T(Depth)) + pow(v.z, T(Depth)), T(1) / T(Depth)); } + template + GLM_FUNC_QUALIFIER T lMaxNorm(vec<3, T, Q> const& a, vec<3, T, Q> const& b) + { + return compMax(abs(b - a)); + } + + template + GLM_FUNC_QUALIFIER T lMaxNorm(vec<3, T, Q> const& v) + { + return compMax(abs(v)); + } + }//namespace glm From a78024d2bfcbf2f2b9e7969c4753ae180917f224 Mon Sep 17 00:00:00 2001 From: Liam Adams Date: Fri, 19 Jul 2019 18:11:07 +0100 Subject: [PATCH 2/2] Add testing of lMaxNorm. --- test/gtx/gtx_norm.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/gtx/gtx_norm.cpp b/test/gtx/gtx_norm.cpp index 38cef8c2..5d9e4f32 100644 --- a/test/gtx/gtx_norm.cpp +++ b/test/gtx/gtx_norm.cpp @@ -1,9 +1,28 @@ #define GLM_ENABLE_EXPERIMENTAL #include +int test_lMaxNorm() +{ + int Error(0); + + { + float norm = glm::lMaxNorm(glm::vec3(-1, -2, -3)); + Error += glm::epsilonEqual(norm, 3.f, 0.00001f) ? 0 : 1; + } + + { + float norm = glm::lMaxNorm(glm::vec3(2, 3, 1)); + Error += glm::epsilonEqual(norm, 3.f, 0.00001f) ? 0 : 1; + } + + return Error; +} + int main() { int Error(0); + Error += test_lMaxNorm(); + return Error; }