def test_solid_cone_intersect(self): from lepton.domain import Cone from lepton.particle_struct import Vec3 cone = Cone((0, 1, 0), (0, -1, 0), 2) lines = [ ((-2, 0, 0), (0, 0, 0)), ((3, 1, 0), (-1, 1, 0)), ((0, 0, -2), (0, 0, 5)), ((0.5, -3, 0), (0.5, -0.5, 0)), ((-1, 2, 0), (1, 0, 0)), ((-5, -2, 0), (5, 0, 0)), ((0, 10, 1), (0, -10, 1)), ((1, 1, 0), (-1, -1, 0)), ((0, 0, 0), (3, 0, 0)), ] expected = [ ((-1, 0, 0), Vec3(-1, 1, 0).normalize()), ((0, 1, 0), (0, 1, 0)), ((0, 0, -1), Vec3(0, 1, -1).normalize()), ((0.5, -1, 0), (0, -1, 0)), ((0, 1, 0), (0, 1, 0)), ((0, -1, 0), (0, -1, 0)), ((0, 0, 1), Vec3(0, 1, 1).normalize()), ((0.5, 0.5, 0), Vec3(1, 1, 0).normalize()), ((1, 0, 0), Vec3(-1, -1, 0).normalize()), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cone.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal)
def test_solid_cone_intersect(self): from lepton.domain import Cone from lepton.particle_struct import Vec3 cone = Cone((0,1,0), (0,-1,0), 2) lines = [ ((-2, 0, 0), (0, 0, 0)), ((3, 1, 0), (-1, 1, 0)), ((0, 0, -2), (0, 0, 5)), ((0.5, -3, 0), (0.5, -0.5, 0)), ((-1, 2, 0), (1, 0, 0)), ((-5, -2, 0), (5, 0, 0)), ((0, 10, 1), (0, -10, 1)), ((1, 1, 0), (-1, -1, 0)), ((0, 0, 0), (3, 0, 0)), ] expected = [ ((-1, 0, 0), Vec3(-1, 1, 0).normalize()), ((0, 1, 0), (0, 1, 0)), ((0, 0, -1), Vec3(0, 1, -1).normalize()), ((0.5, -1, 0), (0, -1, 0)), ((0, 1, 0), (0, 1, 0)), ((0, -1, 0), (0, -1, 0)), ((0, 0, 1), Vec3(0, 1, 1).normalize()), ((0.5, 0.5, 0), Vec3(1, 1, 0).normalize()), ((1, 0, 0), Vec3(-1, -1, 0).normalize()), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cone.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal)
def test_hollow_cone_no_intersect(self): from lepton.domain import Cone cone = Cone((-1, -1, 0), (1, 1, 0), 4, 3) for start, end in [ ((-1, -1, 0), (-2, -1, 0)), ((1, 1, 0), (1, 1.1, 0)), ((-3, 7, 0), (7, -3, 0)), ((-5, -5, 0), (-3, -3, 0)), ((-2, -2, 4.1), (2, 2, 4.1)), ((-2, -2, -2), (-2, -2, -2)), ((1, 1, 0), (0, 0, 0)), ((-2, 10, 20), (-5, 15, 19)) ]: self.assertEqual(cone.intersect(start, end), (None, None))
def test_solid_cone_no_intersect(self): from lepton.domain import Cone cone = Cone((-1,-1,0), (1,1,0), 4, 0) for start, end in [ ((-1, -1, 0), (-2, -1, 0)), ((1, 1, 0), (1, 1.1, 0)), ((-3, 7, 0), (7, -3, 0)), ((-5, -5, 0), (-3, -3, 0)), ((-2, -2, 4.1), (2, 2, 4.1)), ((-2, -2, -2), (-2, -2, -2)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual( cone.intersect(start, end), (None, None))
def test_hollow_cone_intersect(self): from lepton.domain import Cone from lepton.particle_struct import Vec3 cone = Cone((0, 0, 2), (0, 0, -1), 3, 1) lines = [ ((0, 0, -3), (0, 0, 3)), ((0, -5, 0), (0, 5, 0)), ((0, 0, 0), (0, 5, 0)), ((2, 0, -2), (2, 0, 0)), ((0.5, 0, -3), (0.5, 0, 3)), ] expected = [ ((0, 0, 2), (0, 0, -1)), ((0, -2, 0), Vec3(0, -1, 1).normalize()), ((0, 2.0 / 3.0, 0), Vec3(0, -3, -1).normalize()), ((2, 0, -1), (0, 0, -1)), ((0.5, 0, 0.5), Vec3(-3, 0, -1).normalize()), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cone.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal)
def test_hollow_cone_intersect(self): from lepton.domain import Cone from lepton.particle_struct import Vec3 cone = Cone((0,0,2), (0,0,-1), 3, 1) lines = [ ((0, 0, -3), (0, 0, 3)), ((0, -5, 0), (0, 5, 0)), ((0, 0, 0), (0, 5, 0)), ((2, 0, -2), (2, 0, 0)), ((0.5, 0, -3), (0.5, 0, 3)), ] expected = [ ((0, 0, 2), (0, 0, -1)), ((0, -2, 0), Vec3(0, -1, 1).normalize()), ((0, 2.0/3.0, 0), Vec3(0, -3, -1).normalize()), ((2, 0, -1), (0, 0, -1)), ((0.5, 0, 0.5), Vec3(-3, 0, -1).normalize()), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cone.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal)