summaryrefslogtreecommitdiff
path: root/lib/stitches/auto_fill.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2019-03-18 20:57:05 -0400
committerLex Neva <github.com@lexneva.name>2019-03-18 20:57:05 -0400
commit2ba333c8a74245ee86b213809c734fcd7509c823 (patch)
tree8197b11a8d71a08edc2644d909e2c60e42988b5b /lib/stitches/auto_fill.py
parentec14fe7343e966286ce30ff329146feb3af4476b (diff)
avoid putting underpathing on top
Diffstat (limited to 'lib/stitches/auto_fill.py')
-rw-r--r--lib/stitches/auto_fill.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py
index f64f6f28..1eabfac9 100644
--- a/lib/stitches/auto_fill.py
+++ b/lib/stitches/auto_fill.py
@@ -59,7 +59,8 @@ def auto_fill(shape,
check_graph(fill_stitch_graph, shape, max_stitch_length)
travel_graph = build_travel_graph(fill_stitch_graph, shape, angle, underpath)
path = find_stitch_path(fill_stitch_graph, starting_point, ending_point)
- result = path_to_stitches(path, travel_graph, angle, row_spacing, max_stitch_length, running_stitch_length, staggers, skip_last)
+ result = path_to_stitches(path, travel_graph, fill_stitch_graph, angle, row_spacing,
+ max_stitch_length, running_stitch_length, staggers, skip_last)
return result
@@ -136,7 +137,7 @@ def build_fill_stitch_graph(shape, angle, row_spacing, end_row_spacing):
for segment in segments:
# networkx allows us to label nodes with arbitrary data. We'll
# mark this one as a grating segment.
- graph.add_edge(*segment, key="segment")
+ graph.add_edge(*segment, key="segment", underpath_edges=[])
tag_nodes_with_outline_and_projection(graph, shape, graph.nodes())
@@ -244,11 +245,21 @@ def build_travel_graph(fill_stitch_graph, shape, fill_stitch_angle, underpath):
graph.add_edge(start, end, weight=3 * p1.distance(p2))
if underpath:
+ segments = []
+ for start, end, key, data in fill_stitch_graph.edges(keys=True, data=True):
+ if key == 'segment':
+ segments.append((shgeo.LineString((start, end)), data))
+
interior_edges = grating1.symmetric_difference(grating2)
for ls in interior_edges.geoms:
p1, p2 = [InkstitchPoint(*coord) for coord in ls.coords]
+ edge = (p1.as_tuple(), p2.as_tuple())
+
+ for segment, data in segments:
+ if ls.crosses(segment):
+ data['underpath_edges'].append(edge)
- graph.add_edge(p1.as_tuple(), p2.as_tuple(), weight=p1.distance(p2))
+ graph.add_edge(*edge, weight=p1.distance(p2))
return graph
@@ -393,7 +404,7 @@ def travel(travel_graph, start, end, running_stitch_length):
return stitches[1:]
-def path_to_stitches(path, travel_graph, angle, row_spacing, max_stitch_length, running_stitch_length, staggers, skip_last):
+def path_to_stitches(path, travel_graph, fill_stitch_graph, angle, row_spacing, max_stitch_length, running_stitch_length, staggers, skip_last):
path = collapse_sequential_outline_edges(path)
stitches = []
@@ -401,6 +412,7 @@ def path_to_stitches(path, travel_graph, angle, row_spacing, max_stitch_length,
for edge in path:
if edge.is_segment():
stitch_row(stitches, edge[0], edge[1], angle, row_spacing, max_stitch_length, staggers, skip_last)
+ travel_graph.remove_edges_from(fill_stitch_graph[edge[0]][edge[1]]['segment'].get('underpath_edges', []))
else:
stitches.extend(travel(travel_graph, edge[0], edge[1], running_stitch_length))