Esempio n. 1
0
    def test_constructor_applies_offset(self):
        verts = [(-1, -2), (-3, +4), (+5, +6), (+7, -8)]
        offset = (5, 6)
        block = Block(gold, verts, offset)

        expected = offset_verts(verts, offset)
        self.assertEquals(block.verts, expected, "didnt apply offset")
Esempio n. 2
0
    def __init__(
        self, material, verts, offset=None, center=False):

        assert_valid(verts)
        self.verts = verts
        if center:
            self._centralize_verts()
        if offset is not None:
            self.verts = offset_verts(self.verts, offset)
        self.material = material
        self.mass = material.density * area(verts)
        self.shape = None
Esempio n. 3
0
    def test_add_to_body(self):
        space = Space()
        body = Body(10, 20)
        verts = [(-1, -1), (-1, +1), (+1, +1), (+1, -1)]
        offset = (1, 2)
        block = Block(gold, verts, offset)

        block.add_to_body(space, body)

        self.assertEquals(type(block.shape), Poly, "didnt create shape")
        self.assertEquals(block.shape.body, body, "didnt add shape to body")
        shapeVerts = block.shape.get_points()
        expected = [Vec2d(v) for v in offset_verts(verts, offset)]
        self.assertEquals(shapeVerts, expected, "bad shape verts")
        self.assertAlmostEquals(block.shape.friction, gold.friction,
            msg="bad shape friction")
        self.assertAlmostEquals(
            block.shape.elasticity, gold.elasticity,
            msg="bad shape elasticity")
        spaceShape = [s for s in space.shapes][0]
        self.assertEquals(block.shape, spaceShape,
            "didn't add shape to space")
Esempio n. 4
0
 def test_degenerate_cases(self):
     self.assertEquals(offset_verts([], (1, 1)), [], "bad for empty list")
     self.assertEquals(offset_verts((), (1, 1)), (), "bad for empty tuple")
Esempio n. 5
0
 def test_tuple_returns_tuple(self):
     verts = ((0, 1), (-2, -3), (4, 5))
     self.assertEquals(offset_verts(verts, (10, 20)), ((10, 21), (8, 17), (14, 25)), "bad offset tuple verts")
Esempio n. 6
0
 def test_offset_verts(self):
     verts = [(0, 1), (-2, -3), (4, 5)]
     self.assertEquals(offset_verts(verts, (10, 20)), [(10, 21), (8, 17), (14, 25)], "bad offset verts")
Esempio n. 7
0
 def offset(self, offset):
     self.verts = offset_verts(self.verts, offset)