From 3515ca399b6b01e0e293f5e62ee02ab392950183 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 8 Feb 2023 15:39:50 -0500 Subject: remove dead ends --- lib/tiles.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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'), -- cgit v1.2.3