From 32e0aaeaa65976e5483d594fe290712831b13cab Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Mon, 4 Nov 2013 22:04:16 +0100 Subject: [PATCH] Fix #25: vector:angleTo() returns wrong angle. --- vector-light.lua | 5 ++++- vector.lua | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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)