From 13bb8fbb980dabfb9f9d6654cc9a83c473d71f2b Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 14 May 2026 21:45:59 +0200 Subject: [PATCH] arrange polies: don't allow snapped point paths to cross non-containing other rect axes --- src/svgfill/src/arrange_polygons.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/svgfill/src/arrange_polygons.cpp b/src/svgfill/src/arrange_polygons.cpp index 4cac193672..3c7c4ad32a 100644 --- a/src/svgfill/src/arrange_polygons.cpp +++ b/src/svgfill/src/arrange_polygons.cpp @@ -1635,13 +1635,28 @@ std::map> snap_points_to_box_axes( auto& c2 = containing[1]; if (angle_between_dirs_deg(boxes[c1.box_index].direction, boxes[c2.box_index].direction) > 8.) { if (auto x = intersect_infinite_lines_exact(boxes[c1.box_index], boxes[c2.box_index])) { - snapped_points[i] = *x; - debug.write_segment(graph.points[i], *x, "snap_candidate_1"); - continue; + auto seg = CGAL::Segment_2(graph.points[i], *x); + bool intersects_with_other_box_axis = false; + for (size_t j = 0; j < boxes.size(); ++j) { + if (j == c1.box_index || j == c2.box_index) { + continue; + } + auto& box = boxes[j]; + auto box_seg = CGAL::Segment_2(box.exact_start, box.exact_end); + if (CGAL::do_intersect(seg, box_seg)) { + intersects_with_other_box_axis = true; + break; + } + } + if (!intersects_with_other_box_axis) { + snapped_points[i] = *x; + debug.write_segment(graph.points[i], *x, "snap_candidate_1"); + continue; + } } } - snapped_points[i] = c1.projection; - debug.write_segment(graph.points[i], c1.projection, "snap_candidate_2"); + snapped_points[i] = (c1.projection - graph.points[i]).squared_length() < (c2.projection - graph.points[i]).squared_length() ? c1.projection : c2.projection; + debug.write_segment(graph.points[i], snapped_points[i], "snap_candidate_2"); continue; }