From 9e59691e43583835062745e438695bc666b316aa Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Mon, 6 Nov 2017 10:45:27 +0100 Subject: [PATCH] Vector: Additional normalization with check for zero norm because it occurs so many times in applications --- matrix/Vector.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/matrix/Vector.hpp b/matrix/Vector.hpp index b0e01f5555..3d19e1dac0 100644 --- a/matrix/Vector.hpp +++ b/matrix/Vector.hpp @@ -83,6 +83,14 @@ public: return (*this) / norm(); } + Vector unit_or_zero(const Type eps = 1e-5f) { + const Type n = norm(); + if (n > eps) { + return (*this) / n; + } + return Vector(); + } + inline Vector normalized() const { return unit(); }