• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Jass rects area

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

I'm doing some calculations with rects, but I have no idea how their representation works.

In the WE GUI, you can make a rect by specifying four values: left, right, bottom, top.

But when you make a rect in JASS, you do it like this:

Rect(left, bottom, right, top).

I am guessing rects are really just wrappers around 2 locations/points:

Point 1: (left, bottom)

Point 2: (right, top)

Now these coordinates are sometimes (for me) obscenely high values or negative (but I guess the cartesian map is quite big).

It looks like given these two points, you just draw a straight line horizontally and vertically from each one until they meet/make a vertex, at which point you have some kind of square or rectangle.

But how does one:

1) Calculate the area of a given rect (given its coordinates?)
2) calculate the length of each side of a given rect
3) tell whether a point is inside a rect
4) tell whether a point lies exactly on the edge/border of the rect
5) highlight the exterior/border of a rect in a game (imagine seeing the square/rectangle outlined by footman or something).
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
minX (left border), minY (bottom border), maxX (right border), maxY (top border)

1) (maxX-minX)*(maxY-minY)

2) (maxX-minX) for bottom/top border respectively (maxY-minY) for left/right border

3) ((x>=minX) and (x<=maxX) and (y>=minY) and (y<=maxY))

4) (((x==minX) or (x==maxX)) and (y>=minY) and (y<=maxY))) or (((y==minY) or (y==maxY)) and (x>=minX) and (x<=maxX)))

5)

x=minX
for y=minY to maxY

x=maxX
for y=minY to maxY

y=minY
for x=minX to maxX

y=maxY
for x=minX to maxX


better yet, instead of spamming units along the border, take lightnings that take a source and a target point.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
How would you determine if a point is tangent to the edge of the rect (it could be inside the rect or outside of it)?

Also are you sure that's how you get a rect's area? Because I got like an eight digit number for a rect that takes up about 1/40th of the map space:

4565684 (in what units?)

I implemented your answers like so:

JASS:
function rectLength takes rect r returns integer
    return R2I((GetRectMaxX(r) - GetRectMinX(r)))
endfunction

function rectHeight takes rect r returns integer
    return R2I(GetRectMaxY(r) - GetRectMinY(r))
endfunction

function rectArea takes rect r returns integer
    return R2I(rectLength(r) * rectHeight(r))
endfunction

For doing the highlight trick, what do I do since each coordinate is a real number? Do I just add +1 for each loop? Perhaps you could show me the JASS for doing the first loop for x=minX
 
it returns the area calculated based on the coordinates system of wc3...

if you wanna make sure, you can always check the X and Y values it uses via debug messages

JASS:
function border takes rect r returns nothing
    local real maxx = GetRectMaxX(r)
    local real maxy = GetRectMaxY(r)
    local real minx = GetRectMinX(r)
    local real miny = GetRectMinY(r)
    local real i = 0.0
    local real unit_space = 32.0
    //Vertical borders on minx
    loop
        call CreateUnit('u000',Player(1),minx,miny + i)
        set i = i + unit_space
        exitwhen i + miny > maxy
    endloop
    set i = 0.0
   //Vertical borders on maxx
    loop
        call CreateUnit('u000',Player(1),maxx,miny + i)
        set i = i + unit_space
        exitwhen i + miny > maxy
    endloop
    set i = 0.0
    //Horizontal borders on miny
    loop
        call CreateUnit('u000',Player(1),minx+i,miny)
        set i = i + unit_space
        exitwhen i + minx > maxx
    endloop
    set i = 0.0
     //Horizontal borders on maxy
    loop
        call CreateUnit('u000',Player(1),minx+i,maxy)
        set i = i + unit_space
        exitwhen i + minx > maxx
    endloop
endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
How would you determine if a point is tangent to the edge of the rect (it could be inside the rect or outside of it)?

x == minX or x == maxY or y == minY or y == maxY

4565684 (in what units?)

WacraftDistanceUnit2

A map size 32x32 (tiny) has 32x32 = 1024 tiles. Each tile is 32 distance units x 32 distance units. So even a tiny map has an area of 1024x32x32 = 1048567 distanceUnits2. It really adds up quickly.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
x == minX or x == maxY or y == minY or y == maxY

The other coordinate needs to be restricted too. Else the point could be x-wise on minX but y-wise above maxY/below minY for example.

A map size 32x32 (tiny) has 32x32 = 1024 tiles. Each tile is 32 distance units x 32 distance units. So even a tiny map has an area of 1024x32x32 = 1048567 distanceUnits2. It really adds up quickly.

Each "tile" (the space between terrain nodes here) has an area of (4cells*32)², so it's (32*4*32)² = 16777216
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
The other coordinate needs to be restricted too. Else the point could be x-wise on minX but y-wise above maxY/below minY for example.

You're right.
(x == minX or x == maxX) and (y >= minY and y <= maxY) or (y == minY or y == maxY) and (x >= minX and x <= maxX)

Each "tile" (the space between terrain nodes here) has an area of (4cells*32)², so it's (32*4*32)² = 16777216

For some reason I used 32x32 (the value of the small "cell") when of course a tile is 128x128.
 
Status
Not open for further replies.
Top