def get_flat_poly_lists_convex_hull()

in function_app/src/helpers/image.py [0:0]


def get_flat_poly_lists_convex_hull(poly_lists: list[list[float]]) -> list[int]:
    """
    Get the convex hull of a list of polygons.

    :param poly_lists: List of (x0, y0, x1, y1) polygon lists.
    :type poly_lists: list[list[float]]
    :return: Flattened (x0, y0, x1, y1) convex hull polygon.
    :rtype: list[int]
    """
    list_of_points = list(itertools.chain.from_iterable(poly_lists))
    # Multiply points by 1000 to avoid issues with casting floats to ints
    list_of_points = [point * 1000 for point in list_of_points]
    contour = np.array(list_of_points).reshape((-1, 1, 2)).astype(np.int32)
    return contour.reshape(-1) / 1000  # Divide by 1000 to get back to original scale