From d384fe52ac8dec5263fed96acbd511780d14b0d7 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 12 Jun 2015 22:27:47 +0200 Subject: [PATCH] Diagram.py: simplify draw_rect_from_center() by reusing draw_rect() --- Diagram.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Diagram.py b/Diagram.py index ff5a500..8cb41ad 100755 --- a/Diagram.py +++ b/Diagram.py @@ -161,30 +161,17 @@ class Diagram(object): stroke=False, stroke_color=[0, 0, 0, 0.5]): cr = self.cr + # 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)) - cr.save() - cr.translate(rx, ry) - cr.rotate(theta) - - if fill: - cr.rectangle(0, 0, width, height) - r, g, b, a = self.color_to_rgba(fill_color) - cr.set_source_rgba(r, g, b, a) - cr.fill() - - if stroke: - cr.rectangle(0, 0, width, height) - r, g, b, a = self.color_to_rgba(stroke_color) - cr.set_source_rgba(r, g, b, a) - cr.stroke() - self.draw_dot(0, 0, 3.0, stroke_color) - - cr.restore() + self.draw_rect(rx, ry, width, height, theta, fill, fill_color, stroke, + stroke_color) def draw_rect(self, x, y, width, height, theta=0, fill=True, fill_color=[1, 1, 1, 0.8], stroke=False, stroke_color=[0, 0, 0, 0.5]): -- 2.1.4