From eacbb558107e3cb2c17c876d395e2d19f684fca1 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 1 May 2026 20:56:43 +0200 Subject: [PATCH] arrange polies: apply triangle elimination in both algo 1 and 2 --- src/svgfill/src/arrange_polygons.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/svgfill/src/arrange_polygons.cpp b/src/svgfill/src/arrange_polygons.cpp index d8f6e8a79a..e7df3f77bc 100644 --- a/src/svgfill/src/arrange_polygons.cpp +++ b/src/svgfill/src/arrange_polygons.cpp @@ -3307,15 +3307,32 @@ void arrange_cgal_polygons(svgfill::arrange_polygon_settings settings, const std t0 = timer.start("center line cleaning"); Graph2D G; + + { + // this is applied for both algos + auto eliminated_segments = eliminate_triangles(line_graph); + for (auto e : eliminated_segments) { + debug_output.write_segment(e.first, e.second, "eliminated"); + for (int i = 0; i < 2; ++i) { + auto it = line_graph.find(e.first); + if (it == line_graph.end()) { + std::cerr << "Warning: unable to locate vertex for elimination, skipping" << std::endl; + continue; + } + auto& neighbours = it->second; + neighbours.erase(std::remove(neighbours.begin(), neighbours.end(), e.second), neighbours.end()); + if (neighbours.empty()) { + line_graph.erase(it); + } + std::swap(e.first, e.second); + } + } + } + Graph2D G_orig(line_graph); auto apply_line_cleaning_algo_1 = [&]() { - auto eliminated_segments = eliminate_triangles(line_graph); Graph2D G2(line_graph); - for (auto& e : eliminated_segments) { - debug_output.write_segment(e.first, e.second, "eliminated"); - G2.remove_edge(e.first, e.second); - } G = G2.weld_vertices(); for (auto it = G.edges_begin(); it != G.edges_end(); ++it) { debug_output.write_segment(it->first, it->second, "network_2");