def test_generate_verts_with_angle(self): from grease.renderer import Vector from grease.geometry import Vec2d, Vec2dArray world = self.make_world() renderer = Vector() renderer.set_world(world) self.assertTrue(renderer.world is world) world.shapes = [ Data(closed=True, verts=Vec2dArray([(0,0), (0, 1), (1, 0)])), Data(closed=True, verts=Vec2dArray([(-2, -1), (2, -1), (2, 1), (-2, 1)])), Data(closed=False, verts=Vec2dArray([(1, -1), (-1, -1), (1, 1), (-1, 1)])), ] world.positions = [ Data(position=Vec2d(10, 10), angle=45), Data(position=Vec2d(4, 3), angle=90), Data(position=Vec2d(0, 0), angle=-45), ] v_array, i_size, i_array, i_count = renderer._generate_verts() self.assertEqual(i_count, 20) sin45 = math.sin(math.radians(45)) cos45 = math.cos(math.radians(45)) self.assertArrayEqual(self.get_verts(v_array[:3]), [(10, 10), (sin45+10, cos45+10), (cos45+10, -sin45+10)]) self.assertEqual(list(i_array[:6]), [0, 1, 1, 2, 2, 0]) self.assertArrayEqual(self.get_verts(v_array[3:7]), [(3, 5), (3, 1), (5, 1), (5, 5)]) self.assertEqual(list(i_array[6:14]), [3, 4, 4, 5, 5, 6, 6, 3]) self.assertArrayEqual(self.get_verts(v_array[7:11]), [(sqrt2, 0), (0, -sqrt2), (0, sqrt2), (-sqrt2, 0)]) self.assertEqual(list(i_array[14:20]), [7, 8, 8, 9, 9, 10]) self.assertEqual(self.get_rgba(v_array[:11]), [(255,255,255,255)] * 11)
def test_generate_verts_no_scale_or_angle(self): from grease.renderer import Vector world = self.make_world() renderer = Vector() renderer.set_world(world) v_array, i_size, i_array, i_count = renderer._generate_verts() self.assertEqual(i_count, 20) self.assertEqual(self.get_verts(v_array[:3]), [(10, 10), (10, 11), (10.5, 10.5)]) self.assertEqual(list(i_array[:6]), [0, 1, 1, 2, 2, 0]) self.assertEqual(self.get_verts(v_array[3:7]), [(3, 2), (5, 2), (5, 4), (3, 4)]) self.assertEqual(list(i_array[6:14]), [3, 4, 4, 5, 5, 6, 6, 3]) self.assertEqual(self.get_verts(v_array[7:11]), [(1, -1), (-1, -1), (1, 1), (-1, 1)]) self.assertEqual(list(i_array[14:20]), [7, 8, 8, 9, 9, 10]) self.assertEqual(self.get_rgba(v_array[:11]), [(255,255,255,255)] * 11)
def test_generate_verts_with_scale(self): from grease.renderer import Vector world = self.make_world() renderer = Vector(scale=10.0) renderer.set_world(world) self.assertTrue(renderer.world is world) v_array, i_size, i_array, i_count = renderer._generate_verts() self.assertEqual(i_count, 20) self.assertEqual(self.get_verts(v_array[:3]), [(10, 10), (10, 20), (15, 15)]) self.assertEqual(list(i_array[:6]), [0, 1, 1, 2, 2, 0]) self.assertEqual(self.get_verts(v_array[3:7]), [(-6, -7), (14, -7), (14, 13), (-6, 13)]) self.assertEqual(list(i_array[6:14]), [3, 4, 4, 5, 5, 6, 6, 3]) self.assertEqual(self.get_verts(v_array[7:11]), [(10, -10), (-10, -10), (10, 10), (-10, 10)]) self.assertEqual(list(i_array[14:20]), [7, 8, 8, 9, 9, 10]) self.assertEqual(self.get_rgba(v_array[:11]), [(255,255,255,255)] * 11)
def test_generate_verts_with_color(self): from grease.renderer import Vector from grease.color import RGBA world = self.make_world() world.renderable = [ Data(color=RGBA(1,0,0,1)), Data(color=RGBA(1,0,1,1)), Data(color=RGBA(0,0,1,1)), ] renderer = Vector() renderer.set_world(world) v_array, i_size, i_array, i_count = renderer._generate_verts() self.assertEqual(i_count, 20) self.assertEqual(self.get_verts(v_array[:3]), [(10, 10), (10, 11), (10.5, 10.5)]) self.assertEqual(self.get_rgba(v_array[:3]), [(255,0,0,255)] * 3) self.assertEqual(list(i_array[:6]), [0, 1, 1, 2, 2, 0]) self.assertEqual(self.get_verts(v_array[3:7]), [(3, 2), (5, 2), (5, 4), (3, 4)]) self.assertEqual(self.get_rgba(v_array[3:7]), [(255,0,255,255)] * 4) self.assertEqual(list(i_array[6:14]), [3, 4, 4, 5, 5, 6, 6, 3]) self.assertEqual(self.get_verts(v_array[7:11]), [(1, -1), (-1, -1), (1, 1), (-1, 1)]) self.assertEqual(self.get_rgba(v_array[7:11]), [(0,0,255,255)] * 4) self.assertEqual(list(i_array[14:20]), [7, 8, 8, 9, 9, 10])