New primitive: Boxes.step()

Outset a line by a given margin - negative values for insetting
This commit is contained in:
Florian Festi 2020-02-03 16:59:19 +01:00
parent a0338a559f
commit 7c004e2d2c
2 changed files with 15 additions and 11 deletions

View File

@ -717,6 +717,20 @@ class Boxes:
self.ctx.line_to(length, 0)
self.ctx.translate(*self.ctx.get_current_point())
def step(self, out):
"""
Create a parallel step prependicular to the current direction
Positive values move to the outside of the part
"""
if out > 1E-5:
self.corner(-90)
self.edge(out)
self.corner(90)
elif out < -1E-5:
self.corner(90)
self.edge(-out)
self.corner(-90)
def curveTo(self, x1, y1, x2, y2, x3, y3):
"""control point 1, control point 2, end point

View File

@ -450,17 +450,7 @@ class CompoundEdge(BaseEdge):
lastwidth = self.types[0].startwidth()
for e, l in zip(self.types, self.lengths):
diff = e.startwidth() - lastwidth
if diff > 1E-5:
self.boxes.corner(-90)
self.boxes.edge(diff)
self.boxes.corner(90)
elif diff < -1E-5:
self.boxes.corner(90)
self.boxes.edge(-diff)
self.boxes.corner(-90)
self.step(e.startwidth() - lastwidth)
e(l)
lastwidth = e.endwidth()