From 1b31806423c8fec4040fed6d1009db016860b763 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 1 May 2018 20:37:51 -0400 Subject: rename inkstitch/ to lib/ You can't have a module and a package named the same thing. PyInstaller wants to import the main script as if it were a module, and this doesn't work unless there's no directory of the same name with a __init__.py in it. --- lib/stitch_plan/ties.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lib/stitch_plan/ties.py (limited to 'lib/stitch_plan/ties.py') diff --git a/lib/stitch_plan/ties.py b/lib/stitch_plan/ties.py new file mode 100644 index 00000000..1207ea51 --- /dev/null +++ b/lib/stitch_plan/ties.py @@ -0,0 +1,51 @@ +from ..utils import cut_path +from ..stitches import running_stitch +from .. import Stitch +from copy import deepcopy + +def add_tie(stitches, tie_path): + if stitches[-1].no_ties: + # It's from a manual stitch block, so don't add tie stitches. The user + # will add them if they want them. + return + + tie_path = cut_path(tie_path, 0.6) + tie_stitches = running_stitch(tie_path, 0.3) + tie_stitches = [Stitch(stitch.x, stitch.y) for stitch in tie_stitches] + + stitches.extend(deepcopy(tie_stitches[1:])) + stitches.extend(deepcopy(list(reversed(tie_stitches))[1:])) + + +def add_tie_off(stitches): + add_tie(stitches, list(reversed(stitches))) + + +def add_tie_in(stitches, upcoming_stitches): + add_tie(stitches, upcoming_stitches) + + +def add_ties(stitch_plan): + """Add tie-off before and after trims, jumps, and color changes.""" + + for color_block in stitch_plan: + need_tie_in = True + new_stitches = [] + for i, stitch in enumerate(color_block.stitches): + is_special = stitch.trim or stitch.jump or stitch.stop + + if is_special and not need_tie_in: + add_tie_off(new_stitches) + new_stitches.append(stitch) + need_tie_in = True + elif need_tie_in and not is_special: + new_stitches.append(stitch) + add_tie_in(new_stitches, upcoming_stitches=color_block.stitches[i:]) + need_tie_in = False + else: + new_stitches.append(stitch) + + if not need_tie_in: + add_tie_off(new_stitches) + + color_block.replace_stitches(new_stitches) -- cgit v1.2.3 From 05daffb7e01db55879eb24f3c00532324a5d41af Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 1 May 2018 21:21:07 -0400 Subject: refactor everything out of lib/__init__.py --- lib/stitch_plan/ties.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/stitch_plan/ties.py') diff --git a/lib/stitch_plan/ties.py b/lib/stitch_plan/ties.py index 1207ea51..f9c5b721 100644 --- a/lib/stitch_plan/ties.py +++ b/lib/stitch_plan/ties.py @@ -1,7 +1,9 @@ +from copy import deepcopy + +from .stitch import Stitch from ..utils import cut_path from ..stitches import running_stitch -from .. import Stitch -from copy import deepcopy + def add_tie(stitches, tie_path): if stitches[-1].no_ties: -- cgit v1.2.3