diff --git a/vector-light.lua b/vector-light.lua index 40160f5..c352ebc 100644 --- a/vector-light.lua +++ b/vector-light.lua @@ -121,7 +121,10 @@ local function trim(maxLen, x, y) end local function angleTo(x,y, u,v) - return atan2(y - (v or 0), x - (u or 0)) + if u and v then + return atan2(y, x) - atan2(v, u) + end + return atan2(y, x) end -- the module diff --git a/vector.lua b/vector.lua index 89de628..0762ce5 100644 --- a/vector.lua +++ b/vector.lua @@ -175,8 +175,10 @@ function vector:trim_inplace(maxLen) end function vector:angleTo(other) - other = other or zero - return atan2(self.y - other.y, self.x - other.x) + if other then + return atan2(self.y, self.y) - atan2(other.y, other.x) + end + return atan2(self.y, self.y) end function vector:trimmed(maxLen)