Vec2::normal accounts for zero-length

This commit is contained in:
Noel Berry 2022-01-09 14:32:50 -08:00
parent 832c8f4283
commit c8afa3f699

View File

@ -456,6 +456,8 @@ namespace Blah
template<class T>
Vec2<T> Vec2<T>::normal() const {
auto len = std::sqrt(x * x + y * y);
if (len <= 0)
return Vec2<T>(0, 0);
return Vec2(x / len, y / len);
}