def test_eval_child(self): m = cmaterials.PECMaterial() in_ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) out_rays = ctracer.RayCollection(1) m.eval_child_ray(in_ray, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), out_rays) out_ray = out_rays[0] self.assertEqual(out_ray.direction, (1, 0, -1))
def test_copy_to_array(self): rc = ctracer.RayCollection(10) rays = [self.make_ray() for i in range(7)] for ray in rays: rc.add_ray(ray) data = rc.copy_as_array() is_same = [self.compare(ray, row) for ray, row in zip(rays, data)] self.assertTrue(all(is_same))
def test_iteration(self): ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) rc = ctracer.RayCollection(10) for i in range(6): rc.add_ray(ray) self.assertEqual(rc.n_rays, 6) rays = [r for r in rc] self.assertEqual(len(rays), 6)
def test_properties(self): rc = ctracer.RayCollection(10) rays = [self.make_ray() for i in range(7)] for ray in rays: rc.add_ray(ray) data = rc.copy_as_array() self.assertTrue(numpy.alltrue(rc.E1_amp == data['E1_amp'])) self.assertTrue(numpy.alltrue(rc.E2_amp == data['E2_amp'])) self.assertTrue( numpy.alltrue(rc.refractive_index == data['refractive_index']))
def test_iteration2(self): ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) rc = ctracer.RayCollection(10) for i in range(6): rc.add_ray(ray) self.assertEqual(rc.n_rays, 6) itr = iter(rc) self.assertEqual(type(itr), ctracer.RayCollectionIterator) for i in range(6): r1 = next(itr) self.assertEqual(r1.origin, ray.origin) self.assertEqual(r1.direction, ray.direction)
def test_trace_segment(self): from raytrace import cfaces o = AnOwner(diameter=5.5, offset=6.6) c = cfaces.CircularFace(owner=o) rays = ctracer.RayCollection(10) in_ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) rays.add_ray(in_ray) self.assertEqual(rays.n_rays, 1) face_set = ctracer.FaceList() face_set.faces = [c] all_faces = [c] out_rays = ctracer.trace_segment(rays, [face_set], all_faces) self.assertEqual(out_rays.n_rays, 1) out_ray = out_rays[0] self.assertEqual(out_ray.direction, (1, 0, -1))