Discrete-dipole approximation for periodic targets: theory and tests.