Calculates the distance between two points.