Function to compute distance between CGPoints.