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GX52JLNHGUD7GV6YIVZ3ACOK5SFSQC
prepare_to_move = function()
for _,def in pairs(Definitions) do
assert(def.w)
assert(def.h)
if def.pos == nil then def.pos = {} end
if def.hs == nil then def.hs = {} end
def.hs.x = def.w/2 + 50
def.hs.y = def.h/2 + math.max(60, math.min(def.h/3, 200))
def.pos.x = def.x + def.hs.x
def.pos.y = def.y + def.hs.y
end
end
-- move any colliding Rects to make room for `a`
move_others = function(a, depth)
if depth == nil then depth = 0 end
if depth > 10 then return end
-- print('move others', a.key)
for _,d in pairs(Definitions) do
if d ~= a then
local msv = collide(a, d)
if msv then
move(d, msv)
A1(d.key)
move_others(d, depth+1)
end
end
end
end
-- returns the _minimum separation vector_ if there's a collision
-- requires a pos+halfsize representation for nodes
collide = function(a, b)
local delta = {x=a.pos.x-b.pos.x, y=a.pos.y-b.pos.y}
local abs_delta = {x=math.abs(a.pos.x-b.pos.x), y=math.abs(a.pos.y-b.pos.y)}
local size = {x=a.hs.x+b.hs.x, y=a.hs.y+b.hs.y}
local abs_amount = {x=size.x-abs_delta.x, y=size.y-abs_delta.y}
if abs_amount.x > 0 and abs_amount.y > 0 then
if abs_amount.x <= abs_amount.y then
return {x=abs_amount.x*sign(delta.x), y=0}
else
return {x=0, y=abs_amount.y*sign(delta.y)}
end
end
end
Move.node.pos.x = Move.node.x+Move.node.hs.x
Move.node.pos.y = Move.node.y+Move.node.hs.y
move_others(Move.node)