From f05f5386c7fb2226d3630cebc429ee35f1850eb4 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 11 Apr 2024 11:01:19 +0200 Subject: [PATCH] Make line-overlap detection more conservative. (Tried a lot of other things as well, which makes it less predictable.) Clean up experiments, bring it back to basics, be quite conservative as this is only a patch and solving the whole 'scan-segments can be too close to the connector paths' probably requires properly rewriting the zig-zag algorithm -- which is way more like a feature. part of CURA-11597 --- include/infill/ZigzagConnectorProcessor.h | 2 ++ src/infill.cpp | 2 +- src/infill/ZigzagConnectorProcessor.cpp | 24 +++++++++++------------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/infill/ZigzagConnectorProcessor.h b/include/infill/ZigzagConnectorProcessor.h index 9adb751430..9b1b979cf6 100644 --- a/include/infill/ZigzagConnectorProcessor.h +++ b/include/infill/ZigzagConnectorProcessor.h @@ -175,6 +175,8 @@ class ZigzagConnectorProcessor */ void addZagConnector(std::vector& points, bool is_endpiece); + bool handleConnectorToCloseToSegment(const coord_t scanline_x, const coord_t min_distance_to_scanline); + protected: const PointMatrix& rotation_matrix_; //!< The rotation matrix used to enforce the infill angle Polygons& result_; //!< The result of the computation diff --git a/src/infill.cpp b/src/infill.cpp index 715cce1c61..7164da9741 100644 --- a/src/infill.cpp +++ b/src/infill.cpp @@ -751,7 +751,7 @@ void Infill::generateLinearBasedInfill( assert(scanline_idx - scanline_min_idx >= 0 && scanline_idx - scanline_min_idx < int(cut_list.size()) && "reading infill cutlist index out of bounds!"); cut_list[scanline_idx - scanline_min_idx].push_back(y); Point2LL scanline_linesegment_intersection(x, y); - zigzag_connector_processor.registerScanlineSegmentIntersection(scanline_linesegment_intersection, scanline_idx, line_distance / 2); + zigzag_connector_processor.registerScanlineSegmentIntersection(scanline_linesegment_intersection, scanline_idx, line_distance / 4); crossings_per_scanline[scanline_idx - min_scanline_index].emplace_back(scanline_linesegment_intersection, poly_idx, point_idx); } zigzag_connector_processor.registerVertex(p1); diff --git a/src/infill/ZigzagConnectorProcessor.cpp b/src/infill/ZigzagConnectorProcessor.cpp index 315735bb9a..c19cd46b4e 100644 --- a/src/infill/ZigzagConnectorProcessor.cpp +++ b/src/infill/ZigzagConnectorProcessor.cpp @@ -83,6 +83,15 @@ bool ZigzagConnectorProcessor::shouldAddCurrentConnector(int start_scanline_idx, return should_add; } +bool ZigzagConnectorProcessor::handleConnectorToCloseToSegment(const coord_t scanline_x, const coord_t min_distance_to_scanline) +{ + bool all_within_min_dist = ! current_connector_.empty(); + for (const auto& point : current_connector_) + { + all_within_min_dist &= std::abs(point.X - scanline_x) < min_distance_to_scanline; + } + return all_within_min_dist; +} void ZigzagConnectorProcessor::registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index, coord_t min_distance_to_scanline) { @@ -97,20 +106,11 @@ void ZigzagConnectorProcessor::registerScanlineSegmentIntersection(const Point2L else { // add the current connector if needed - if (shouldAddCurrentConnector(last_connector_index_, scanline_index)) + if (shouldAddCurrentConnector(last_connector_index_, scanline_index) && ! handleConnectorToCloseToSegment(intersection.X, min_distance_to_scanline)) { const bool is_this_endpiece = scanline_index == last_connector_index_; - bool close_to_line_except_intersect = true; - const coord_t min_dist2 = min_distance_to_scanline * min_distance_to_scanline; - for (const auto& point : current_connector_) - { - close_to_line_except_intersect &= std::abs(point.X - intersection.X) < min_distance_to_scanline; - } - if (current_connector_.empty() || ! close_to_line_except_intersect) - { - current_connector_.push_back(intersection); - addZagConnector(current_connector_, is_this_endpiece); - } + current_connector_.push_back(intersection); + addZagConnector(current_connector_, is_this_endpiece); } }