def trimesh_swap_edge(mesh, u, v, allow_boundary=True):
    """Replace an edge of the mesh by an edge connecting the opposite
    vertices of the adjacent faces.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        Instance of mesh.
    u : str
        The key of one of the vertices of the edge.
    v : str
        The key of the other vertex of the edge.

    Returns
    -------
    None

    """
    fkey_uv = mesh.halfedge[u][v]
    fkey_vu = mesh.halfedge[v][u]
    u_on = mesh.is_vertex_on_boundary(u)
    v_on = mesh.is_vertex_on_boundary(v)
    if u_on and v_on:
        return False
    if not allow_boundary:
        if mesh.is_vertex_on_boundary(u) or mesh.is_vertex_on_boundary(v):
            return False
    uv = mesh.face[fkey_uv]
    vu = mesh.face[fkey_vu]
    o_uv = uv[uv.index(u) - 1]
    o_vu = vu[vu.index(v) - 1]
    if o_uv in mesh.halfedge[o_vu] and o_vu in mesh.halfedge[o_uv]:
        return False
    del mesh.halfedge[u][v]
    del mesh.halfedge[v][u]
    del mesh.face[fkey_uv]
    del mesh.face[fkey_vu]
    a = mesh.add_face([o_uv, o_vu, v])
    b = mesh.add_face([o_vu, o_uv, u])
    return a, b
