diff options
| author | Lex Neva <github.com@lexneva.name> | 2019-03-20 22:43:36 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2019-03-21 21:09:03 -0400 |
| commit | 90fe0451695dafc8fff2272b122c9112dd205bd6 (patch) | |
| tree | 4635486a5345ee8cc156f2e0a8cbe0b3f104cfe9 | |
| parent | 97ced89e8793ff608588324304e53427d180ee1e (diff) | |
don't try to end inside the shape
| -rw-r--r-- | lib/stitches/auto_fill.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py index a7ac49e7..e9c9b9e5 100644 --- a/lib/stitches/auto_fill.py +++ b/lib/stitches/auto_fill.py @@ -283,9 +283,9 @@ def check_graph(graph, shape, max_stitch_length): "This most often happens because your shape is made up of multiple sections that aren't connected.")) -def nearest_node(graph, point): +def nearest_node(nodes, point, attr=None): point = shgeo.Point(*point) - nearest = min(graph.nodes, key=lambda node: shgeo.Point(*node).distance(point)) + nearest = min(nodes, key=lambda node: shgeo.Point(*node).distance(point)) return nearest @@ -363,7 +363,13 @@ def find_stitch_path(graph, travel_graph, starting_point=None, ending_point=None real_start = nearest_node(travel_graph, starting_point) path.insert(0, PathEdge((real_start, starting_node), key="outline")) - real_end = nearest_node(travel_graph, ending_point) + # We're willing to start inside the shape, since we'll just cover the + # stitches. We have to end on the outline of the shape. This is mostly + # relevant in the case that the user specifies an underlay with an inset + # value, because the starting point (and possibly ending point) can be + # inside the shape. + outline_nodes = [node for node, outline in travel_graph.nodes(data="outline") if outline is not None] + real_end = nearest_node(outline_nodes, ending_point) path.append(PathEdge((ending_node, real_end), key="outline")) return path |
