summaryrefslogtreecommitdiffhomepage
path: root/src/raymath.h
diff options
context:
space:
mode:
authorJeffery Myers <[email protected]>2021-07-27 23:59:39 -0700
committerGitHub <[email protected]>2021-07-28 08:59:39 +0200
commitc706b33b30438771bc09096357d6ad0ec9b52be2 (patch)
treedaeafbf4a59e6630e31f5b0cdb9bf9c29bb72277 /src/raymath.h
parente9c7ab925fe3fb8530389f0e554496bdf3fa6ce9 (diff)
downloadraylib-c706b33b30438771bc09096357d6ad0ec9b52be2.tar.gz
raylib-c706b33b30438771bc09096357d6ad0ec9b52be2.zip
Don't normalize zero length vectors. (#1896)
Diffstat (limited to 'src/raymath.h')
-rw-r--r--src/raymath.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/raymath.h b/src/raymath.h
index 13cb5e17..cc2cda82 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -282,7 +282,11 @@ RMDEF Vector2 Vector2Divide(Vector2 v1, Vector2 v2)
// Normalize provided vector
RMDEF Vector2 Vector2Normalize(Vector2 v)
{
- Vector2 result = Vector2Scale(v, 1/Vector2Length(v));
+ float length = Vector2Length(v);
+ if (length <= 0)
+ return v;
+
+ Vector2 result = Vector2Scale(v, 1/length);
return result;
}