def get_shortest_endpoint(x, y, intersections: List[Point]) -> Tuple[float, float]: shortest_x, shortest_y = intersections[0].x, intersections[0].y min_length = LineSegment(Point(x, y), Point(shortest_x, shortest_y)).length() for p in intersections: xe, ye = p.x, p.y tmp = LineSegment(Point(x, y), Point(xe, ye)) if tmp.length() < min_length: shortest_x = xe shortest_y = ye return (shortest_x, shortest_y)
def test_line_segment_length_y(): line_segment = LineSegment(Point(0, 0), Point(0, 42)) assert line_segment.length() == 42 line_segment = LineSegment(Point(0, 2), Point(0, 42)) assert line_segment.length() == 40
def test_line_segment_length_xy(): line_segment = LineSegment(Point(0, 0), Point(3, 4)) assert line_segment.length() == 5
def test_line_segment_length_x(): line_segment = LineSegment(Point(0, 0), Point(42, 0)) assert line_segment.length() == 42 line_segment = LineSegment(Point(2, 0), Point(42, 0)) assert line_segment.length() == 40