Arrange polies: reorder segment to exterior insertion based on length

This commit is contained in:
Thomas Krijnen
2026-05-12 20:52:30 +02:00
parent 7a901c1fce
commit 10f93545da
+35 -11
View File
@@ -1469,6 +1469,7 @@ std::vector<MergedBoxRecord> merge_intersecting_parallel_boxes_iterative(const s
std::vector<size_t> members = clusters[i].members; std::vector<size_t> members = clusters[i].members;
members.insert(members.end(), clusters[j].members.begin(), clusters[j].members.end()); members.insert(members.end(), clusters[j].members.begin(), clusters[j].members.end());
auto merged = BoxCluster{members, merge_cluster_to_box(members, records)}; auto merged = BoxCluster{members, merge_cluster_to_box(members, records)};
std::cout << "Result width: " << merged.box.avg_width << " fromt " << clusters[i].box.avg_width << " & " << clusters[j].box.avg_width << std::endl;
std::vector<BoxCluster> next_clusters; std::vector<BoxCluster> next_clusters;
next_clusters.reserve(clusters.size() - 1); next_clusters.reserve(clusters.size() - 1);
@@ -2170,17 +2171,12 @@ extend_end_vertices_based_on_input_simple(
const K::FT& max_projection_distance) const K::FT& max_projection_distance)
{ {
auto max_intersection_distance = max_projection_distance / 4; auto max_intersection_distance = max_projection_distance / 4;
std::list<std::pair<Point_2, Point_2>> constructed_segments;
for (auto it = G.vertices_begin(); it != G.vertices_end(); ++it) {
if (it->second.size() == 1) {
auto& M = it->first;
const auto& process_point = [&](const Point_2& M, const Point_2& incoming) {
for (auto& bnd : outer_perimiter) { for (auto& bnd : outer_perimiter) {
// if point M is contained in bnd interior: // if point M is contained in bnd interior:
// if (!bnd.has_on_unbounded_side(M)) { // if (!bnd.has_on_unbounded_side(M)) {
if (bnd.has_on_bounded_side(M)) { if (bnd.has_on_bounded_side(M)) {
auto& incoming = *it->second.begin();
// create ray incoming -> M // create ray incoming -> M
CGAL::Ray_2<K> ray(incoming, M - incoming); CGAL::Ray_2<K> ray(incoming, M - incoming);
@@ -2207,7 +2203,8 @@ extend_end_vertices_based_on_input_simple(
} }
if (closest_intersection_point) { if (closest_intersection_point) {
constructed_segments.push_front({M, *closest_intersection_point}); return closest_intersection_point;
// constructed_segments.push_front({M, *closest_intersection_point});
} else { } else {
// Loop over boundary segments, and project point onto it, take the closest // Loop over boundary segments, and project point onto it, take the closest
@@ -2230,7 +2227,8 @@ extend_end_vertices_based_on_input_simple(
} }
if (closest_point) { if (closest_point) {
constructed_segments.push_front({M, *closest_point}); return closest_point;
// constructed_segments.push_front({M, *closest_point});
} else { } else {
for (auto& poly : outer_perimiter) { for (auto& poly : outer_perimiter) {
@@ -2247,14 +2245,40 @@ extend_end_vertices_based_on_input_simple(
} }
if (closest_point) { if (closest_point) {
constructed_segments.push_front({M, *closest_point}); return closest_point;
// constructed_segments.push_front({M, *closest_point});
} else {
}
}
}
}
}
return boost::optional<Point_2>{};
};
using solution_length_point_incoming = std::tuple<K::FT, Point_2, Point_2>;
std::vector<solution_length_point_incoming> solutions;
for (auto it = G.vertices_begin(); it != G.vertices_end(); ++it) {
if (it->second.size() == 1) {
auto& M = it->first;
if (auto result = process_point(M, *it->second.begin())) {
auto d = (M - *result).squared_length();
solutions.emplace_back(d, *result, *it->second.begin());
} else { } else {
std::cout << "Unable to find projection or intersection point for interior boundary (" << M.x() << " " << M.y() << ")" << std::endl; std::cout << "Unable to find projection or intersection point for interior boundary (" << M.x() << " " << M.y() << ")" << std::endl;
} }
} }
} }
}
} std::sort(solutions.begin(), solutions.end());
std::list<std::pair<Point_2, Point_2>> constructed_segments;
for (auto& [d, point, incoming] : solutions) {
if (auto result = process_point(point, incoming)) {
constructed_segments.push_front({point, *result});
} else {
std::cout << "Unable to find projection or intersection point for interior boundary (" << M.x() << " " << M.y() << ")" << std::endl;
} }
} }