[DEV] add safeNormalize in vec2

This commit is contained in:
Edouard DUPIN 2014-10-22 08:13:12 +02:00
parent 63c9ff74c2
commit 45c4fbb98d

View File

@ -257,6 +257,17 @@ namespace etk {
*this /= length();
return *this;
}
/**
* @brief Normalize this vector
* x^2 + y^2 + z^2 = 1
*/
Vector2D<T>& safeNormalize() {
T tmp = length();
if (tmp != 0) {
*this /= length();
}
return *this;
}
/**
* @brief Return a normalized version of this vector
*/