sqrt() is monotonic, or order-preserving, for non-negative arguments so:
sqrt(x) < sqrt(y) iff 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