From 5888392d99fd178664cf3f7a11d70874f4440318 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Tue, 10 Sep 2024 15:52:38 +0200 Subject: [PATCH] Fix vec2_norm --- sources/iron_vec2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sources/iron_vec2.c b/sources/iron_vec2.c index 625c6682..3d0c5a2d 100644 --- a/sources/iron_vec2.c +++ b/sources/iron_vec2.c @@ -52,9 +52,12 @@ float vec2_cross(vec2_t a, vec2_t b) { } vec2_t vec2_norm(vec2_t v) { - float length = vec2_len(v); - v.x /= length; - v.y /= length; + float n = vec2_len(v); + if (n > 0.0) { + float inv_n = 1.0f / n; + v.x *= inv_n; + v.y *= inv_n; + } return v; }