mirror of
https://github.com/NoelFB/blah.git
synced 2026-11-10 00:35:14 +08:00
Vec2::normal accounts for zero-length
This commit is contained in:
1 parent
832c8f4283
commit
c8afa3f699
1 file changed
+2
@@ -456,6 +456,8 @@ namespace Blah
|
|||||||
template<class T>
|
template<class T>
|
||||||
Vec2<T> Vec2<T>::normal() const {
|
Vec2<T> Vec2<T>::normal() const {
|
||||||
auto len = std::sqrt(x * x + y * y);
|
auto len = std::sqrt(x * x + y * y);
|
||||||
|
if (len <= 0)
|
||||||
|
return Vec2<T>(0, 0);
|
||||||
return Vec2(x / len, y / len);
|
return Vec2(x / len, y / len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user