def test_oblique_Plane(self): from lepton.domain import Plane from lepton.particle_struct import Vec3 normal = Vec3(3, 4, 5).normalize() plane = Plane((0, 0, 0), normal) self.assertEqual(tuple(plane.point), (0, 0, 0)) self.assertEqual(tuple(plane.normal), tuple(normal)) self.failIf(normal in plane) self.failUnless(plane.point in plane) self.failUnless(-normal in plane) p, N = plane.intersect((0, 1, 0), (0, -1, 0)) self.assertVector(p, (0, 0, 0)) self.assertVector(N, normal) p, N = plane.intersect((0, -1, 0), (0, 1, 0)) self.assertVector(p, (0, 0, 0)) self.assertVector(N, -normal)
def test_oblique_Plane(self): from lepton.domain import Plane from lepton.particle_struct import Vec3 normal = Vec3(3,4,5).normalize() plane = Plane((0,0,0), normal) self.assertEqual(tuple(plane.point), (0, 0, 0)) self.assertEqual(tuple(plane.normal), tuple(normal)) self.failIf(normal in plane) self.failUnless(plane.point in plane) self.failUnless(-normal in plane) p, N = plane.intersect((0,1,0), (0,-1,0)) self.assertVector(p, (0,0,0)) self.assertVector(N, normal) p, N = plane.intersect((0,-1,0), (0,1,0)) self.assertVector(p, (0,0,0)) self.assertVector(N, -normal)
def test_horizontal_Plane(self): from lepton.domain import Plane for Ny in (1, -1, 50, -50): # Simple horizontal plane plane = Plane((0, 0, 0), (0, Ny, 0)) self.assertEqual(plane.generate(), (0, 0, 0)) self.failUnless((0, 0, 0) in plane) self.failIf((0, Ny, 0) in plane) self.failUnless((0, -Ny, 0) in plane) # Perpendicular intersection p, N = plane.intersect((1, 1, 4), (1, -1, 4)) self.assertVector(p, (1, 0, 4)) self.assertVector(N, (0, 1, 0)) p, N = plane.intersect((-5, -2, 20), (-5, 5, 20)) self.assertVector(p, (-5, 0, 20)) self.assertVector(N, (0, -1, 0)) # Oblique intersection plane = Plane((20, 5, 3000), (0, Ny, 0)) p, N = plane.intersect((0, 7, 0), (4, 3, -4)) self.assertVector(p, (2, 5, -2)) self.assertVector(N, (0, 1, -0)) # No intersection self.assertEqual(plane.intersect((40, 8, 20), (40, 6, -4)), (None, None)) self.assertEqual(plane.intersect((0, 0, 0), (3, 4, 10)), (None, None)) # Line in plane self.assertEqual(plane.intersect((-10, 5, 0), (3, 5, 10)), (None, None))
def test_horizontal_Plane(self): from lepton.domain import Plane for Ny in (1, -1, 50, -50): # Simple horizontal plane plane = Plane((0,0,0), (0,Ny,0)) self.assertEqual(plane.generate(), (0,0,0)) self.failUnless((0,0,0) in plane) self.failIf((0, Ny, 0) in plane) self.failUnless((0, -Ny, 0) in plane) # Perpendicular intersection p, N = plane.intersect((1, 1, 4), (1, -1, 4)) self.assertVector(p, (1, 0, 4)) self.assertVector(N, (0, 1, 0)) p, N = plane.intersect((-5, -2, 20), (-5, 5, 20)) self.assertVector(p, (-5, 0, 20)) self.assertVector(N, (0, -1, 0)) # Oblique intersection plane = Plane((20,5,3000), (0,Ny,0)) p, N = plane.intersect((0, 7, 0), (4, 3, -4)) self.assertVector(p, (2, 5, -2)) self.assertVector(N, (0, 1, -0)) # No intersection self.assertEqual( plane.intersect((40, 8, 20), (40, 6, -4)), (None, None)) self.assertEqual( plane.intersect((0, 0, 0), (3, 4, 10)), (None, None)) # Line in plane self.assertEqual( plane.intersect((-10, 5, 0), (3, 5, 10)), (None, None))