summaryrefslogtreecommitdiff
path: root/lib/vec2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vec2.c')
-rw-r--r--lib/vec2.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/vec2.c b/lib/vec2.c
index d795d50..55f5078 100644
--- a/lib/vec2.c
+++ b/lib/vec2.c
@@ -61,7 +61,8 @@ dp_vec2_length(vec2 v)
vec2
dp_vec2_normal(vec2 v)
{
- float a;
- a = 1.f / dp_vec2_length(v);
- return dp_vec2_mul(v, a);
+ float len = dp_vec2_length(v);
+ if (len == 0.0f)
+ return dp_vec2_new(0.0f, 0.0f);
+ return dp_vec2_mul(v, 1.0f / len);
}