From 3f9caa86f8e9a1dd0b4690f60c3f2ec1162ae589 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Tue, 22 Mar 2016 10:25:41 +0100
Subject: [PATCH] BasicVector3D::unit() now throws exception when called for
 unit vector

---
 Core/Geometry/BasicVector3D.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/Core/Geometry/BasicVector3D.h b/Core/Geometry/BasicVector3D.h
index ce42af55e53..af4933f7ffe 100644
--- a/Core/Geometry/BasicVector3D.h
+++ b/Core/Geometry/BasicVector3D.h
@@ -22,6 +22,7 @@
 
 static const double PI2 = 6.28318530717958647692528676655900577;
 #include "WinDllMacros.h"
+#include "Exceptions.h"
 #include <complex>
 
 namespace Geometry {
@@ -127,12 +128,12 @@ public:
     //! Returns squared sine of polar angle.
     double sin2Theta() const;
 
-    //! Returns unit vector in direction of this (or null vector).
+    //! Returns unit vector in direction of this. Throws for null vector.
     inline BasicVector3D<T> unit() const {
         double len = mag();
-        return (len > 0.0) ?
-            BasicVector3D<T>(x()/len, y()/len, z()/len) :
-            BasicVector3D<T>();
+        if ( len==0.0 )
+            throw Exceptions::DivisionByZeroException("Cannot normalize zero vector");
+        return BasicVector3D<T>(x()/len, y()/len, z()/len);
     }
 
     //! Returns this, trivially converted to complex type.
-- 
GitLab