From 81d11949122c63feb14e6595fc59e49cd264c89e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 1 May 2017 09:38:42 +0200 Subject: simple-mat: return 0 norm if below epsilon --- compat/simple-mat.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp index 9490473a..a909e40b 100644 --- a/compat/simple-mat.hpp +++ b/compat/simple-mat.hpp @@ -107,6 +107,7 @@ public: template typename std::enable_if::value, num&>::type w() { OPENTRACK_ASSERT_SWIZZLE; return operator()(3); } + // parameters w_ and h_ are rebound so that SFINAE occurs // removing them causes a compile-time error -sh 20150811 @@ -116,7 +117,12 @@ public: { static_assert(P == h_ && Q == w_, ""); - return std::sqrt(dot(*this)); + const num val = dot(*this); + + if (std::fabs(val) < 1e-4) + return num(0); + else + return std::sqrt(val); } template -- cgit v1.2.3