diagram: move draw_rect_from_center to the generic Diagram class
authorAntonio Ospite <ao2@ao2.it>
Tue, 26 Jun 2018 13:42:26 +0000 (15:42 +0200)
committerAntonio Ospite <ao2@ao2.it>
Wed, 27 Jun 2018 13:16:35 +0000 (15:16 +0200)
Move draw_rect_from_center from cairo_diagram.py to diagram.py as it
does not depend on any specific backend.

src/diagram/cairo_diagram.py
src/diagram/diagram.py

index 9aab30e..fd632d7 100755 (executable)
@@ -143,20 +143,6 @@ class CairoDiagram(Diagram):
         cr.line_to(x2, y2)
         self._stroke(stroke_color)
 
         cr.line_to(x2, y2)
         self._stroke(stroke_color)
 
-    def draw_rect_from_center(self, cx, cy, width, height, theta=0.0,
-                              stroke_color=None,
-                              fill_color=(1, 1, 1, 0.8)):
-        # the position of the center of a rectangle at (0,0)
-        mx = width / 2.0
-        my = height / 2.0
-
-        # calculate the position of the bottom-left corner after rotating the
-        # rectangle around the center
-        rx = cx - (mx * cos(theta) - my * sin(theta))
-        ry = cy - (mx * sin(theta) + my * cos(theta))
-
-        self.draw_rect(rx, ry, width, height, theta, stroke_color, fill_color)
-
     def draw_rect(self, x, y, width, height, theta=0,
                   stroke_color=None,
                   fill_color=(1, 1, 1, 0.8)):
     def draw_rect(self, x, y, width, height, theta=0,
                   stroke_color=None,
                   fill_color=(1, 1, 1, 0.8)):
index eee9fc6..a949577 100755 (executable)
@@ -86,3 +86,22 @@ class Diagram(object):
         apothem_angle = theta + pi / sides
 
         return self.draw_star(cx, cy, sides, apothem, apothem_angle, stroke_color)
         apothem_angle = theta + pi / sides
 
         return self.draw_star(cx, cy, sides, apothem, apothem_angle, stroke_color)
+
+    def draw_rect(self, x, y, width, height, theta=0,
+                  stroke_color=None,
+                  fill_color=(1, 1, 1, 0.8)):
+        raise NotImplementedError
+
+    def draw_rect_from_center(self, cx, cy, width, height, theta=0.0,
+                              stroke_color=None,
+                              fill_color=(1, 1, 1, 0.8)):
+        # the position of the center of a rectangle at (0,0)
+        mx = width / 2.0
+        my = height / 2.0
+
+        # calculate the position of the bottom-left corner after rotating the
+        # rectangle around the center
+        rx = cx - (mx * cos(theta) - my * sin(theta))
+        ry = cy - (mx * sin(theta) + my * cos(theta))
+
+        self.draw_rect(rx, ry, width, height, theta, stroke_color, fill_color)