Skip to content

Commit

Permalink
Handle 0 vectors in vector.normalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja authored and kwolekr committed Jul 7, 2013
1 parent 39ab220 commit 07715b1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion builtin/vector.lua
Expand Up @@ -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)
Expand Down

0 comments on commit 07715b1

Please sign in to comment.