sqrt()sqrt() is continuousmonotonic, meaningor order-preserving, for non-negative arguments so:
if sqrt(x) < sqrt(y) theniff x < y andAnd 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 sqrtsqrt()-step from your pythagorasPythagoras-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