compute distance from segment to segment