Exemple #1
0
 def test_90_degree_rotation(self):
     point = (1, 0)
     degrees = 90
     expected = (0, 1)
     result = math_utils.rotate_point(point, degrees)
     self.assertAlmostEqual(expected[0], result[0], places=10)
     self.assertAlmostEqual(expected[1], result[1], places=10)
Exemple #2
0
 def test_45_degree_rotation(self):
     point = (1, 0)
     degrees = 45
     expected = (math.sqrt(2) / 2, math.sqrt(2) / 2)
     result = math_utils.rotate_point(point, degrees)
     self.assertAlmostEqual(expected[0], result[0], places=10)
     self.assertAlmostEqual(expected[1], result[1], places=10)
Exemple #3
0
 def test_0_degree_rotation_around_point(self):
     point = (5, 3)
     center_point = (3, 3)
     degrees = 0
     expected = (5, 3)
     result = math_utils.rotate_point(point, degrees, center_point)
     self.assertAlmostEqual(expected[0], result[0], places=10)
     self.assertAlmostEqual(expected[1], result[1], places=10)
Exemple #4
0
    def rotate(self, degrees):
        coords = []
        center_point = (self.center.x, self.center.y)
        old_p1 = (self.p1.x, self.p1.y)
        old_p2 = (self.p2.x, self.p2.y)
        new_p1 = math_utils.rotate_point(old_p1, degrees, center_point)
        new_p2 = math_utils.rotate_point(old_p2, degrees, center_point)
        self.p1 = Point(new_p1[0], new_p1[1])
        self.p2 = Point(new_p2[0], new_p2[1])

        # need to convert to screen coordinates when rendering to screen
        screen_p1_x, screen_p1_y = self.canvas.toScreen(new_p1[0], new_p1[1])
        screen_p2_x, screen_p2_y = self.canvas.toScreen(new_p2[0], new_p2[1])
        coords = [screen_p1_x, screen_p1_y, screen_p2_x, screen_p2_y]
        try:
            self.canvas.coords(self.id, coords)
        except tk.TclError:
            sys.exit()
Exemple #5
0
 def rotate(self, degrees):
     center_point = (self.center.x, self.center.y)
     self.points = [
         math_utils.rotate_point(point, degrees, center_point)
         for point in self.points
     ]
     screen_point_tuples = [
         self.canvas.toScreen(point[0], point[1]) for point in self.points
     ]
     coords = list(itertools.chain.from_iterable(screen_point_tuples))
     self.canvas.coords(self.id, coords)