示例#1
0
	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))
示例#2
0
    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))
示例#3
0
	def test_shell_cyl_generate_contains(self):
		from lepton.domain import Cylinder
		cyl = Cylinder((2, 3, 4), (2, 3, 6), 2, 2)
		for i in range(20):
			x, y, z = cyl.generate()
			mag = (x - 2)**2 + (y - 3)**2
			self.assertAlmostEqual(mag, 4.0, 4)
			self.failUnless(4 <= z <= 6, z)
			self.failUnless((x, y, z) in cyl, (x, y ,z))
示例#4
0
 def test_shell_cyl_generate_contains(self):
     from lepton.domain import Cylinder
     cyl = Cylinder((2, 3, 4), (2, 3, 6), 2, 2)
     for i in range(20):
         x, y, z = cyl.generate()
         mag = (x - 2)**2 + (y - 3)**2
         self.assertAlmostEqual(mag, 4.0, 4)
         self.failUnless(4 <= z <= 6, z)
         self.failUnless((x, y, z) in cyl, (x, y, z))
示例#5
0
 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))
示例#6
0
 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))
示例#7
0
 def test_solid_cyl_closest_pt_to_on_axis(self):
     from lepton.domain import Cylinder
     cyl = Cylinder((0, 3, 0), (0, 0, 0), 3)
     for point, closest, normal in [
         ((0, 4, 0), (0, 3, 0), (0, 1, 0)),
         ((0, 3, 0), (0, 3, 0), (0, 0, 0)),
         ((0, 2, 0), (0, 2, 0), (0, 0, 0)),
         ((0, -2, 0), (0, 0, 0), (0, -1, 0)),
         ((0, 0, 0), (0, 0, 0), (0, 0, 0)),
     ]:
         p, N = cyl.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
示例#8
0
	def test_solid_cyl_closest_pt_to_on_axis(self):
		from lepton.domain import Cylinder
		cyl = Cylinder((0, 3, 0), (0, 0, 0), 3)
		for point, closest, normal in [
			((0, 4, 0), (0, 3, 0), (0, 1, 0)),
			((0, 3, 0), (0, 3, 0), (0, 0, 0)),
			((0, 2, 0), (0, 2, 0), (0, 0, 0)),
			((0, -2, 0), (0, 0, 0), (0, -1, 0)),
			((0, 0, 0), (0, 0, 0), (0, 0, 0)),
			]:
			p, N = cyl.closest_point_to(point)
			self.assertVector(p, closest)
			self.assertVector(N, normal)
示例#9
0
	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))
示例#10
0
	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))
示例#11
0
	def test_cylinder_length(self):
		from lepton.domain import Cylinder
		cyl = Cylinder((0,0,0), (2,0,0), 1)
		self.assertEqual(cyl.length, 2)
		self.assertVector(cyl.end_point0, (0,0,0))
		self.assertVector(cyl.end_point1, (2,0,0))
		cyl = Cylinder((1,0,-1), (3,2,1), 1)
		self.assertAlmostEqual(cyl.length, math.sqrt(12), 5)
		self.assertVector(cyl.end_point0, (1,0,-1))
		self.assertVector(cyl.end_point1, (3,2,1))

		# Changing end points shoud adjust length
		cyl.end_point0 = (3, 0, -1)
		self.assertAlmostEqual(cyl.length, math.sqrt(8), 5)
		cyl.end_point1 = (5, 0, -1)
		self.assertAlmostEqual(cyl.length, 2, 5)
示例#12
0
	def test_solid_cyl_generate_contains(self):
		from lepton.domain import Cylinder
		cyl = Cylinder((0, 1, 2), (0, 2, 2), 2)
		for i in range(20):
			x, y, z = cyl.generate()
			mag = x**2 + (z - 2)**2
			self.failUnless(mag <= 4, ((x, y), mag))
			self.failUnless(1 <= y <= 2, y)
			self.failUnless((x, y, z) in cyl, (x, y ,z))

		self.failUnless((0, 1, 2) in cyl)
		self.failUnless((0, 2, 2) in cyl)
		self.failUnless((2, 1.5, 2) in cyl)
		self.failUnless((-2, 1.5, 2) in cyl)
		self.failIf((2.1, 1, 2) in cyl)
		self.failIf((-2.1, 1, 2) in cyl)
		self.failIf((0, 0, 2) in cyl)
		self.failIf((0, 2.1, 2) in cyl)
