diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-05-19 14:41:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-19 14:41:50 -0400 |
| commit | 9dadd836e2f09b0216f7b40c782e2b55bcc90dee (patch) | |
| tree | 128b6f13ea682a8e5a033370ab2e13388801f100 /lib/stitch_plan/ties.py | |
| parent | ba7288d8fcd62678bd17d8fab01d0d488d9e21e8 (diff) | |
| parent | 6fe417cd64090f028c0d07b799620eb94637bf33 (diff) | |
Merge pull request #163 from lexelby/lexelby-single-extension
single code entry point
Diffstat (limited to 'lib/stitch_plan/ties.py')
| -rw-r--r-- | lib/stitch_plan/ties.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/stitch_plan/ties.py b/lib/stitch_plan/ties.py new file mode 100644 index 00000000..f9c5b721 --- /dev/null +++ b/lib/stitch_plan/ties.py @@ -0,0 +1,53 @@ +from copy import deepcopy + +from .stitch import Stitch +from ..utils import cut_path +from ..stitches import running_stitch + + +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) |
