def find_longest_edge(polygon: Union[shapely.geometry.Polygon, list]):
    """
    Return the longest edge of a polygon
    Args:
        polygon: shapely.Polygon or list of 2D points representing a polygon

    Returns: the longest edge

    """
    coords = list(polygon.exterior.coords) if isinstance(polygon, shapely.geometry.Polygon) else polygon
    edges = []
    # 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]))
    return heapq.nlargest(1, edges, key=lambda edge: size(edge))

    Return the longest edge of a polygon
    Args:
        polygon: shapely.Polygon or list of 2D points representing a polygon

    Returns: the longest edge

    
metadrive/utils/shapely_utils/geom.py