Notice that it is not important to compute the exact distance, it is important to found which point is the closest one. This is why I am computing the sum of the squares without even taking a sqrt, relying on the fact that sqrt is a monotonous function. I should probably add a comment there.