def to_meshgrid(x):
    """
    Converts a 2D grid of points (x,y) into a mesh grid

    Parameters
    ----------
    x: list[list]
        A 2D array of 2-tuples (x,y)

    Returns
    -------
    tuple
        A 2-tuple with the X and Y coordinates of the mesh

    """
    dim1r, dim2r = range(len(x)), range(len(x[0]))
    x1 = [[x[n][m][1] for m in dim2r] for n in dim1r]
    x2 = [[x[n][m][0] for m in dim2r] for n in dim1r]
    return x1, x2

    # Nr, Mr = range(len(X)), range(len(X[0]))
    # N = [[0 for _ in Mr] for _ in Nr]
    # M = [[0 for _ in Mr] for _ in Nr]
    #
    # for n in Nr:
    #     for m in Mr:
    #         N[n][m] = X[n][m][0]
    #         M[n][m] = X[n][m][1]
    #
    # return N, M