diff options
Diffstat (limited to 'lib/stitches')
| -rw-r--r-- | lib/stitches/auto_fill.py | 19 | ||||
| -rw-r--r-- | lib/stitches/fill.py | 3 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py index 3ff5a24f..fde3433a 100644 --- a/lib/stitches/auto_fill.py +++ b/lib/stitches/auto_fill.py @@ -19,6 +19,7 @@ from ..svg import PIXELS_PER_MM from ..utils.geometry import Point as InkstitchPoint, line_string_to_point_list, ensure_multi_line_string from .fill import intersect_region_with_grating, stitch_row from .running_stitch import running_stitch +from ..utils.threading import check_stop_flag class PathEdge(object): @@ -153,6 +154,8 @@ def build_fill_stitch_graph(shape, segments, starting_point=None, ending_point=N # mark this one as a grating segment. graph.add_edge(segment[0], segment[-1], key="segment", underpath_edges=[], geometry=shgeo.LineString(segment)) + check_stop_flag() + tag_nodes_with_outline_and_projection(graph, shape, graph.nodes()) add_edges_between_outline_nodes(graph, duplicate_every_other=True) @@ -196,6 +199,8 @@ def tag_nodes_with_outline_and_projection(graph, shape, nodes): graph.add_node(node, outline=outline_index, projection=outline_projection) + check_stop_flag() + def add_boundary_travel_nodes(graph, shape): outlines = ensure_multi_line_string(shape.boundary).geoms @@ -215,6 +220,8 @@ def add_boundary_travel_nodes(graph, shape): subpoint = segment.interpolate(i) graph.add_node((subpoint.x, subpoint.y), projection=outline.project(subpoint), outline=outline_index) + check_stop_flag() + graph.add_node((point.x, point.y), projection=outline.project(point), outline=outline_index) prev = point @@ -245,6 +252,8 @@ def add_edges_between_outline_nodes(graph, duplicate_every_other=False): if i % 2 == 0: graph.add_edge(node1, node2, key="extra", **data) + check_stop_flag() + def graph_is_valid(graph, shape, max_stitch_length): # The graph may be empty if the shape is so small that it fits between the @@ -382,6 +391,8 @@ def process_travel_edges(graph, fill_stitch_graph, shape, travel_edges): graph.add_edge(*edge, weight=weight) + check_stop_flag() + # without this, we sometimes get exceptions like this: # Exception AttributeError: "'NoneType' object has no attribute 'GEOSSTRtree_destroy'" in # <bound method STRtree.__del__ of <shapely.strtree.STRtree instance at 0x0D2BFD50>> ignored @@ -444,9 +455,13 @@ def build_travel_edges(shape, fill_angle): diagonal_edges = ensure_multi_line_string(grating1.symmetric_difference(grating2)) + check_stop_flag() + # without this, floating point inaccuracies prevent the intersection points from lining up perfectly. vertical_edges = ensure_multi_line_string(snap(grating3.difference(grating1), diagonal_edges, 0.005)) + check_stop_flag() + return endpoints, chain(diagonal_edges.geoms, vertical_edges.geoms) @@ -540,6 +555,8 @@ def find_stitch_path(graph, travel_graph, starting_point=None, ending_point=None real_end = nearest_node(outline_nodes, ending_point) path.append(PathEdge((ending_node, real_end), key="outline")) + check_stop_flag() + return path @@ -629,4 +646,6 @@ def path_to_stitches(path, travel_graph, fill_stitch_graph, angle, row_spacing, else: stitches.extend(travel(travel_graph, edge[0], edge[1], running_stitch_length, running_stitch_tolerance, skip_last)) + check_stop_flag() + return stitches diff --git a/lib/stitches/fill.py b/lib/stitches/fill.py index 11c9259b..b3bb0bb7 100644 --- a/lib/stitches/fill.py +++ b/lib/stitches/fill.py @@ -11,6 +11,7 @@ from ..stitch_plan import Stitch from ..svg import PIXELS_PER_MM from ..utils import Point as InkstitchPoint from ..utils import cache +from ..utils.threading import check_stop_flag def legacy_fill(shape, angle, row_spacing, end_row_spacing, max_stitch_length, flip, staggers, skip_last): @@ -169,6 +170,8 @@ def intersect_region_with_grating(shape, angle, row_spacing, end_row_spacing=Non else: current_row_y += row_spacing + check_stop_flag() + return rows |
