Merge pull request #188 from lexelby/lexelby-fix-empty-subpath

fix empty subpath
pull/196/head
Lex Neva 2018-06-07 20:15:19 -04:00 zatwierdzone przez GitHub
commit dbaf923efd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 45 dodań i 47 usunięć

Wyświetl plik

@ -29,6 +29,10 @@ class Patch:
else: else:
raise TypeError("Patch can only be added to another Patch") raise TypeError("Patch can only be added to another Patch")
def __len__(self):
# This method allows `len(patch)` and `if patch:
return len(self.stitches)
def add_stitch(self, stitch): def add_stitch(self, stitch):
self.stitches.append(stitch) self.stitches.append(stitch)
@ -36,7 +40,6 @@ class Patch:
return Patch(self.color, self.stitches[::-1]) return Patch(self.color, self.stitches[::-1])
class Param(object): class Param(object):
def __init__(self, name, description, unit=None, values=[], type=None, group=None, inverse=False, default=None, tooltip=None, sort_index=0): def __init__(self, name, description, unit=None, values=[], type=None, group=None, inverse=False, default=None, tooltip=None, sort_index=0):
self.name = name self.name = name

Wyświetl plik

@ -3,7 +3,7 @@ import sys
from .element import param, EmbroideryElement, Patch from .element import param, EmbroideryElement, Patch
from ..i18n import _ from ..i18n import _
from ..utils import cache, Point from ..utils import cache, Point
from ..stitches import running_stitch
warned_about_legacy_running_stitch = False warned_about_legacy_running_stitch = False
@ -93,57 +93,51 @@ class Stroke(EmbroideryElement):
else: else:
return False return False
def stroke_points(self, emb_point_list, zigzag_spacing, stroke_width): def simple_satin(self, path, zigzag_spacing, stroke_width):
# TODO: use inkstitch.stitches.running_stitch "zig-zag along the path at the specified spacing and wdith"
patch = Patch(color=self.color) # `self.zigzag_spacing` is the length for a zig and a zag
p0 = emb_point_list[0] # together (a V shape). Start with running stitch at half
rho = 0.0 # that length:
side = 1 patch = self.running_stitch(path, zigzag_spacing / 2.0)
last_segment_direction = None
for repeat in xrange(self.repeats): # Now move the points left and right. Consider each pair
if repeat % 2 == 0: # of points in turn, and move perpendicular to them,
order = range(1, len(emb_point_list)) # alternating left and right.
else:
order = range(-2, -len(emb_point_list) - 1, -1)
for segi in order: offset = stroke_width / 2.0
p1 = emb_point_list[segi]
# how far we have to go along segment for i in xrange(len(patch) - 1):
seg_len = (p1 - p0).length() start = patch.stitches[i]
if (seg_len == 0): end = patch.stitches[i + 1]
continue segment_direction = (end - start).unit()
zigzag_direction = segment_direction.rotate_left()
# vector pointing along segment if i % 2 == 1:
along = (p1 - p0).unit() zigzag_direction *= -1
# vector pointing to edge of stroke width patch.stitches[i] += zigzag_direction * offset
perp = along.rotate_left() * (stroke_width * 0.5)
if stroke_width == 0.0 and last_segment_direction is not None:
if abs(1.0 - along * last_segment_direction) > 0.5:
# if greater than 45 degree angle, stitch the corner
rho = zigzag_spacing
patch.add_stitch(p0)
# iteration variable: how far we are along segment
while (rho <= seg_len):
left_pt = p0 + along * rho + perp * side
patch.add_stitch(left_pt)
rho += zigzag_spacing
side = -side
p0 = p1
last_segment_direction = along
rho -= seg_len
if (p0 - patch.stitches[-1]).length() > 0.1:
patch.add_stitch(p0)
return patch return patch
def running_stitch(self, path, stitch_length):
repeated_path = []
# go back and forth along the path as specified by self.repeats
for i in xrange(self.repeats):
if i % 2 == 1:
# reverse every other pass
this_path = path[::-1]
else:
this_path = path[:]
repeated_path.extend(this_path)
stitches = running_stitch(repeated_path, stitch_length)
return Patch(self.color, stitches)
def to_patches(self, last_patch): def to_patches(self, last_patch):
patches = [] patches = []
@ -152,10 +146,11 @@ class Stroke(EmbroideryElement):
if self.manual_stitch_mode: if self.manual_stitch_mode:
patch = Patch(color=self.color, stitches=path, stitch_as_is=True) patch = Patch(color=self.color, stitches=path, stitch_as_is=True)
elif self.is_running_stitch(): elif self.is_running_stitch():
patch = self.stroke_points(path, self.running_stitch_length, stroke_width=0.0) patch = self.running_stitch(path, self.running_stitch_length)
else: else:
patch = self.stroke_points(path, self.zigzag_spacing / 2.0, stroke_width=self.stroke_width) patch = self.simple_satin(path, self.zigzag_spacing, self.stroke_width)
patches.append(patch) if patch:
patches.append(patch)
return patches return patches