Analysis of the diffuse-domain method for solving PDEs in complex geometries