示例#13
0
    def test_solid_cyl_generate_contains(self):
        from lepton.domain import Cylinder
        cyl = Cylinder((0, 1, 2), (0, 2, 2), 2)
        for i in range(20):
            x, y, z = cyl.generate()
            mag = x**2 + (z - 2)**2
            self.failUnless(mag <= 4, ((x, y), mag))
            self.failUnless(1 <= y <= 2, y)
            self.failUnless((x, y, z) in cyl, (x, y, z))

        self.failUnless((0, 1, 2) in cyl)
        self.failUnless((0, 2, 2) in cyl)
        self.failUnless((2, 1.5, 2) in cyl)
        self.failUnless((-2, 1.5, 2) in cyl)
        self.failIf((2.1, 1, 2) in cyl)
        self.failIf((-2.1, 1, 2) in cyl)
        self.failIf((0, 0, 2) in cyl)
        self.failIf((0, 2.1, 2) in cyl)
示例#14
0
	def test_hollow_cyl_generate_contains(self):
		from lepton.domain import Cylinder
		cyl = Cylinder((-1, -1, 0), (-3, -1, 0), 2, 1)
		for i in range(20):
			x, y, z = cyl.generate()
			mag = (y + 1)**2 + z**2
			self.failUnless(1 <= mag <= 4, ((y, z), mag))
			self.failUnless(-3 <= x <= -1, y)
			self.failUnless((x, y, z) in cyl, (x, y ,z))

		self.failUnless((-1.5, -2, 0) in cyl)
		self.failUnless((-2, -1, -1) in cyl)
		self.failUnless((-3, 0, 0) in cyl)
		self.failUnless((-1, 0, 0) in cyl)
		self.failIf((-2, 2, 0) in cyl)
		self.failIf((-2, -1, 2.1) in cyl)
		self.failIf((0, 0, 2) in cyl)
		self.failIf((0, 2.1, 2) in cyl)
		self.failIf((-1, -1, 0) in cyl)
		self.failIf((-2, -1, 0) in cyl)
		self.failIf((-3, -1, 0) in cyl)
示例#15
0
    def test_hollow_cyl_generate_contains(self):
        from lepton.domain import Cylinder
        cyl = Cylinder((-1, -1, 0), (-3, -1, 0), 2, 1)
        for i in range(20):
            x, y, z = cyl.generate()
            mag = (y + 1)**2 + z**2
            self.failUnless(1 <= mag <= 4, ((y, z), mag))
            self.failUnless(-3 <= x <= -1, y)
            self.failUnless((x, y, z) in cyl, (x, y, z))

        self.failUnless((-1.5, -2, 0) in cyl)
        self.failUnless((-2, -1, -1) in cyl)
        self.failUnless((-3, 0, 0) in cyl)
        self.failUnless((-1, 0, 0) in cyl)
        self.failIf((-2, 2, 0) in cyl)
        self.failIf((-2, -1, 2.1) in cyl)
        self.failIf((0, 0, 2) in cyl)
        self.failIf((0, 2.1, 2) in cyl)
        self.failIf((-1, -1, 0) in cyl)
        self.failIf((-2, -1, 0) in cyl)
        self.failIf((-3, -1, 0) in cyl)
示例#16
0
    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)
示例#17
0
	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)
