diff options
| author | Lex Neva <github.com@lexneva.name> | 2023-02-08 15:39:50 -0500 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2023-02-20 15:27:55 -0500 |
| commit | 3515ca399b6b01e0e293f5e62ee02ab392950183 (patch) | |
| tree | 168dfdce05e991301e9049d6aaee8a4d4508117d | |
| parent | f2344375df9364f33b957d46e9cea508e1b32c67 (diff) | |
remove dead ends
| -rw-r--r-- | lib/tiles.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/tiles.py b/lib/tiles.py index 9986183b..7f46a5aa 100644 --- a/lib/tiles.py +++ b/lib/tiles.py @@ -139,8 +139,19 @@ class Tile: if shape.contains(line_string): graph.add_edge(line[0], line[1]) + self._remove_dead_ends(graph) + return graph + def _remove_dead_ends(self, graph): + while True: + nodes_with_degree_1 = [node for node, degree in graph.degree() if degree == 1] + + if nodes_with_degree_1: + graph.remove_nodes_from(nodes_with_degree_1) + else: + return + def all_tile_paths(): return [os.path.join(guess_inkscape_config_path(), 'tiles'), |
