summaryrefslogtreecommitdiff
path: root/lib/stitches/fill.py
diff options
context:
space:
mode:
authorAndreas <v.andreas.1@web.de>2021-11-10 17:23:24 +0100
committerKaalleen <reni@allenka.de>2022-05-04 18:59:08 +0200
commit3caaae693893354ff10472044116e623e219e633 (patch)
tree74ccd998e96426cdef662d355416197e11aba778 /lib/stitches/fill.py
parent1a1939b5daf421116791b5ae45434cb1aba2ea38 (diff)
bug fixing
Diffstat (limited to 'lib/stitches/fill.py')
-rw-r--r--lib/stitches/fill.py16
1 files changed, 14 insertions, 2 deletions
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)