示例#18
0
	def test_cyl_closest_pt_to(self):
		from lepton.domain import Cylinder
		from lepton.particle_struct import Vec3
		cyl = Cylinder((-2, 3, 0), (0, 3, 0), 3, 2)
		for point, closest, normal in [
			((-1, 7, 0), (-1, 6, 0), (0, 1, 0)),
			((-2, 3, -6), (-2, 3, -3), (0, 0, -1)),
			((0, 6, 3), Vec3(0, 3, 0) + Vec3(0, 1, 1).normalize() * 3, Vec3(0, 1, 1).normalize()),
			((-2.2, 5.5, 0), (-2, 5.5, 0), (-1, 0, 0)),
			((-5, 10, 0), (-2, 6, 0), (-1, 0, 0)),
			((-10, 3, 1), (-2, 3, 2), (-1, 0, 0)),
			((0.5, 0, 0), (0, 0, 0), (1, 0, 0)),
			((3, 5, 0), (0, 5, 0), (1, 0, 0)),
			((20, 3, -0.1), (0, 3, -2), (1, 0, 0)),
			# points inside cylinder and along axis
			((-0.5, 5.5, 0), (-0.5, 5.5, 0), (0, 0, 0)),
			((-1, 3, 0), (-1, 3, 0), (0, 0, 0)),
			((-30, 3, 0), (-2, 3, 0), (0, 0, 0)),
			((30, 3, 0), (0, 3, 0), (0, 0, 0)),
			]:
			p, N = cyl.closest_point_to(point)
			self.assertVector(p, closest)
			self.assertVector(N, normal)
示例#19
0
 def test_cyl_closest_pt_to(self):
     from lepton.domain import Cylinder
     from lepton.particle_struct import Vec3
     cyl = Cylinder((-2, 3, 0), (0, 3, 0), 3, 2)
     for point, closest, normal in [
         ((-1, 7, 0), (-1, 6, 0), (0, 1, 0)),
         ((-2, 3, -6), (-2, 3, -3), (0, 0, -1)),
         ((0, 6, 3), Vec3(0, 3, 0) + Vec3(0, 1, 1).normalize() * 3,
          Vec3(0, 1, 1).normalize()),
         ((-2.2, 5.5, 0), (-2, 5.5, 0), (-1, 0, 0)),
         ((-5, 10, 0), (-2, 6, 0), (-1, 0, 0)),
         ((-10, 3, 1), (-2, 3, 2), (-1, 0, 0)),
         ((0.5, 0, 0), (0, 0, 0), (1, 0, 0)),
         ((3, 5, 0), (0, 5, 0), (1, 0, 0)),
         ((20, 3, -0.1), (0, 3, -2), (1, 0, 0)),
             # points inside cylinder and along axis
         ((-0.5, 5.5, 0), (-0.5, 5.5, 0), (0, 0, 0)),
         ((-1, 3, 0), (-1, 3, 0), (0, 0, 0)),
         ((-30, 3, 0), (-2, 3, 0), (0, 0, 0)),
         ((30, 3, 0), (0, 3, 0), (0, 0, 0)),
     ]:
         p, N = cyl.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
示例#20
0
 def __init__(self, wpos):
     self.last_pos = wpos
     self.domain = Cylinder((*wpos, -10), (*wpos, 0), 5)
     self.emitter = StaticEmitter(rate=600,
                                  position=self.domain,
                                  template=Particle(
                                      color=(1.0, 1.0, 1.0, 0.3),
                                      size=(2.0, ) * 3,
                                      rotation=(0, 0, 1),
                                      velocity=(0, 0, 0),
                                  ),
                                  deviation=Particle(
                                      rotation=(0, 0, 0.5),
                                      angle=(0, 0, 6),
                                  ))
     self.group.bind_controller(self.emitter)
示例#21
0
    def test_cylinder_length(self):
        from lepton.domain import Cylinder
        cyl = Cylinder((0, 0, 0), (2, 0, 0), 1)
        self.assertEqual(cyl.length, 2)
        self.assertVector(cyl.end_point0, (0, 0, 0))
        self.assertVector(cyl.end_point1, (2, 0, 0))
        cyl = Cylinder((1, 0, -1), (3, 2, 1), 1)
        self.assertAlmostEqual(cyl.length, math.sqrt(12), 5)
        self.assertVector(cyl.end_point0, (1, 0, -1))
        self.assertVector(cyl.end_point1, (3, 2, 1))

        # Changing end points shoud adjust length
        cyl.end_point0 = (3, 0, -1)
        self.assertAlmostEqual(cyl.length, math.sqrt(8), 5)
        cyl.end_point1 = (5, 0, -1)
        self.assertAlmostEqual(cyl.length, 2, 5)