vector: add is_normalised
This commit is contained in:
parent
f87481c5e0
commit
6f1278767f
@ -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 ();
|
||||
}
|
||||
|
10
vector.cpp
10
vector.cpp
@ -71,6 +71,16 @@ util::vector<S,T>::difference2 (const util::vector<S,T> &rhs) const
|
||||
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>
|
||||
util::vector<S,T>&
|
||||
|
@ -30,15 +30,18 @@ namespace util {
|
||||
{
|
||||
using coord::base<S,T,util::vector,coord::xyzw,coord::stpq>::base;
|
||||
|
||||
// vector size
|
||||
bool is_zero (void) const;
|
||||
|
||||
// vector operators
|
||||
T magnitude (void) const;
|
||||
T magnitude2 (void) const;
|
||||
|
||||
T difference (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> normalised [[gnu::warn_unused_result]] (void) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user