diff options
| -rw-r--r-- | lib/elements/auto_fill.py | 3 | ||||
| -rw-r--r-- | lib/patterns.py | 4 | ||||
| -rw-r--r-- | lib/stitches/fill.py | 16 |
3 files changed, 18 insertions, 5 deletions
diff --git a/lib/elements/auto_fill.py b/lib/elements/auto_fill.py index 81abf7ad..094ad91e 100644 --- a/lib/elements/auto_fill.py +++ b/lib/elements/auto_fill.py @@ -456,7 +456,8 @@ class AutoFill(EmbroideryElement): stitches=path) stitch_groups.append(stitch_group) elif self.fill_method == 2: # Guided Auto Fill - lines = get_patterns(self.node, "#inkstitch-guide-line-marker") + lines = get_patterns( + self.node, "#inkstitch-guide-line-marker", False, True) lines = lines['stroke_patterns'] if not lines or lines[0].is_empty: inkex.errormsg( diff --git a/lib/patterns.py b/lib/patterns.py index 789d5f89..7ec4d082 100644 --- a/lib/patterns.py +++ b/lib/patterns.py @@ -65,7 +65,7 @@ def _apply_fill_patterns(patterns, patches): patch.stitches = patch_points -def get_patterns(node, marker_id): +def get_patterns(node, marker_id, get_fills=True, get_strokes=True): from .elements import EmbroideryElement from .elements.auto_fill import auto_fill from .elements.stroke import Stroke @@ -88,7 +88,7 @@ def get_patterns(node, marker_id): for ring in linear_rings: fills.append(shgeo.Polygon(ring)) - if stroke is not None: + if get_strokes and stroke is not None: stroke_pattern = Stroke(pattern).paths line_strings = [shgeo.LineString(path) for path in stroke_pattern] strokes.append(shgeo.MultiLineString(line_strings)) diff --git a/lib/stitches/fill.py b/lib/stitches/fill.py index 9a7254e2..55ce09a4 100644 --- a/lib/stitches/fill.py +++ b/lib/stitches/fill.py @@ -7,6 +7,7 @@ import math import shapely from shapely.geometry.linestring import LineString +from shapely.ops import linemerge from ..svg import PIXELS_PER_MM from ..utils import Point as InkstitchPoint from ..utils import cache @@ -108,7 +109,7 @@ def extend_line(line, minx, maxx, miny, maxy): point4 = InkstitchPoint(*line.coords[-1]) new_ending_point = point4+(point4-point3).unit()*length - line = LineString([new_starting_point.as_tuple()] + + return LineString([new_starting_point.as_tuple()] + line.coords[1:-1]+[new_ending_point.as_tuple()]) @@ -119,7 +120,7 @@ def intersect_region_with_grating_line(shape, line, row_spacing, end_row_spacing upper_left = InkstitchPoint(minx, miny) rows = [] # extend the line towards the ends to increase probability that all offsetted curves cross the shape - extend_line(line, minx, maxx, miny, maxy) + line = extend_line(line, minx, maxx, miny, maxy) line_offsetted = line res = line_offsetted.intersection(shape) @@ -141,6 +142,17 @@ def intersect_region_with_grating_line(shape, line, row_spacing, end_row_spacing else: rows.insert(0, runs) line_offsetted = line_offsetted.parallel_offset(row_spacing, 'left', 5) + if line_offsetted.geom_type == 'MultiLineString': # if we got multiple lines take the longest + lines = linemerge(line_offsetted) + lines = list(line_offsetted.geoms) + max_length = -1 + max_length_idx = -1 + for idx, subline in enumerate(lines): + if subline.length > max_length: + max_length = subline.length + max_length_idx = idx + line_offsetted = lines[max_length_idx] + if row_spacing < 0: line_offsetted.coords = line_offsetted.coords[::-1] line_offsetted = line_offsetted.simplify(0.01, False) |
