From 6f1278767ffb00507db4cc7d327aa650ab2b4361 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 15 Apr 2015 13:48:51 +1000 Subject: [PATCH] vector: add is_normalised --- test/vector.cpp | 9 +++++++-- vector.cpp | 10 ++++++++++ vector.hpp | 5 ++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test/vector.cpp b/test/vector.cpp index 6e111eea..ad160bf5 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -64,8 +64,13 @@ test_polar (void) int main () { + util::TAP::logger test; + + test.skip ("convert to TAP"); test_polar (); - util::TAP::logger test; - test.skip ("convert to TAP"); + test.expect (!util::vector3f::ZERO.is_normalised (), "zero isn't normalised"); + test.expect (!util::vector3f::UNIT.is_normalised (), "unit is normalised"); + + return test.status (); } diff --git a/vector.cpp b/vector.cpp index 57a82877..ef235f00 100644 --- a/vector.cpp +++ b/vector.cpp @@ -71,6 +71,16 @@ util::vector::difference2 (const util::vector &rhs) const return sum; } + +/////////////////////////////////////////////////////////////////////////////// +template +bool +vector::is_normalised (void) const +{ + return almost_equal (magnitude (), 1.f); +} + + //----------------------------------------------------------------------------- template util::vector& diff --git a/vector.hpp b/vector.hpp index 20c405a3..4b5c96d3 100644 --- a/vector.hpp +++ b/vector.hpp @@ -30,15 +30,18 @@ namespace util { { using coord::base::base; + // vector size bool is_zero (void) const; - // vector operators T magnitude (void) const; T magnitude2 (void) const; T difference (const vector&) const; T difference2 (const vector&) const; + // normalisation + bool is_normalised (void) const; + vector& normalise (void); vector normalised [[gnu::warn_unused_result]] (void) const;