def nearest_vertex(self, xi, yi):
        """
        Locate the index of the nearest vertex to points (xi,yi)
        and return the squared distance between (xi,yi) and
        each nearest neighbour.

        Parameters
        ----------
         xi : array of floats, shape (l,)
            Cartesian coordinates in the x direction
         yi : array of floats, shape (l,)
            Cartesian coordinates in the y direction

        Returns
        -------
         index : array of ints
            the nearest vertex to each of the supplied points
         dist : array of floats
            squared distance to the closest vertex identified

        Notes
        -----
         Faster searches can be obtained using a KDTree.
         Store all x and y coordinates in a (c)KDTree, then query
         a set of points to find their nearest neighbours.
        """
        n = np.array(xi).size
        xi = np.array(xi).reshape(n)
        yi = np.array(yi).reshape(n)

        idx  = np.empty_like(xi, dtype=np.int)
        dist = np.empty_like(xi, dtype=np.float)

        for pt in range(0, n):
            # i is the node at which we start the search
            # the closest x coordinate is a good place
            i = np.abs(self._x - xi[pt]).argmin()

            idx[pt], dist[pt] = _tripack.nearnd(xi[pt], yi[pt], i, self._x, self._y,\
                                                self.lst, self.lptr, self.lend)
        idx -= 1 # return to C ordering

        return self._deshuffle_simplices(idx), dist