Fix calculation of distance between clients

This fixes move by direction

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Jo De Boeck 2013-01-25 11:47:11 +02:00 committed by Uli Schlachter
parent a484ef076d
commit e0a163cba0
1 changed files with 9 additions and 7 deletions

View File

@ -289,20 +289,22 @@ end
-- @param gB The second rectangle. -- @param gB The second rectangle.
-- @return The distance between the screens. -- @return The distance between the screens.
local function calculate_distance(dir, _gA, _gB) local function calculate_distance(dir, _gA, _gB)
local gA = _gA local gAx = _gA.x
local gB = _gB local gAy = _gA.y
local gBx = _gB.x
local gBy = _gB.y
if dir == "up" then if dir == "up" then
gB.y = gB.y + gB.height gBy = _gB.y + _gB.height
elseif dir == "down" then elseif dir == "down" then
gA.y = gA.y + gA.height gAy = _gA.y + _gA.height
elseif dir == "left" then elseif dir == "left" then
gB.x = gB.x + gB.width gBx = _gB.x + _gB.width
elseif dir == "right" then elseif dir == "right" then
gA.x = gA.x + gA.width gAx = _gA.x + _gA.width
end end
return math.sqrt(math.pow(gB.x - gA.x, 2) + math.pow(gB.y - gA.y, 2)) return math.sqrt(math.pow(gBx - gAx, 2) + math.pow(gBy - gAy, 2))
end end
-- Get the nearest rectangle in the given direction. Every rectangle is specified as a table -- Get the nearest rectangle in the given direction. Every rectangle is specified as a table