I'm using this in some of my addons to find which side is closer.
I can easily be adapted for finding if top or bottom is closer.
Note that it tells you which side is closer without trying to qualify what is "close",
just that "my frame is positioned closer to left side of screen than to right side of screen"
Code:
local function findSide(frame)
local side = "left";
local rightDist = 0;
local leftPos = frame:GetLeft();
local rightPos = frame:GetRight();
if ( not rightPos ) then
rightPos = 0;
end
if ( not leftPos ) then
leftPos = 0;
end
rightDist = GetScreenWidth() - rightPos;
if (leftPos and (rightDist < leftPos)) then
side = "left";
else
side = "right";
end
return side
end
Also note that because I use it to decide an anchor point the returns might be a little confusing at first.
I.e if it finds that my frame is closer to the right side it returns "left" as in:
"we're closer to right = have more space on the left, anchor things there".