  Accurate evaluation of nearly singular integrals plays an important role in
many boundary integral equation based numerical methods. In this paper, we
propose a variant of singularity swapping method to accurately evaluate the
layer potentials for arbitrarily close targets. Our method is based on the
global trapezoidal rule and trigonometric interpolation, resulting in an
explicit quadrature formula. The method achieves spectral accuracy for nearly
singular integrals on closed analytic curves. In order to extract the
singularity from the complexified distance function, an efficient root finding
method is proposed based on contour integration. Through the change of
variables, we also extend the quadrature method to integrals on the piecewise
analytic curves. Numerical examples for Laplace's and Helmholtz equations show
that high order accuracy can be achieved for arbitrarily close field
evaluation.
