def intersect_poly_poly(
    am: bpy.types.Mesh, bm: bpy.types.Mesh, ai: int, bi: int, return_normals=False
):
    """
    ai, bi = polygon index into am.polygons, bm.polygons
    """

    # find line of intersection
    ap, bp = am.polygons[ai], bm.polygons[bi]
    ap_pos, bp_pos = am.vertices[ap.vertices[0]].co, bm.vertices[bp.vertices[0]].co
    line = geometry.intersect_plane_plane(ap_pos, ap.normal, bp_pos, bp.normal)
    if line == (None, None):
        return None

    a_tmin, a_tmax = find_poly_line_bounds(am, ai, line)
    b_tmin, b_tmax = find_poly_line_bounds(bm, bi, line)

    tmin = max(a_tmin, b_tmin)
    tmax = min(a_tmax, b_tmax)
    if tmin > tmax:
        return None

    p0 = np.array(line[0] + tmin * line[1])
    p1 = np.array(line[0] + tmax * line[1])

    if not return_normals:
        return p0, p1

    raise NotImplementedError

    ai, bi = polygon index into am.polygons, bm.polygons
    
infinigen/assets/objects/creatures/util/join_smoothing.py