コード例 #1
0
 def testInit(self):
     a = pyjet.BoundingBox2D()
     self.assertGreater(a.lowerCorner.x, a.upperCorner.x)
     self.assertGreater(a.lowerCorner.y, a.upperCorner.y)
     b = pyjet.BoundingBox2D((-1, -2), (4, 2))
     self.assertEqual(b.lowerCorner.x, -1.0)
     self.assertEqual(b.lowerCorner.y, -2.0)
     self.assertEqual(b.upperCorner.x, 4.0)
     self.assertEqual(b.upperCorner.y, 2.0)
     l, u = pyjet.Vector2D(-1, -2), pyjet.Vector2D(4, 2)
     c = pyjet.BoundingBox2D(l, u)
     self.assertEqual(c.lowerCorner.x, -1.0)
     self.assertEqual(c.lowerCorner.y, -2.0)
     self.assertEqual(c.upperCorner.x, 4.0)
     self.assertEqual(c.upperCorner.y, 2.0)
コード例 #2
0
def test_grid2():
    global cnt

    a = pyjet.CellCenteredScalarGrid2(resolution=(3, 4),
                                      gridSpacing=(1, 2),
                                      gridOrigin=(7, 5))

    assert a.resolution == (3, 4)
    assert_vector_similar(a.origin, (7, 5))
    assert_vector_similar(a.gridSpacing, (1, 2))
    assert_bounding_box_similar(
        a.boundingBox, pyjet.BoundingBox2D((7, 5), (10, 13)))
    f = a.cellCenterPosition
    assert_vector_similar(f(0, 0), (7.5, 6))

    b = pyjet.CellCenteredScalarGrid2(resolution=(3, 4),
                                      gridSpacing=(1, 2),
                                      gridOrigin=(7, 5))
    assert a.hasSameShape(b)

    def func(i, j):
        global cnt
        assert i >= 0 and i < 3
        assert j >= 0 and j < 4
        cnt += 1
    cnt = 0
    a.forEachCellIndex(func)
    assert cnt == 12
コード例 #3
0
def test_bounding_box2d_init():
    a = pyjet.BoundingBox2D()
    assert a.lowerCorner.x > a.upperCorner.x
    assert a.lowerCorner.y > a.upperCorner.y

    b = pyjet.BoundingBox2D((-1, -2), (4, 2))
    b.lowerCorner.x == -1.0
    b.lowerCorner.y == -2.0
    b.upperCorner.x == 4.0
    b.upperCorner.y == 2.0

    l, c = pyjet.Vector2D(-1, -2), pyjet.Vector2D(4, 2)
    c = pyjet.BoundingBox2D(l, c)
    c.lowerCorner.x == -1.0
    c.lowerCorner.y == -2.0
    c.upperCorner.x == 4.0
    c.upperCorner.y == 2.0
コード例 #4
0
def test_volume_particle_emitter2():
    sphere = pyjet.Sphere2()
    emitter = pyjet.VolumeParticleEmitter2(
        sphere, pyjet.BoundingBox2D((-1, -2), (4, 2)), 0.1, (-1, 0.5), (3, 4),
        5.0, 30, 0.01, False, True, 42)

    assert emitter.surface != None
    assert_bounding_box_similar(emitter.maxRegion,
                                pyjet.BoundingBox2D((-1, -2), (4, 2)))
    assert emitter.spacing == 0.1
    assert_vector_similar(emitter.initialVelocity, (-1, 0.5))
    assert_vector_similar(emitter.linearVelocity, (3, 4))
    assert emitter.angularVelocity == 5.0
    assert emitter.maxNumberOfParticles == 30
    assert emitter.jitter == 0.01
    assert emitter.isOneShot == False
    assert emitter.allowOverlapping == True

    emitter2 = pyjet.VolumeParticleEmitter2(implicitSurface=sphere,
                                            maxRegion=pyjet.BoundingBox2D(
                                                (-1, -2), (4, 2)),
                                            spacing=0.1,
                                            initialVelocity=(-1, 0.5),
                                            linearVelocity=(3, 4),
                                            angularVelocity=5.0,
                                            maxNumberOfParticles=30,
                                            jitter=0.01,
                                            isOneShot=False,
                                            allowOverlapping=True,
                                            seed=42)

    assert emitter2.surface != None
    assert_bounding_box_similar(emitter2.maxRegion,
                                pyjet.BoundingBox2D((-1, -2), (4, 2)))
    assert emitter2.spacing == 0.1
    assert_vector_similar(emitter2.initialVelocity, (-1, 0.5))
    assert_vector_similar(emitter2.linearVelocity, (3, 4))
    assert emitter2.angularVelocity == 5.0
    assert emitter2.maxNumberOfParticles == 30
    assert emitter2.jitter == 0.01
    assert emitter2.isOneShot == False
    assert emitter2.allowOverlapping == True
