From be7344e1959c381b63a6b0e8cac9ff6651c73068 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Mon, 7 Oct 2024 14:14:54 +0200 Subject: [PATCH 1/2] Change segment overhanging calculation formula CURA-12078 Instead of naively checking whether the start and end point of the segment are in the overhang area, calculate the intersection of the segment with the overhang area, and see if the length of the intersection is a significant enough part of the origin segment. This filters out some segments that partially overhang and are not really expected to be treated as overhanging. --- include/LayerPlan.h | 7 +++++++ src/LayerPlan.cpp | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/LayerPlan.h b/include/LayerPlan.h index 50195d7b36..48624a5afc 100644 --- a/include/LayerPlan.h +++ b/include/LayerPlan.h @@ -820,6 +820,13 @@ class LayerPlan : public NoCopy const coord_t wipe_dist, const Ratio flow_ratio, const double fan_speed); + + /*! + * \brief Calculates whether the given segment is to be treated as overhanging + * \param p0 The start point of the segment + * \param p1 The end point of the segment + */ + bool segmentIsOnOverhang(const Point2LL& p0, const Point2LL& p1) const; }; } // namespace cura diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 271d29ff9a..e5b74a01b2 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -737,7 +737,7 @@ void LayerPlan::addWallLine( segment_flow, width_factor, spiralize, - (overhang_mask_.empty() || (! overhang_mask_.inside(p0, true) && ! overhang_mask_.inside(p1, true))) ? speed_factor : overhang_speed_factor); + segmentIsOnOverhang(p0, p1) ? overhang_speed_factor : speed_factor); } distance_to_bridge_start -= len; @@ -752,7 +752,7 @@ void LayerPlan::addWallLine( segment_flow, width_factor, spiralize, - (overhang_mask_.empty() || (! overhang_mask_.inside(p0, true) && ! overhang_mask_.inside(p1, true))) ? speed_factor : overhang_speed_factor); + segmentIsOnOverhang(p0, p1) ? overhang_speed_factor : speed_factor); } non_bridge_line_volume += vSize(cur_point - segment_end) * segment_flow * width_factor * speed_factor * default_config.getSpeed(); cur_point = segment_end; @@ -839,14 +839,7 @@ void LayerPlan::addWallLine( else if (bridge_wall_mask_.empty()) { // no bridges required - addExtrusionMove( - p1, - default_config, - SpaceFillType::Polygons, - flow, - width_factor, - spiralize, - (overhang_mask_.empty() || (! overhang_mask_.inside(p0, true) && ! overhang_mask_.inside(p1, true))) ? 1.0_r : overhang_speed_factor); + addExtrusionMove(p1, default_config, SpaceFillType::Polygons, flow, width_factor, spiralize, segmentIsOnOverhang(p0, p1) ? overhang_speed_factor : 1.0_r); } else { @@ -1497,6 +1490,13 @@ void LayerPlan::addLinesInGivenOrder( } } +bool LayerPlan::segmentIsOnOverhang(const Point2LL& p0, const Point2LL& p1) const +{ + const OpenPolyline segment{ p0, p1 }; + const OpenLinesSet intersected_lines = overhang_mask_.intersection(OpenLinesSet{ segment }); + return ! intersected_lines.empty() && (static_cast(intersected_lines.length()) / segment.length()) > 0.5; +} + void LayerPlan::addLinesMonotonic( const Shape& area, const OpenLinesSet& lines, From 04fc407e6ea3960d47bd7e1bf7b15d02c607902e Mon Sep 17 00:00:00 2001 From: wawanbreton Date: Mon, 7 Oct 2024 12:43:43 +0000 Subject: [PATCH 2/2] Applied clang-format. --- include/LayerPlan.h | 2 +- src/LayerPlan.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/LayerPlan.h b/include/LayerPlan.h index b67d2257bb..75eac440ea 100644 --- a/include/LayerPlan.h +++ b/include/LayerPlan.h @@ -948,7 +948,7 @@ class LayerPlan : public NoCopy * \param p0 The start point of the segment * \param p1 The end point of the segment */ - bool segmentIsOnOverhang(const Point3LL &p0, const Point3LL &p1) const; + bool segmentIsOnOverhang(const Point3LL& p0, const Point3LL& p1) const; }; } // namespace cura diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 1969524ee4..a821d01f4a 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -2387,7 +2387,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) for (const auto& reversed_chunk : paths | ranges::views::enumerate | ranges::views::reverse | ranges::views::chunk_by( - [](const auto& path_a, const auto& path_b) + [](const auto&path_a, const auto&path_b) { return (! std::get<1>(path_a).isTravelPath()) || std::get<1>(path_b).isTravelPath(); }))