File: test_kwargs.py

package info (click to toggle)
python-box2d 2.3.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,596 kB
  • ctags: 5,116
  • sloc: python: 14,384; cpp: 13,393; makefile: 8; sh: 6
file content (69 lines) | stat: -rw-r--r-- 2,367 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from Box2D import *

class cl (b2ContactListener):
    pass

class test_kwargs (unittest.TestCase):
    def setUp(self):
        pass

    def test_kwargs(self):
        self.cont_list=cl()
        world = b2World(gravity=(0,-10), doSleep=True, contactListener=self.cont_list)
        groundBody = world.CreateBody(b2BodyDef(position=(0,-10)))

        groundBody.CreateFixturesFromShapes(b2PolygonShape(box=(50,10)))

        body = world.CreateBody(b2BodyDef(type=b2_dynamicBody, position=(0,4),
                        fixtures=[]))

        body = world.CreateBody(
                type=b2_dynamicBody,
                position=(0,4),
                fixtures=b2FixtureDef(shape=b2PolygonShape(box=(2,1)), density=1.0)
                )

        body = world.CreateBody(
                    type=b2_dynamicBody,
                    position=(0,4),
                    shapes=(b2PolygonShape(box=(2,1)), b2PolygonShape(box=(2,1))),
                    shapeFixture=b2FixtureDef(density=1.0),
                )

        body = world.CreateBody(
                    type=b2_dynamicBody,
                    position=(0,4),
                    fixtures=b2FixtureDef(shape=b2CircleShape(radius=1), density=1, friction=0.3),
                    shapes=(b2PolygonShape(box=(2,1)), b2PolygonShape(box=(2,1))),
                    shapeFixture=b2FixtureDef(density=1.0),
                )

        body.CreateFixture(shape=b2CircleShape(radius=1), density=1, friction=0.3)
        timeStep = 1.0 / 60
        vel_iters, pos_iters = 6, 2

        for i in range(60):
            world.Step(timeStep, vel_iters, pos_iters)
            world.ClearForces()

    def test_body(self):
        world = b2World(gravity=(0,-10), doSleep=True)
        body = world.CreateBody(b2BodyDef())
        body2 = world.CreateBody(position=(1,1))

    def test_joints(self):
        world = b2World(gravity=(0,-10), doSleep=True)
        body = world.CreateBody(b2BodyDef())
        body2 = world.CreateBody(position=(1,1))
        world.CreateJoint(type=b2RevoluteJoint, bodyA=body, bodyB=body2)
        world.CreateJoint(type=b2RevoluteJointDef, bodyA=body, bodyB=body2)

        kwargs=dict(type=b2RevoluteJointDef, bodyA=body, bodyB=body2)
        world.CreateJoint(**kwargs)

if __name__ == '__main__':
    unittest.main()