HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GetNearest

02-03-2010, 08:13 PM#1
grim001
Requires: GroupUtils

GetNearest is a very simple library that allows you to find the nearest unit, destructable, or item to a specified point within a specified radius. You can use a boolexpr filter as well, just like native Enum functions.

I made this because the concept behind FindFuncs seemed useful. You can still find the nearest tree by using IsDestructableTree within a boolexpr.

GetNearestUnit can easily be recreated using PruneGroup, along with more generalized functionality. SortUtils should be used when actual sorting of units by values is required. This library is just meant to be small and easy to use.

Expand JASS:
02-04-2010, 03:00 PM#2
Rising_Dusk
Isn't the Pow() function classically slower than just multiplying the numbers together? I seem to recall something like that. Anyways, this fixes most of the problems I had with Michael Peppers submission (lack of textmacros, etc). I can kind of see it being niche useful, but I'll let it sit here to get some more feedback before doing anything with it.
02-04-2010, 03:07 PM#3
Anachron
Yes, Pow is slower then a*a.
02-04-2010, 03:53 PM#4
Archmage Owenalacaster
When you resize the rect, shouldn't it account for the map boundaries? While this is never an issue for units and items, it is not uncommon for destructables to be placed beyond the playable map area.
02-04-2010, 04:00 PM#5
grim001
Quote:
Originally Posted by Rising_Dusk
Isn't the Pow() function classically slower than just multiplying the numbers together?

Depends on a lot of factors, like whether you would have to declare extra locals, perform extra set operations or make extra native calls without using Pow. I guess I'll benchmark it because I'm curious.

Quote:
Originally Posted by Archmage Owenalacaster
When you resize the rect, shouldn't it account for the map boundaries? While this is never an issue for units and items, it is not uncommon for destructables to be placed beyond the playable map area.

As far as practical usage goes, I guess this is important. I'll make all the functions filter out stuff outside of map boundries.
02-05-2010, 03:38 AM#6
grim001
I did a benchmark comparing GetNearestDestructable using Pow versus multiplication in the enum. There were 100 trees within range of the enumeration, and the test was repeated 100,000 times. The benchmark showed that the multiplication version was 0.0697% slower, which is such a small difference that it amounts to noise. In this case I'm going to go with the one that looks better.

I also fixed a couple typos, optimized the code a bit, and made sure that none of the functions will return stuff outside the playable map area.
02-05-2010, 02:09 PM#7
Anitarf
Well, in this case, using multiplication requires you to declare additional locals or do the x - GetUnitX(u) calculation twice, so using Pow likely is faster. Otherwise, I believe I've seen other people post test results where Pow(x,2) was slightly slower than x*x while Pow(x,3) was slightly faster than its multiplication counterpart.

Either way, as your test shows, the difference is inconsequential in the context of this function.
02-05-2010, 04:00 PM#8
Rising_Dusk
*Shrug* Don't need a benchmark and two posts to tell me so, it was just something that came to mind as a possible improvement. I can think of nothing else this really needs, so if it works as listed and no other reviewer can think of anything, we can approve it.
02-21-2010, 06:27 PM#9
Rising_Dusk
Going to go ahead and approve this, then.