def smooth_around_line(obj, line_obj, rad, iters=30, factor=0.9):
    """
    Assumes: polyline is fairly densely sampled with points,
        obj and line_obj have same transform
    """

    assert obj.matrix_world == line_obj.matrix_world

    kd = mathutils.kdtree.KDTree(len(line_obj.data.vertices))
    for i, v in enumerate(line_obj.data.vertices):
        kd.insert(v.co, i)
    kd.balance()

    ds = np.array([kd.find(v.co)[2] for v in obj.data.vertices])
    for i, v in enumerate(obj.data.vertices):
        v.select = ds[i] < rad

    with butil.ViewportMode(obj, mode="EDIT"):
        bpy.ops.mesh.vertices_smooth(repeat=iters, factor=0.9)

    Assumes: polyline is fairly densely sampled with points,
        obj and line_obj have same transform
    
infinigen/assets/objects/creatures/util/join_smoothing.py