small improvement for getDistance to squares