aboutsummaryrefslogtreecommitdiff
path: root/builtin/vector.lua
diff options
context:
space:
mode:
authorShadowNinja <noreply@gmail.com>2013-07-07 02:02:45 -0400
committerkwolekr <kwolekr@minetest.net>2013-07-07 02:29:09 -0400
commit07715b1b6adbdaeaa3f72591297ad59b443a0d9c (patch)
tree245661e2869b4a3d90abdca89aca0d5a57b98e49 /builtin/vector.lua
parent39ab22070e912b328b021731be8e1d983a2124ff (diff)
downloadminetest-07715b1b6adbdaeaa3f72591297ad59b443a0d9c.tar.gz
minetest-07715b1b6adbdaeaa3f72591297ad59b443a0d9c.tar.bz2
minetest-07715b1b6adbdaeaa3f72591297ad59b443a0d9c.zip
Handle 0 vectors in vector.normalize()
Diffstat (limited to 'builtin/vector.lua')
-rw-r--r--builtin/vector.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/builtin/vector.lua b/builtin/vector.lua
index f534471c2..839f139ca 100644
--- a/builtin/vector.lua
+++ b/builtin/vector.lua
@@ -31,7 +31,12 @@ function vector.length(v)
end
function vector.normalize(v)
- return vector.divide(v, vector.length(v))
+ local len = vector.length(v)
+ if len == 0 then
+ return vector.new()
+ else
+ return vector.divide(v, len)
+ end
end
function vector.round(v)