def find_longest_parallel_edges(polygon: Union[shapely.geometry.Polygon, list]):
    """
    Find and return the longest parallel edges of a polygon. If it can not find, return the longest two edges instead.
    Args:
        polygon: shapely.Polygon or list of 2D points representing a polygon

    Returns:

    """

    edges = []
    longest_parallel_edges = None
    coords = list(polygon.exterior.coords) if isinstance(polygon, shapely.geometry.Polygon) else polygon

    # Extract the edges from the polygon
    for i in range(len(coords) - 1):
        edge = (coords[i], coords[i + 1])
        edges.append(edge)
    edges.append((coords[-1], coords[0]))

    # Compare each edge with every other edge
    for edge1, edge2 in combinations(edges, 2):
        slope1 = calculate_slope(*edge1)
        slope2 = calculate_slope(*edge2)

        # Check if the slopes are equal (or both are vertical)
        if abs(slope1 - slope2) < 0.5:
            max_len = max(length(edge1), length(edge2))
            if longest_parallel_edges is None or max_len > longest_parallel_edges[-1]:
                longest_parallel_edges = ((edge1, edge2), max_len)

    if longest_parallel_edges:
        return longest_parallel_edges[0]
    else:
        # return sorted(edges, key=lambda edge: size(edge))[-2:]
        return heapq.nlargest(2, edges, key=lambda edge: size(edge))

    Find and return the longest parallel edges of a polygon. If it can not find, return the longest two edges instead.
    Args:
        polygon: shapely.Polygon or list of 2D points representing a polygon

    Returns:

    
metadrive/utils/shapely_utils/geom.py