calculate distance to nearest line segment, SLOW