diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-01 00:59:21 +0200 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-01 01:01:08 +0200 | 
| commit | 8aa78cf708d646a05090223b55294f3390cb8e29 (patch) | |
| tree | 43a8fec0b9b6ed51c46aea380be99ca588417d9a | |
| parent | 2ed30847cfae5e32b43d8671cc02b6a10e9b66d5 (diff) | |
simple-mat: add vector norm
| -rw-r--r-- | compat/simple-mat.hpp | 15 | 
1 files changed, 12 insertions, 3 deletions
| diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp index a119044c..46d9e382 100644 --- a/compat/simple-mat.hpp +++ b/compat/simple-mat.hpp @@ -10,9 +10,9 @@  #include "export.hpp" -#include <initializer_list>  #include <type_traits>  #include <utility> +#include <cmath>  namespace {      // last param to fool SFINAE into overloading @@ -112,6 +112,15 @@ public:      template<int R, int S, int P = h_, int Q = w_>      typename std::enable_if<is_vector_pair<R, S, P, Q>::value, num>::type +    norm() const +    { +        static_assert(P == h_ && Q == w_, ""); + +        return std::sqrt(dot(*this)); +    } + +    template<int R, int S, int P = h_, int Q = w_> +    typename std::enable_if<is_vector_pair<R, S, P, Q>::value, num>::type      dot(const Mat<num, R, S>& p2) const      {          static_assert(P == h_ && Q == w_, ""); @@ -130,8 +139,8 @@ public:          static_assert(P == h_ && Q == w_, "");          decltype(*this)& p1 = *this; -        return Mat<num, R, S>(p1.y() * p2.z() - p2.y() * p1.z(), -                              p2.x() * p1.z() - p1.x() * p2.z(), +        return Mat<num, R, S>(p1.y() * p2.z() - p1.y() * p2.z(), +                              p1.x() * p2.z() - p1.x() * p2.z(),                                p1.x() * p2.y() - p1.y() * p2.x());      } | 
