def find_poly_line_bounds(mesh, poly_idx, line, eps=1e-5):
    """
    assumes `mesh.polygons[poly_idx]` is valid, convex, and contains `line`
    returns t1, t2 such that `for all t1<t<t2: line(t) \in poly`
    """

    poly = mesh.polygons[poly_idx]

    # find all line - polyedge intersections
    ts, dists = [], []
    for vi_1, vi_2 in poly.edge_keys:
        v1, v2 = mesh.vertices[vi_1].co, mesh.vertices[vi_2].co
        lp, vp = intersect_line_seg(line, (v1, v2))
        if lp is None:
            continue
        ts.append(invert_line(line, lp))
        dists.append((lp - vp).length)
    ts = np.array(ts)
    dists = np.array(dists)

    mask = dists < eps
    if mask.sum() < 2:
        raise ValueError(
            f"find_poly_line_bounds(..., {eps=}) had {mask.sum()} intersections, maybe increase eps. {ts=}, {dists=}"
        )
    ts = ts[mask]

    return float(ts.min()), float(ts.max())

    assumes `mesh.polygons[poly_idx]` is valid, convex, and contains `line`
    returns t1, t2 such that `for all t1<t<t2: line(t) \in poly`
    
infinigen/assets/objects/creatures/util/join_smoothing.py