One thing you can do pretty easily to increase performance (although only by a tiny bit) is use squared distances instead of normal ones. For example, instead of
you can use
square roots are slow, so the second version is a bit faster. Probably only worth it if it's inside a loop or something though. --David Alves |