diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-01 09:38:42 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-02 23:19:38 +0200 |
commit | 81d11949122c63feb14e6595fc59e49cd264c89e (patch) | |
tree | db1e06a57338d4af4361be6c2cdc111792cb2f98 /compat | |
parent | ff3f20bf50ccae00937732673bbb12f1b6be7afe (diff) |
simple-mat: return 0 norm if below epsilon
Diffstat (limited to 'compat')
-rw-r--r-- | compat/simple-mat.hpp | 8 |
1 files changed, 7 insertions, 1 deletions
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<int P = h_, int Q = w_> typename std::enable_if<maybe_add_swizzle<P, Q, 4>::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<int R, int S, int P = h_, int Q = w_> |