コード例 #5
0
 def testIsEmpty(self):
     a = pyjet.BoundingBox2D((-2.0, -2.0), (4.0, 3.0))
     self.assertFalse(a.isEmpty())
コード例 #6
0
def test_bounding_box2d_is_empty():
    a = pyjet.BoundingBox2D((-2.0, -2.0), (4.0, 3.0))
    assert not a.isEmpty()
コード例 #7
0
def test_volume_particle_emitter2():
    # Basic ctor test
    sphere = pyjet.Sphere2()
    emitter = pyjet.VolumeParticleEmitter2(
        sphere, pyjet.BoundingBox2D((-1, -2), (4, 2)), 0.1, (-1, 0.5), (3, 4),
        5.0, 30, 0.01, False, True, 42)

    assert emitter.surface
    assert_bounding_box_similar(emitter.maxRegion,
                                pyjet.BoundingBox2D((-1, -2), (4, 2)))
    assert emitter.spacing == 0.1
    assert_vector_similar(emitter.initialVelocity, (-1, 0.5))
    assert_vector_similar(emitter.linearVelocity, (3, 4))
    assert emitter.angularVelocity == 5.0
    assert emitter.maxNumberOfParticles == 30
    assert emitter.jitter == 0.01
    assert not emitter.isOneShot
    assert emitter.allowOverlapping
    assert emitter.isEnabled

    # Another basic ctor test
    emitter2 = pyjet.VolumeParticleEmitter2(implicitSurface=sphere,
                                            maxRegion=pyjet.BoundingBox2D(
                                                (-1, -2), (4, 2)),
                                            spacing=0.1,
                                            initialVelocity=(-1, 0.5),
                                            linearVelocity=(3, 4),
                                            angularVelocity=5.0,
                                            maxNumberOfParticles=3000,
                                            jitter=0.01,
                                            isOneShot=False,
                                            allowOverlapping=True,
                                            seed=42)

    assert emitter2.surface
    assert_bounding_box_similar(emitter2.maxRegion,
                                pyjet.BoundingBox2D((-1, -2), (4, 2)))
    assert emitter2.spacing == 0.1
    assert_vector_similar(emitter2.initialVelocity, (-1, 0.5))
    assert_vector_similar(emitter2.linearVelocity, (3, 4))
    assert emitter2.angularVelocity == 5.0
    assert emitter2.maxNumberOfParticles == 3000
    assert emitter2.jitter == 0.01
    assert not emitter2.isOneShot
    assert emitter2.allowOverlapping
    assert emitter2.isEnabled

    # Emit some particles
    frame = pyjet.Frame()
    solver = pyjet.ParticleSystemSolver2()
    solver.emitter = emitter2
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > 0

    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > old_num_particles

    # Disabling emitter should stop emitting particles
    emitter2.isEnabled = False
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles == old_num_particles

    # Re-enabling emitter should resume emission
    emitter2.isEnabled = True
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > old_num_particles

    # One-shot emitter
    emitter3 = pyjet.VolumeParticleEmitter2(implicitSurface=sphere,
                                            maxRegion=pyjet.BoundingBox2D(
                                                (-1, -2), (4, 2)),
                                            spacing=0.1,
                                            initialVelocity=(-1, 0.5),
                                            linearVelocity=(3, 4),
                                            angularVelocity=5.0,
                                            maxNumberOfParticles=3000,
                                            jitter=0.01,
                                            isOneShot=True,
                                            allowOverlapping=True,
                                            seed=42)

    # Emit some particles
    frame = pyjet.Frame()
    solver = pyjet.ParticleSystemSolver2()
    solver.emitter = emitter3
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > 0
    assert not emitter3.isEnabled

    # Should not emit more particles
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles == old_num_particles

    # Re-enabling the emitter should make it emit one more time
    emitter3.isEnabled = True
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles > old_num_particles

    # ...and gets disabled again
    old_num_particles = solver.particleSystemData.numberOfParticles
    solver.update(frame)
    frame.advance()
    assert solver.particleSystemData.numberOfParticles == old_num_particles