Skip to content

Commit

Permalink
Merge pull request vrld#5 from am0d/master
Browse files Browse the repository at this point in the history
Fixes divide-by-zero error in vector:normalize() and vector:normalize_inplace()
  • Loading branch information
vrld committed May 18, 2012
2 parents b12f02f + 1c683f5 commit b259e75
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions vector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ end

function vector:normalize_inplace()
local l = self:len()
self.x, self.y = self.x / l, self.y / l
if l > 0 then self.x, self.y = self.x / l, self.y / l end
return self
end

function vector:normalized()
return self / self:len()
local l = self:len()
if l == 0 then return self end
return self / l
end

function vector:rotate_inplace(phi)
Expand Down

0 comments on commit b259e75

Please sign in to comment.