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

Bret S. Lambert bret.lambert at freecodeint.com
Fri Sep 25 09:37:06 EDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Assigned to dmorissette as ticket #3134

Daniel Morissette wrote:
> 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
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (OpenBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkq8x4IACgkQiP9Ks5BxbEkPGwCeP8jaNqJUHTlOmtEoy2YLvzI/
hTgAn1tzVIgrslVDDSqw9pVnA93y9iaM
=x3tU
-----END PGP SIGNATURE-----


More information about the mapserver-dev mailing list