diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-06-30 19:22:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-30 19:22:33 +0200 |
| commit | 8d5ef5b6635b5b84f12409b535114853954680d1 (patch) | |
| tree | c963bf0e1ddc4ee584c08b4014232f0f067ae512 /lib/stitches/ripple_stitch.py | |
| parent | 725281f075f8d40a68427733f377983b6f7c607b (diff) | |
Fixes (#1703)
* guide line position
* use direction from line to shape
* optimize intersection detection
* fix flapack elf
* handle weird guide lines better
* update starting point for self crossing (multiple) fills
* ripple: fixes and non circular join style
* avoid jumps in ripple stitch
* fallback only necessary if shape does not intersect grating
* make valid may return a polygon
* add profiling
* Stitch.__init__ didn't work right and was super slow
* shrink or grow to multipolygon
Co-authored-by: Lex Neva
Diffstat (limited to 'lib/stitches/ripple_stitch.py')
| -rw-r--r-- | lib/stitches/ripple_stitch.py | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/lib/stitches/ripple_stitch.py b/lib/stitches/ripple_stitch.py index 489666b0..6a0ef7f0 100644 --- a/lib/stitches/ripple_stitch.py +++ b/lib/stitches/ripple_stitch.py @@ -63,6 +63,8 @@ def _get_helper_lines(stroke): if stroke.is_closed: return False, _get_circular_ripple_helper_lines(stroke, outline) + elif stroke.join_style == 1: + return True, _get_point_style_linear_helper_lines(stroke, outline) else: return True, _get_linear_ripple_helper_lines(stroke, outline) @@ -74,7 +76,7 @@ def _get_satin_ripple_helper_lines(stroke): # use satin column points for satin like build ripple stitches rail_points = SatinColumn(stroke.node).plot_points_on_rails(length, 0) - steps = _get_steps(stroke.line_count, exponent=stroke.exponent, flip=stroke.flip_exponent) + steps = _get_steps(stroke.get_line_count(), exponent=stroke.exponent, flip=stroke.flip_exponent) helper_lines = [] for point0, point1 in zip(*rail_points): @@ -83,24 +85,39 @@ def _get_satin_ripple_helper_lines(stroke): for step in steps: helper_lines[-1].append(InkstitchPoint.from_shapely_point(helper_line.interpolate(step, normalized=True))) - return helper_lines + if stroke.join_style == 1: + helper_lines = _converge_helper_line_points(helper_lines, True) + return helper_lines -def _get_circular_ripple_helper_lines(stroke, outline): - helper_lines = _get_linear_ripple_helper_lines(stroke, outline) - # Now we want to adjust the helper lines to make a spiral. +def _converge_helper_line_points(helper_lines, point_edge=False): num_lines = len(helper_lines) steps = _get_steps(num_lines) for i, line in enumerate(helper_lines): points = [] for j in range(len(line) - 1): - points.append(line[j] * (1 - steps[i]) + line[j + 1] * steps[i]) + if point_edge and j % 2 == 1: + k = num_lines - 1 - i + points.append(line[j] * (1 - steps[k]) + line[j + 1] * steps[k]) + else: + points.append(line[j] * (1 - steps[i]) + line[j + 1] * steps[i]) helper_lines[i] = points return helper_lines +def _get_circular_ripple_helper_lines(stroke, outline): + helper_lines = _get_linear_ripple_helper_lines(stroke, outline) + # Now we want to adjust the helper lines to make a spiral. + return _converge_helper_line_points(helper_lines) + + +def _get_point_style_linear_helper_lines(stroke, outline): + helper_lines = _get_linear_ripple_helper_lines(stroke, outline) + return _converge_helper_line_points(helper_lines, True) + + def _get_linear_ripple_helper_lines(stroke, outline): guide_line = stroke.get_guide_line() max_dist = stroke.grid_size or stroke.running_stitch_length @@ -124,10 +141,25 @@ def _target_point_helper_lines(stroke, outline): return helper_lines +def _adjust_helper_lines_for_grid(stroke, helper_lines): + num_lines = stroke.line_count - stroke.skip_end + if stroke.reverse: + helper_lines = [helper_line[::-1] for helper_line in helper_lines] + num_lines = stroke.skip_start + if (num_lines % 2 != 0 and not stroke.is_closed) or (stroke.is_closed and not stroke.reverse): + helper_lines.reverse() + + return helper_lines + + def _do_grid(stroke, helper_lines): + helper_lines = _adjust_helper_lines_for_grid(stroke, helper_lines) + start = stroke.get_skip_start() + skip_end = stroke.get_skip_end() + if stroke.reverse: + start, skip_end = skip_end, start for i, helper in enumerate(helper_lines): - start = stroke.get_skip_start() - end = len(helper) - stroke.get_skip_end() + end = len(helper) - skip_end points = helper[start:end] if i % 2 == 0: points.reverse() @@ -146,7 +178,7 @@ def _get_guided_helper_lines(stroke, outline, max_distance): def _generate_guided_helper_lines(stroke, outline, max_distance, guide_line): - # helper lines are generated by making copies of the outline alog the guide line + # helper lines are generated by making copies of the outline along the guide line line_point_dict = defaultdict(list) outline = LineString(running_stitch(line_string_to_point_list(outline), max_distance, stroke.running_stitch_tolerance)) |
