Snippet GetRectPos()

Sooda

Diversity enchants
Reaction score
318
Compares two rects and tells how they are positioned towards each other.
JASS:
function IsRectOnTop takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinX(whichRect) == GetRectMinX(comparedTo) and GetRectMaxX(whichRect) == GetRectMaxX(comparedTo) and GetRectMinY(whichRect) > GetRectMinY(comparedTo) and GetRectMaxY(whichRect) > GetRectMaxY(comparedTo)
endfunction

function IsRectOnBottom takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinX(whichRect) == GetRectMinX(comparedTo) and GetRectMaxX(whichRect) == GetRectMaxX(comparedTo) and GetRectMinY(whichRect) < GetRectMinY(comparedTo) and GetRectMaxY(whichRect) < GetRectMaxY(comparedTo)
endfunction

function IsRectOnRight takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinY(whichRect) == GetRectMinY(comparedTo) and GetRectMaxY(whichRect) == GetRectMaxY(comparedTo) and GetRectMinX(whichRect) > GetRectMinX(comparedTo) and GetRectMaxX(whichRect) > GetRectMaxX(comparedTo)
endfunction

function IsRectOnLeft takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinY(whichRect) == GetRectMinY(comparedTo) and GetRectMaxY(whichRect) == GetRectMaxY(comparedTo) and GetRectMinX(whichRect) < GetRectMinX(comparedTo) and GetRectMaxX(whichRect) < GetRectMaxX(comparedTo)
endfunction

function IsRectOnRightTop takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinX(whichRect) > GetRectMinX(comparedTo) and GetRectMaxX(whichRect) > GetRectMaxX(comparedTo) and GetRectMinY(whichRect) > GetRectMinY(comparedTo) and GetRectMaxY(whichRect) > GetRectMaxY(comparedTo)
endfunction

function IsRectOnRightBottom takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinX(whichRect) > GetRectMinX(comparedTo) and GetRectMaxX(whichRect) > GetRectMaxX(comparedTo) and GetRectMinY(whichRect) < GetRectMinY(comparedTo) and GetRectMaxY(whichRect) < GetRectMaxY(comparedTo)
endfunction

function IsRectOnLeftTop takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinX(whichRect) < GetRectMinX(comparedTo) and GetRectMaxX(whichRect) < GetRectMaxX(comparedTo) and GetRectMinY(whichRect) > GetRectMinY(comparedTo) and GetRectMaxY(whichRect) > GetRectMaxY(comparedTo)
endfunction

function IsRectOnLeftBottom takes rect whichRect, rect comparedTo returns boolean
    return GetRectMinX(whichRect) < GetRectMinX(comparedTo) and GetRectMaxX(whichRect) < GetRectMaxX(comparedTo) and GetRectMinY(whichRect) < GetRectMinY(comparedTo) and GetRectMaxY(whichRect) < GetRectMaxY(comparedTo)
endfunction

function GetRectPos takes rect whichRect, rect comparedTo returns nothing
    if IsRectOnTop(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on top!")
    elseif IsRectOnBottom(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on bottom!")
    elseif IsRectOnRight(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on right!")
    elseif IsRectOnLeft(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on left!")
    elseif IsRectOnRightTop(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on right top!")
    elseif IsRectOnRightBottom(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on right bottom!")
    elseif IsRectOnLeftTop(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on left top!")
    elseif IsRectOnLeftBottom(whichRect, comparedTo) then
        call BJDebugMsg("Rect is on left bottom!")
    else
        call BJDebugMsg("Unknown rect position!")
    endif
endfunction

Use it like that:
Code:
Test
    Events
        Player - Player 1 (Red) skips a cinematic sequence
    Conditions
    Actions
        Set tempRect1 = Region 001 <gen>
        Set tempRect2 = Region 000 <gen>
        Custom script:       call GetRectPos(udg_tempRect1, udg_tempRect2)
'tempRect1' and 'tempRect2' are region variables.
 

Romek

Super Moderator
Reaction score
964
OnTop and OnBottom should be renamed to "Above" and "Below".

Those names could be slightly misleading.

Also, maybe the function could return an integer. And you could make constants for it. For example:
RECT_ONTOP = 0 etc.
Then you'd return the integer, and it could be used in triggers with this system. Instead of just messages.
 

Flare

Stops copies me!
Reaction score
662
Nice idea (can't really think of an immediate use, but I'm sure someone will have use for it :p)

OnTop and OnBottom should be renamed to "Above" and "Below".
Would sound a bit weird when combined with Left/Right - and what's misleading about OnTop/Bottom? The only thing I can think of that would cause any misunderstanding (whether Z height is factored in, but that can't really be done properly) would have the very same issue with Above/Below

Also, maybe the function could return an integer.
Just use the specific functions instead of GetRectPos then? If you just use the individual functions, the boolean is much neater and simpler to understand (true/false vs 1 - 8, 2 options to remember is far easier than 8 :p)
 

Romek

Super Moderator
Reaction score
964
Nice idea (can't really think of an immediate use, but I'm sure someone will have use for it :p)


Would sound a bit weird when combined with Left/Right - and what's misleading about OnTop/Bottom? The only thing I can think of that would cause any misunderstanding (whether Z height is factored in, but that can't really be done properly) would have the very same issue with Above/Below

I actually thought it meant above/below with Z-Height :p


Just use the specific functions instead of GetRectPos then? If you just use the individual functions, the boolean is much neater and simpler to understand (true/false vs 1 - 8, 2 options to remember is far easier than 8 :p)
Calling 8 functions just to find out something simple... :eek:
Thats why I suggested the constants.

You could use RECT_BELOW instead of '5' for example.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Hm...

The first one for example, IsRectOnTop, tests for the top left corners to be identical(*), and the opposite inside.
How is that "on top"?


(*)
EDIT:
Actually, it's not even that...
What IS that thing testing?
 

Romek

Super Moderator
Reaction score
964
Hm...

The first one for example, IsRectOnTop, tests for the top left corners to be identical(*), and the opposite inside.
How is that "on top"?

No it doesn't o_O
(Unless I'm not seeing something...)

(*)
EDIT:
Actually, it's not even that...
What IS that thing testing?
The first one checks if Region A is above Region B.

They have to have identical x's though.

JASS:
return GetRectMinY(whichRect) &gt; GetRectMinY(comparedTo)

Should be enough for the first one.
Any X's. And no need for Max Y :p
 

Samael88

Evil always finds a way
Reaction score
181
This could be helpful if someone uses a system or something that moves rects and the person want to know where the rect is moved, I think it would be even better if you add an option for minimap ping aswell:) Then it would be really awesome.

Correct me if I'm wrong.
If region1 is in the middle of the map for example, you can check where the second one is by using this:) It will say if it is above the middle one or under from an air view:) Was I wrong?
 

Romek

Super Moderator
Reaction score
964
This could be helpful if someone uses a system or something that moves rects and the person want to know where the rect is moved, I think it would be even better if you add an option for minimap ping aswell:) Then it would be really awesome.

Correct me if I'm wrong.
If region1 is in the middle of the map for example, you can check where the second one is by using this:) It will say if it is above the middle one or under from an air view:) Was I wrong?
You could make your own triggers which make ping. Just use this snippet :p

There really isn't a need for things so specific xD

Well.. It's up to Sooda anyway :p
 

Samael88

Evil always finds a way
Reaction score
181
yeah, your right Romek. I figured that with the ping out myself:( But I was right on the rest, was I not?:)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top