From 5678df7dbbc04460f3fb23d37990ba34ae7af429 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 1 Apr 2011 09:59:44 -0400 Subject: [PATCH] add accessor methods in shapes to get vars --- Circle.py | 6 ++++++ Line.py | 6 ++++++ SketchWidget.py | 15 +++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Circle.py b/Circle.py index fecb6df..a606c4f 100644 --- a/Circle.py +++ b/Circle.py @@ -22,3 +22,9 @@ class Circle(Shape): return ([1, 0, -1], [0, 1, 0]) elif ptNum == 4: return ([1, 0, 0], [0, 1, -1]) + + def getCenter(self): + return (self.vars[0], self.vars[1]) + + def getRadius(self): + return self.vars[2] diff --git a/Line.py b/Line.py index d46033b..179102a 100644 --- a/Line.py +++ b/Line.py @@ -18,3 +18,9 @@ class Line(Shape): return ([0, 0, 1, 0], [0, 0, 0, 1]) elif ptNum == 2: return ([0.5, 0, 0.5, 0], [0, 0.5, 0, 0.5]) + + def getPt(self, ptNum): + if ptNum == 0: + return (self.vars[0], self.vars[1]) + elif ptNum == 1: + return (self.vars[2], self.vars[3]) diff --git a/SketchWidget.py b/SketchWidget.py index 91a43ef..cd711e7 100644 --- a/SketchWidget.py +++ b/SketchWidget.py @@ -89,19 +89,22 @@ class SketchWidget: return True def drawLine(self, shape, size): - self.drawFilledLine(shape.vars[0], shape.vars[1], - shape.vars[2], shape.vars[3], size) + pt0 = shape.getPt(0) + pt1 = shape.getPt(1) + self.drawFilledLine(pt0[0], pt0[1], pt1[0], pt1[1], size) def drawCircle(self, shape, size): steps = 16 step = 2 * math.pi / steps + center = shape.getCenter() + rad = shape.getRadius() for i in range(steps + 1): angle = i * step next_angle = (i + 1) * step - x0 = shape.vars[0] + shape.vars[2] * math.cos(angle) - y0 = shape.vars[1] + shape.vars[2] * math.sin(angle) - x1 = shape.vars[0] + shape.vars[2] * math.cos(next_angle) - y1 = shape.vars[1] + shape.vars[2] * math.sin(next_angle) + x0 = center[0] + rad * math.cos(angle) + y0 = center[1] + rad * math.sin(angle) + x1 = center[0] + rad * math.cos(next_angle) + y1 = center[1] + rad * math.sin(next_angle) self.drawFilledLineUncapped(x0, y0, x1, y1, size) self.drawFilledCircle(x0, y0, size, 8)