From 8aa78cf708d646a05090223b55294f3390cb8e29 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 1 May 2017 00:59:21 +0200 Subject: simple-mat: add vector norm --- compat/simple-mat.hpp | 15 ++++++++++++--- 1 file 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 #include #include +#include namespace { // last param to fool SFINAE into overloading @@ -110,6 +110,15 @@ public: // parameters w_ and h_ are rebound so that SFINAE occurs // removing them causes a compile-time error -sh 20150811 + template + typename std::enable_if::value, num>::type + norm() const + { + static_assert(P == h_ && Q == w_, ""); + + return std::sqrt(dot(*this)); + } + template typename std::enable_if::value, num>::type dot(const Mat& p2) const @@ -130,8 +139,8 @@ public: static_assert(P == h_ && Q == w_, ""); decltype(*this)& p1 = *this; - return Mat(p1.y() * p2.z() - p2.y() * p1.z(), - p2.x() * p1.z() - p1.x() * p2.z(), + return Mat(p1.y() * p2.z() - p1.y() * p2.z(), + p1.x() * p2.z() - p1.x() * p2.z(), p1.x() * p2.y() - p1.y() * p2.x()); } -- cgit v1.2.3