# # Path representation # # Just a guy made of arcs and lines # # TODO: # handedness rule # intersections # (both needed to handle kerf calculations properly) from math import * class Path: class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def clone(self): c=Path.Point(self.x,self.y) return c def rotate(self, origin, theta): xoff = self.x - origin.x yoff = self.y - origin.y c = cos(theta) s = sin(theta) self.x = origin.x + cos(theta)*xoff - sin(theta)*yoff self.y = origin.y + sin(theta)*xoff + cos(theta)*yoff class Polar(Point): def __init__(self, radius, theta): Path.Point.__init__(self,radius*cos(theta),radius*sin(theta)) class Line: def __init__(self, a, b): self.a = a.clone() self.b = b.clone() def rotate(self,origin,theta): self.b.rotate(origin,theta) self.a.rotate(origin,theta) class Arc: def __init__(self, where, radius, start, end): self.where = where.clone() self.radius = radius self.start = start self.end = end def getEndpoint(self): return Path.Polar(self.radius,self.end) def rotate(self,origin,theta): self.where.rotate(origin,theta) self.start=self.start+theta self.end=self.end+theta def __init__(self): self.segments=[] self.last=None def startAt(self, point): self.last = point def lineTo(self, point): self.appendLine(Path.Line(self.last,point)) def appendLine(self, line): self.segments.append(line) self.last = line.b def appendArc(self, arc): self.segments.append(arc) self.last = arc.getEndpoint() def rotate(self,origin,theta): for segment in self.segments: segment.rotate(origin,theta)