def test_shift(self): s = gm.Sphere(center=zeros(), radius=2.0) self.assertEqual(s.center, gm.Vector3()) shifted = s.shift(gm.Vector3(10)) self.assertEqual(shifted.center, gm.Vector3(10, 0, 0)) self.assertEqual(shifted.radius, 2.0) s = gm.Sphere(center=gm.Vector3(10, 10), radius=2.0) shifted = s.shift(gm.Vector3(-10, -10)) self.assertEqual(shifted.center, gm.Vector3()) s = gm.Sphere(center=zeros(), radius=2.0) s += mp.Vector3(5, 5) self.assertEqual(s.center, mp.Vector3(5, 5)) s = gm.Sphere(center=zeros(), radius=2.0) new_sphere = s + mp.Vector3(5, 5) self.assertEqual(new_sphere.center, mp.Vector3(5, 5)) self.assertEqual(s.center, zeros()) s = gm.Sphere(center=zeros(), radius=2.0) new_sphere = mp.Vector3(5, 5) + s self.assertEqual(new_sphere.center, mp.Vector3(5, 5)) self.assertEqual(s.center, zeros())
def test_non_neg_radius_constructor(self): gm.Sphere(radius=0.0) gm.Sphere(radius=1.0) with self.assertRaises(ValueError) as ctx: gm.Sphere(radius=-1) self.assertIn("Got -1", ctx.exception)
def test_shift(self): s = gm.Sphere(center=zeros(), radius=2.0) self.assertEqual(s.center, gm.Vector3()) s.shift(gm.Vector3(10)) self.assertEqual(s.center, gm.Vector3(10, 0, 0)) s = gm.Sphere(center=gm.Vector3(10, 10), radius=2.0) s.shift(gm.Vector3(-10, -10)) self.assertEqual(s.center, gm.Vector3())
def test_kwargs_passed_to_parent(self): s = gm.Sphere(1.0) self.assertEqual(s.material.epsilon_diag, ones()) self.assertEqual(s.center, zeros()) self.assertEqual(s.radius, 1) s = gm.Sphere(radius=2.0) self.assertEqual(s.material.epsilon_diag, ones()) self.assertEqual(s.center, zeros()) self.assertEqual(s.radius, 2.0) s = gm.Sphere(1.0, center=ones()) self.assertEqual(s.material.epsilon_diag, ones()) self.assertEqual(s.center, ones()) self.assertEqual(s.radius, 1)
def test_contains_point(self): s = gm.Sphere(center=zeros(), radius=2.0) point = ones() self.assertTrue(point in s) self.assertTrue(mp.is_point_in_periodic_object(mp.Vector3(), s)) self.assertIn(point, s) self.assertFalse(gm.Vector3(10, 10, 10) in s)
def test_non_neg_radius_setter(self): s = gm.Sphere(radius=0.0) s.radius = 1.0 with self.assertRaises(ValueError) as ctx: s.radius = -1.0 self.assertIn("Got -1.0", ctx.exception)
def test_invalid_kwarg_raises_exception(self): with self.assertRaises(TypeError): gm.Sphere(invalid='This is not allowed') with self.assertRaises(TypeError): gm.Sphere(radius=1.0, oops='Nope')
def test_info(self): # Sanity test to ensure that display_geometric_object_info is callable s = gm.Sphere(2) s.info() s.info(2)