Handle 0 vectors in vector.normalize()
authorShadowNinja <noreply@gmail.com>
Sun, 7 Jul 2013 06:02:45 +0000 (02:02 -0400)
committerkwolekr <kwolekr@minetest.net>
Sun, 7 Jul 2013 06:29:09 +0000 (02:29 -0400)
builtin/vector.lua

index f534471c2c12f4bbdec28bf34e6125953aaebe52..839f139ca25a018314b0ca0224150974b9369b0e 100644 (file)
@@ -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)