Ejemplo n.º 1
0
    def test_assert_valid_too_few(self):
        self.assertRaises(lambda: assert_valid([]), TypeError, "need 3 or more verts: []")

        verts1 = [(0, 0)]
        self.assertRaises(lambda: assert_valid(verts1), TypeError, "need 3 or more verts: %s" % (verts1,))

        verts2 = [(0, 0), (0, 1)]
        self.assertRaises(lambda: assert_valid(verts2), TypeError, "need 3 or more verts: %s" % (verts2,))
Ejemplo n.º 2
0
 def __init__(self, verts):
     self.id = Room._nextRoomId
     Room._nextRoomId += 1
     assert_valid(verts)
     self.verts = None
     self._polygon = None
     self.material = granite
     self.neighbours = {}
     self.color = (0, 0, 64)
     self.polygon = Polygon(verts)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def test_assert_valid_counterclockwise(self):
        verts3cw = [(0, 1), (0, 0), (1, 0)]
        self.assertRaises(lambda: assert_valid(verts3cw), TypeError, "anticlockwise winding: %s" % (verts3cw,))

        verts4cw = [(0, 2), (0, 0), (2, 0), (2, 2)]
        self.assertRaises(lambda: assert_valid(verts4cw), TypeError, "anticlockwise winding: %s" % (verts4cw,))
Ejemplo n.º 5
0
 def test_assert_valid_nonconvex(self):
     verts4n = [(3, 0), (0, 0), (0, 3), (1, 1)]
     self.assertRaises(lambda: assert_valid(verts4n), TypeError, "not convex: %s" % (verts4n,))
Ejemplo n.º 6
0
 def test_assert_valid_colinear_are_ok(self):
     colinear = [(0, 0), (1, 1), (2, 2)]
     self.assertRaises(lambda: assert_valid(colinear), TypeError, "colinear: %s" % (colinear,))
Ejemplo n.º 7
0
    def test_assert_valid_ok(self):
        verts3 = [(0, 0), (0, 1), (1, 0)]
        assert_valid(verts3)

        verts4 = [(0, 0), (0, 2), (2, 2), (2, 0)]
        assert_valid(verts4)