def test_zeroth_order_diffraction_equals_reflection(self):
     plane = Plane()
     ray = Rays([(A, B, -1)], [(0, 0, 1)], uniform(100, 1000))
     reflection = plane.reflect(ray)
     diffraction = plane.diffract(ray, uniform(0.001, 0.002), 0)
     self.assertTrue(allclose(reflection.endpoints, diffraction.endpoints))
     self.assertTrue(allclose(reflection.directions,
                              diffraction.directions))
 def test_diffract(self):
     """Test that diffraction works for a simple case."""
     plane = Plane()
     d = 1 / uniform(9e4, 1e5)
     order = -1
     wavelength = uniform(500e-9, 700e-9)
     ray = Rays([(0, -abs(B), 1)],
                array([(0, abs(B), -1)]) / sqrt(B ** 2 + 1),
                wavelength)
     diffraction = plane.diffract(ray, d, order)
     inc_angle = atan(abs(B))
     exit_angle = asin(sin(inc_angle) + order * wavelength / d)
     self.assertTrue(allclose(diffraction.directions[0],
                              (0, -sin(exit_angle), cos(exit_angle))))