diff options
| author | Stefan Siegl <stesie@brokenpipe.de> | 2014-12-29 22:38:22 +0100 |
|---|---|---|
| committer | Stefan Siegl <stesie@brokenpipe.de> | 2014-12-29 22:38:22 +0100 |
| commit | 35e5c09c99269615207242cf67409b8cc4c88d2a (patch) | |
| tree | 392a44f5a9469aff76d0a77836d0093af54deef4 /embroider.py | |
| parent | 0c1cfae0b7858dce5a271a5c8e0eeefc81ba6fb4 (diff) | |
Allow to collapse (jump) stitches
Diffstat (limited to 'embroider.py')
| -rw-r--r-- | embroider.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/embroider.py b/embroider.py index 435f3167..d92f733a 100644 --- a/embroider.py +++ b/embroider.py @@ -328,11 +328,21 @@ class EmbroideryObject: self.patchList = patchList self.row_spacing_px = row_spacing_px - def emit_file(self, filename, output_format): + def emit_file(self, filename, output_format, collapse_len_px): emb = PyEmb.Embroidery() + lastStitch = None + lastColor = None for patch in self.patchList.patches: jumpStitch = True for stitch in patch.stitches: + if jumpStitch and lastStitch and lastColor == patch.color: + # consider collapsing jump stich, if it is pretty short + c = math.sqrt((stitch.x - lastStitch.x) ** 2 + (stitch.y + lastStitch.y) ** 2) + dbg.write("jump stitch length: %f (%d/%d -> %d/%d)\n" % (c, lastStitch.x, lastStitch.y, stitch.x, stitch.y)) + if c < collapse_len_px: + dbg.write("... collapsed\n") + jumpStitch = False + dbg.write("stitch color %s\n" % patch.color) newStitch = PyEmb.Point(stitch.x, -stitch.y) @@ -341,6 +351,8 @@ class EmbroideryObject: emb.addStitch(newStitch) jumpStitch = False + lastStitch = newStitch + lastColor = patch.color emb.translate_to_origin() emb.scale(10.0/pixels_per_millimeter) @@ -423,6 +435,10 @@ class Embroider(inkex.Effect): action="store", type="float", dest="max_stitch_len_mm", default=3.0, help="max stitch length (mm)") + self.OptionParser.add_option("-c", "--collapse_len_mm", + action="store", type="float", + dest="collapse_len_mm", default=0.0, + help="max collapse length (mm)") self.OptionParser.add_option("-f", "--flatness", action="store", type="float", dest="flat", default=0.1, @@ -594,7 +610,8 @@ class Embroider(inkex.Effect): def effect(self): self.row_spacing_px = self.options.row_spacing_mm * pixels_per_millimeter - self.max_stitch_len_px = self.options.max_stitch_len_mm*pixels_per_millimeter + self.max_stitch_len_px = self.options.max_stitch_len_mm*pixels_per_millimeter + self.collapse_len_px = self.options.collapse_len_mm*pixels_per_millimeter self.svgpath = inkex.addNS('path', 'svg') self.patchList = PatchList([]) @@ -605,7 +622,7 @@ class Embroider(inkex.Effect): dbg.write("patch count: %d\n" % len(self.patchList.patches)) eo = EmbroideryObject(self.patchList, self.row_spacing_px) - eo.emit_file(self.options.filename, self.options.output_format) + eo.emit_file(self.options.filename, self.options.output_format, self.collapse_len_px) new_group = inkex.etree.SubElement(self.current_layer, inkex.addNS('g', 'svg'), {}) |
