Skip to main content
2 of 3
added 20 characters in body

sqrt() is continuous, meaning

if sqrt(x) < sqrt(y) then x < y 

and vice versa

So if you only want to compare two distances but are not interested in their actual values you can just cut out the sqrt-step from your pythagoras-stuff:

pseudoDistanceB = (A.x - B.x)² + (A.y - B.y)² pseudoDistanceC = (A.x - C.x)² + (A.y - C.y)² if (pseudoDistanceB < pseudoDistanceC) { A is closest to B! } else { A is closest to C! } 

It's not as efficient as the oct-tree thing, but it's easier to implement and does bump up the speed at least a little bit