| 04-12-2009, 03:43 PM | #1 |
JASS:library IsUnitOnRect //** //* IsUnitOnRect returns true if the unit's collision circle //* ------------ interesects with a rect. //* //* Useful for example, in a "enter rect" event //* it will return true, unlike blizz' RectContainsUnit //* //* probably slower than RectContainsUnit //* //******************************************************************* //================================================================= function IsUnitOnRect takes unit u, rect r returns boolean local real x =GetUnitX(u) local real y =GetUnitY(u) local real mx = GetRectMaxX(r) local real nx = GetRectMinX(r) local real my = GetRectMaxY(r) local real ny = GetRectMinY(r) if (nx <= x) and (x <= mx) and (ny <= y) and (y <= my) then return true endif if(x>mx) then set x=mx elseif(x<nx) then set x=nx endif if(y>my) then set y=my elseif(y<ny) then set y=ny endif return IsUnitInRangeXY(u,x,y,0.0) endfunction endlibrary |
| 04-12-2009, 03:51 PM | #2 |
Why four times : JASS:exitwhen ( IsUnitInRangeOfSegment(u, nx,ny, nx,my, 0) ) |
| 04-12-2009, 03:57 PM | #3 |
take a closer look. |
| 04-12-2009, 04:06 PM | #4 |
y not use 'if or or or or or' instead of loop. i think or evaluates each condition 1 by 1 and terminates evaluation upon finding a true condition; and it is more 'to the point' is it that u just wanted it the conditions to be enumerated more clearly? |
| 04-12-2009, 04:10 PM | #5 |
ok my bad, variables' name are nearly the same :p |
| 04-12-2009, 04:14 PM | #6 | |
Quote:
Edit: code got shorter. |
| 04-12-2009, 06:42 PM | #7 |
That's a clever way to mesh 4 checks together without a bunch of ugly if/thens. |
| 04-12-2009, 08:25 PM | #8 | |
Quote:
imho using a loop which will never loop is not clever. loops are ment to loop and i think it is useless to use IsUnitInRangeOfSegment for checking if a unit is in a rect. I think this does the same: JASS:function IsUnitAtRect takes unit u, rect r returns boolean local real x =GetUnitX(u) local real y =GetUnitY(u) local real maxx = GetRectMaxX(r) local real minx = GetRectMinX(r) local real maxy = GetRectMaxY(r) local real miny = GetRectMinY(r) if x > maxx then set x = maxx elseif x < minx then set x = minx endif if y > maxy then set y = maxy elseif y < miny then set y = miny endif return IsUnitInRange(u, x, y, 0.) endfunction |
| 04-12-2009, 09:22 PM | #9 |
... No, it isn't even close to doing the same. Edit: darn I forgot rects are always paralel to the x and y axis. Edit: Updated. |
| 04-12-2009, 10:15 PM | #10 |
Vex, you should probably remove the library requirement of IsUnitInRangeOfSegment() since you don't use it anymore. |
| 04-12-2009, 10:30 PM | #11 |
probably. |
| 04-12-2009, 10:54 PM | #12 | |
Quote:
|
| 04-12-2009, 10:56 PM | #13 |
Technically the unit is not necessarily in the rect, half of its collision circle could be outside. Not sure if At is a much better choice though. |
| 04-12-2009, 10:57 PM | #14 |
Well, I think 'in' makes more sense intuitively, even if it doesn't necessarily describe it perfectly. |
| 04-13-2009, 04:08 AM | #15 |
IsUnitOnRect() probably? I was thinking of circles when you and Rising_Dusk were having the name discussion. In = inside the radius of the circle, On = exactly at the radius of the circle. |
