![]() |
#1 |
Free Software Terrorist
Technical Director
|
![]() ![]() 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 |
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
User
Join Date: Oct 2006
Posts: 1,490
![]() |
![]() Why four times :
![]() exitwhen ( IsUnitInRangeOfSegment(u, nx,ny, nx,my, 0) ) |
![]() |
![]() |
![]() |
#3 |
Free Software Terrorist
Technical Director
|
![]() take a closer look.
__________________ |
![]() |
![]() |
![]() |
#4 |
User
Join Date: Jan 2007
Posts: 528
![]() ![]() |
![]() 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? |
![]() |
![]() |
![]() |
#5 |
User
Join Date: Oct 2006
Posts: 1,490
![]() |
![]() ok my bad, variables' name are nearly the same :p
|
![]() |
![]() |
![]() |
#6 | |
Free Software Terrorist
Technical Director
|
![]() Quote:
Edit: code got shorter. |
|
![]() |
![]() |
![]() |
#8 | |
User
Join Date: Jul 2006
Posts: 57
![]() |
![]() 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: ![]() 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 |
|
![]() |
![]() |
![]() |
#9 |
Free Software Terrorist
Technical Director
|
![]() ... 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. |
![]() |
![]() |
![]() |
#11 |
Free Software Terrorist
Technical Director
|
![]() probably.
__________________ |
![]() |
![]() |
![]() |
#12 | |
Obscurity, the Art
|
![]() Quote:
|
|
![]() |
![]() |
![]() |
#13 |
Free Software Terrorist
Technical Director
|
![]() 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.
__________________ |
![]() |
![]() |
![]() |
#15 |
User
Join Date: Feb 2009
Posts: 109
![]() |
![]() 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.
__________________ |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|