From c8afa3f6991a57bb17e89e317b2eec320350148c Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sun, 9 Jan 2022 14:32:50 -0800 Subject: [PATCH] Vec2::normal accounts for zero-length --- include/blah/numerics/spatial.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/blah/numerics/spatial.h b/include/blah/numerics/spatial.h index a5bfd8b..c62073b 100644 --- a/include/blah/numerics/spatial.h +++ b/include/blah/numerics/spatial.h @@ -456,6 +456,8 @@ namespace Blah template Vec2 Vec2::normal() const { auto len = std::sqrt(x * x + y * y); + if (len <= 0) + return Vec2(0, 0); return Vec2(x / len, y / len); }