Skip to content

Commit 07715b1

Browse files
ShadowNinjakwolekr
authored andcommittedJul 7, 2013
Handle 0 vectors in vector.normalize()
1 parent 39ab220 commit 07715b1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

Diff for: ‎builtin/vector.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ function vector.length(v)
3131
end
3232

3333
function vector.normalize(v)
34-
return vector.divide(v, vector.length(v))
34+
local len = vector.length(v)
35+
if len == 0 then
36+
return vector.new()
37+
else
38+
return vector.divide(v, len)
39+
end
3540
end
3641

3742
function vector.round(v)

0 commit comments

Comments
 (0)
Please sign in to comment.