Skip to content
Snippets Groups Projects
Commit e65d2803 authored by Tom Fischer's avatar Tom Fischer
Browse files

[MathLib] Vector3: Impl. and test for normalization.

parent 6bbd0432
No related branches found
No related tags found
No related merge requests found
...@@ -127,6 +127,16 @@ public: ...@@ -127,6 +127,16 @@ public:
return *this; return *this;
} }
/**
* After applying the normalize operator to the vector its length is 1.0.
*/
void normalize()
{
const double s(1/length());
for (std::size_t i(0); i < 3; i++)
this->_x[i] *= s;
}
/// Returns the length /// Returns the length
double length(void) const double length(void) const
{ {
......
...@@ -155,5 +155,10 @@ TEST(MathLib, TestVector3Multiplications) ...@@ -155,5 +155,10 @@ TEST(MathLib, TestVector3Multiplications)
ASSERT_NEAR(1.0, v[0], std::numeric_limits<double>::epsilon()); ASSERT_NEAR(1.0, v[0], std::numeric_limits<double>::epsilon());
ASSERT_NEAR(3.0, v[1], std::numeric_limits<double>::epsilon()); ASSERT_NEAR(3.0, v[1], std::numeric_limits<double>::epsilon());
ASSERT_NEAR(5.0, v[2], std::numeric_limits<double>::epsilon()); ASSERT_NEAR(5.0, v[2], std::numeric_limits<double>::epsilon());
// test normalisation
v.normalize();
ASSERT_NEAR(1.0, v.length(), std::numeric_limits<double>::epsilon());
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment