Function distanceSq