A General Formalism to Model the Diffraction Pattern of Layered and Faulted Materials