You need to calculate the area of the intersection of rectangle3 with the other 2 and then test for the bigger one.
Here’s a sample implementation
[lua]
local function intersectRect( x, y, w, h, otherX, otherY, otherW, otherH )
if x < otherX then
w = w - (otherX - x)
x = otherX
end
if (x + w) > (otherX + otherW) then
w = (otherX + otherW) - x
end
if y < otherY then
h = h - (otherY - y)
y = otherY
end
if (y + h) > (otherY + otherH) then
h = (otherY + otherH) - y
end
return x, y, w, h
end
local function intersectArea( r1, r2 )
local bounds1 = r1.contentBounds
local bounds2 = r2.contentBounds
local x, y, w, h = intersectRect(
bounds1.xMin, bounds1.yMin, r1.contentWidth, r1.contentHeight,
bounds2.xMin, bounds2.yMin, r2.contentWidth, r2.contentHeight )
if w <= 0 or h <= 0 then
return 0
else
return w*h
end
end
local function biggerOverlap( r1, r2, r3 )
local area1 = intersectArea( r1, r3 )
local area2 = intersectArea( r2, r3 )
if area1 > area2 then
return “first”
elseif area2 > area1 then
return “second”
elseif area1 == 0 then
return “none”
else
return “same”
end
end
[/lua]