[mapserver-dev] reduce sqrt() usage in mapserver distance calculations

Daniel Morissette dmorissette at mapgears.com
Fri Sep 25 08:59:49 EDT 2009


Hi Bret,

That's a very welcome enhancement. Could you please create a ticket for 
it assigned to me (dmorissette) and attach the patch and we'll try to 
get it in the next 5.6 beta?

http://trac.osgeo.org/mapserver/

Daniel

Bret S. Lambert wrote:
> Looking through mapsearch.c, I noticed a pretty textbook case of
> sqrt() overuse in distance calculation functions. Given that these
> functions are called many times in tight loops, deferring the actual
> calculation of the square root until necessary should reduce the
> computational overhead needed.
> 
> The attached diff creates a pair of 'Quick' function versions,
> which require the caller to call sqrt() on the returned value in
> order to get the actual distance; however, when finding a minimum
> distance, comparing the squares of the distances gives the same
> result as comparing the distances themselves, so calling the
> Quick version in a loop and then doing a single sqrt() on the
> value found should result in a measurable improvement.
> 
> Caveats:
> 
> Tested by compilation and inspection only; I have no access to
> a testbed until after the weekend, and am relying on the kindness
> of strangers ;) (however, I will be available via email for the
> foreseeable future, and have 6 paid days in the next 2 weeks that
> I can use to hack on this for a client).
> 
> If this diff is lost/mangled by the mailer daemon, I'll find an
> alternate way of getting it to the list.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev


-- 
Daniel Morissette
http://www.mapgears.com/


More information about the mapserver-dev mailing list