def test_solid_cyl_intersect(self): from lepton.domain import Cylinder from lepton.particle_struct import Vec3 cyl = Cylinder((0, -1, 0), (0, 1, 0), 1) lines = [ ((-2, 0, 0), (0, 0, 0)), ((2, 1, 0), (0, 1, 0)), ((0, 0, -2), (0, 0, 0.8)), ((0, 2, 0.5), (0, 0, 0.5)), ((0.5, -3, 0), (0.5, -0.5, 0)), ] expected = [ ((-1, 0, 0), (-1, 0, 0)), ((1, 1, 0), (1, 0, 0)), ((0, 0, -1), (0, 0, -1)), ((0, 1, 0.5), (0, 1, 0)), ((0.5, -1, 0), (0, -1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cyl.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = cyl.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_solid_cyl_intersect(self): from lepton.domain import Cylinder from lepton.particle_struct import Vec3 cyl = Cylinder((0,-1,0), (0,1,0), 1) lines = [ ((-2, 0, 0), (0, 0, 0)), ((2, 1, 0), (0, 1, 0)), ((0, 0, -2), (0, 0, 0.8)), ((0, 2, 0.5), (0, 0, 0.5)), ((0.5, -3, 0), (0.5, -0.5, 0)), ] expected = [ ((-1, 0, 0), (-1, 0, 0)), ((1, 1, 0), (1, 0, 0)), ((0, 0, -1), (0, 0, -1)), ((0, 1, 0.5), (0, 1, 0)), ((0.5, -1, 0), (0, -1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cyl.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = cyl.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_solid_cyl_no_intersect(self): from lepton.domain import Cylinder cyl = Cylinder((-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)), ((-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( cyl.intersect(start, end), (None, None)) self.assertEqual( cyl.intersect(end, start), (None, None))
def test_hollow_cyl_no_intersect(self): from lepton.domain import Cylinder cyl = Cylinder((0,1,-5), (0,1,0), 5, 1) for start, end in [ ((0, 1, -6), (0, 1, 1)), ((0, 1.5, -2), (0, 0.5, -1)), ((-10, 1, -5.1), (10, 1, -5.1)), ((0, -5, 0.1), (0, 1, 0.1)), ((0, 1, -3), (0, 1, -3)), ((5, 1, -4), (5, 1, -1)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual( cyl.intersect(start, end), (None, None)) self.assertEqual( cyl.intersect(end, start), (None, None))
def test_hollow_cyl_no_intersect(self): from lepton.domain import Cylinder cyl = Cylinder((0, 1, -5), (0, 1, 0), 5, 1) for start, end in [((0, 1, -6), (0, 1, 1)), ((0, 1.5, -2), (0, 0.5, -1)), ((-10, 1, -5.1), (10, 1, -5.1)), ((0, -5, 0.1), (0, 1, 0.1)), ((0, 1, -3), (0, 1, -3)), ((5, 1, -4), (5, 1, -1)), ((-2, 10, 20), (-5, 15, 19))]: self.assertEqual(cyl.intersect(start, end), (None, None)) self.assertEqual(cyl.intersect(end, start), (None, None))
def test_solid_cyl_no_intersect(self): from lepton.domain import Cylinder cyl = Cylinder((-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)), ((-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(cyl.intersect(start, end), (None, None)) self.assertEqual(cyl.intersect(end, start), (None, None))
def test_hollow_cyl_intersect(self): from lepton.domain import Cylinder cyl = Cylinder((3, 1, 0), (5, 1, 0), 2, 1) lines = [ ((4, 4, 0), (4, 2, 0)), ((3, 4, 0), (6, 1, 0)), ((4, 1, 0), (4, 4, 0)), ((2, 2.5, 0), (4, 2.5, 0)), ((2, 1, 0.5), (4, 1, 2.5)), ] expected = [ ((4, 3, 0), (0, 1, 0)), ((4, 3, 0), (0, 1, 0)), ((4, 2, 0), (0, -1, 0)), ((3, 2.5, 0), (-1, 0, 0)), ((3, 1, 1.5), (-1, 0, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cyl.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal)
def test_hollow_cyl_intersect(self): from lepton.domain import Cylinder cyl = Cylinder((3,1,0), (5,1,0), 2, 1) lines = [ ((4, 4, 0), (4, 2, 0)), ((3, 4, 0), (6, 1, 0)), ((4, 1, 0), (4, 4, 0)), ((2, 2.5, 0), (4, 2.5, 0)), ((2, 1 , 0.5), (4, 1, 2.5)), ] expected = [ ((4, 3, 0), (0, 1, 0)), ((4, 3, 0), (0, 1, 0)), ((4, 2, 0), (0, -1, 0)), ((3, 2.5, 0), (-1, 0, 0)), ((3, 1, 1.5), (-1, 0, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = cyl.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal)