def test_join_segments_multiple_pline():
    """Test the join_segments method with multiple polylines."""
    pts = (Point2D(0, 0), Point2D(2, 0), Point2D(2, 2), Point2D(0, 2))
    extra_pts = (Point2D(3, 3), Point2D(4, 3), Point2D(4, 4), Point2D(3, 4))
    l_segs = (LineSegment2D.from_end_points(extra_pts[0], extra_pts[1]),
              LineSegment2D.from_end_points(pts[0], pts[1]),
              LineSegment2D.from_end_points(pts[1], pts[2]),
              LineSegment2D.from_end_points(pts[0], pts[3]),
              LineSegment2D.from_end_points(pts[3], pts[2]))
    p_lines = Polyline2D.join_segments(l_segs, 0.01)
    assert len(p_lines) == 2

    l_segs = (LineSegment2D.from_end_points(extra_pts[0], extra_pts[1]),
              LineSegment2D.from_end_points(pts[0], pts[1]),
              LineSegment2D.from_end_points(pts[1], pts[2]),
              LineSegment2D.from_end_points(pts[0], pts[3]),
              LineSegment2D.from_end_points(pts[3], pts[2]),
              LineSegment2D.from_end_points(extra_pts[2], extra_pts[3]),
              LineSegment2D.from_end_points(extra_pts[1], extra_pts[2]),
              LineSegment2D.from_end_points(extra_pts[0], extra_pts[3]))
    p_lines = Polyline2D.join_segments(l_segs, 0.01)
    assert len(p_lines) == 2
    for p_line in p_lines:
        assert isinstance(p_line, Polyline2D)
        assert len(p_line) == 5
        assert p_line.is_closed(0.01)
def test_join_segments():
    """Test the join_segments method."""
    pts = (Point2D(0, 0), Point2D(2, 0), Point2D(2, 2), Point2D(0, 2))
    l_segs = (LineSegment2D.from_end_points(pts[0], pts[1]),
              LineSegment2D.from_end_points(pts[1], pts[2]),
              LineSegment2D.from_end_points(pts[2], pts[3]),
              LineSegment2D.from_end_points(pts[3], pts[0]))
    p_lines = Polyline2D.join_segments(l_segs, 0.01)
    assert len(p_lines) == 1
    assert isinstance(p_lines[0], Polyline2D)
    assert len(p_lines[0]) == 5
    assert p_lines[0].is_closed(0.01)

    l_segs = (LineSegment2D.from_end_points(pts[0], pts[1]),
              LineSegment2D.from_end_points(pts[2], pts[3]),
              LineSegment2D.from_end_points(pts[1], pts[2]),
              LineSegment2D.from_end_points(pts[3], pts[0]))
    p_lines = Polyline2D.join_segments(l_segs, 0.01)
    assert len(p_lines) == 1
    assert isinstance(p_lines[0], Polyline2D)
    assert len(p_lines[0]) == 5
    assert p_lines[0].is_closed(0.01)

    l_segs = (LineSegment2D.from_end_points(pts[0], pts[1]),
              LineSegment2D.from_end_points(pts[1], pts[2]),
              LineSegment2D.from_end_points(pts[0], pts[3]),
              LineSegment2D.from_end_points(pts[3], pts[2]))
    p_lines = Polyline2D.join_segments(l_segs, 0.01)
    assert len(p_lines) == 1
    assert isinstance(p_lines[0], Polyline2D)
    assert len(p_lines[0]) == 5
    assert p_lines[0].is_closed(0.01)
def test_join_segments_disconnected():
    """Test the join_segments method with diconnected polylines."""
    pts = (Point2D(0, 0), Point2D(2, 0), Point2D(2, 2), Point2D(0, 2))
    extra_pts = (Point2D(3, 3), Point2D(4, 3), Point2D(4, 4), Point2D(3, 4))

    l_segs = (LineSegment2D.from_end_points(extra_pts[0], extra_pts[1]),
              LineSegment2D.from_end_points(pts[0], pts[1]),
              LineSegment2D.from_end_points(pts[2], pts[3]),
              LineSegment2D.from_end_points(extra_pts[3], extra_pts[2]))
    p_lines = Polyline2D.join_segments(l_segs, 0.01)
    assert len(p_lines) == 4