vector: add is_normalised

This commit is contained in:
Danny Robson 2015-04-15 13:48:51 +10:00
parent f87481c5e0
commit 6f1278767f
3 changed files with 21 additions and 3 deletions

View File

@ -64,8 +64,13 @@ test_polar (void)
int int
main () main ()
{ {
util::TAP::logger test;
test.skip ("convert to TAP");
test_polar (); test_polar ();
util::TAP::logger test; test.expect (!util::vector3f::ZERO.is_normalised (), "zero isn't normalised");
test.skip ("convert to TAP"); test.expect (!util::vector3f::UNIT.is_normalised (), "unit is normalised");
return test.status ();
} }

View File

@ -71,6 +71,16 @@ util::vector<S,T>::difference2 (const util::vector<S,T> &rhs) const
return sum; return sum;
} }
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
bool
vector<S,T>::is_normalised (void) const
{
return almost_equal (magnitude (), 1.f);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
util::vector<S,T>& util::vector<S,T>&

View File

@ -30,15 +30,18 @@ namespace util {
{ {
using coord::base<S,T,util::vector,coord::xyzw,coord::stpq>::base; using coord::base<S,T,util::vector,coord::xyzw,coord::stpq>::base;
// vector size
bool is_zero (void) const; bool is_zero (void) const;
// vector operators
T magnitude (void) const; T magnitude (void) const;
T magnitude2 (void) const; T magnitude2 (void) const;
T difference (const vector<S,T>&) const; T difference (const vector<S,T>&) const;
T difference2 (const vector<S,T>&) const; T difference2 (const vector<S,T>&) const;
// normalisation
bool is_normalised (void) const;
vector<S,T>& normalise (void); vector<S,T>& normalise (void);
vector<S,T> normalised [[gnu::warn_unused_result]] (void) const; vector<S,T> normalised [[gnu::warn_unused_result]] (void) const;