From 68adb324726d8b7c6c3304a7949aa06dfd995491 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 3 May 2012 15:56:56 +1000 Subject: [PATCH] Add is_zero for vector magnitude --- vector.cpp | 8 ++++++++ vector.hpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/vector.cpp b/vector.cpp index db391c0c..d79e273c 100644 --- a/vector.cpp +++ b/vector.cpp @@ -184,6 +184,14 @@ vector::cartesian_to_spherical (const vector &c) { } +bool +vector::is_zero (void) const { + return almost_equal (x, 0.0) && + almost_equal (y, 0.0) && + almost_equal (z, 0.0); +} + + void vector::sanity (void) const { check_soft (!std::isnan (x)); diff --git a/vector.hpp b/vector.hpp index 26cbdd69..7e53550b 100644 --- a/vector.hpp +++ b/vector.hpp @@ -56,6 +56,8 @@ namespace util { static vector spherical_to_cartesian (const vector &); static vector cartesian_to_spherical (const vector &); + bool is_zero (void) const; + void sanity (void) const; };