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,))
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)
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
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,))
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,))
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,))
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)