From a9574d62e7aaa97cc59f116da9a021d42e3b6258 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 11 Jul 2024 15:28:07 +0200 Subject: [PATCH 1/2] Fix floating point rounding issue The calculated line width is quite important here, because GCodePath objects may be merged (or not) depending on it, and sometimes the value would be rounded to a very close value, but not equal. We now use llrint to make sure we round to the neareset value. CURA-12038 --- src/LayerPlan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 56d7514509..55626167eb 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -1151,7 +1151,7 @@ void LayerPlan::addWall( for (size_t piece = 0; piece < pieces; ++piece) { const double average_progress = (double(piece) + 0.5) / pieces; // How far along this line to sample the line width in the middle of this piece. - const coord_t line_width = p0.w_ + average_progress * delta_line_width; + const coord_t line_width = std::lrint(p0.w_ + average_progress * delta_line_width); const Point2LL destination = p0.p_ + normal(line_vector, piece_length * (piece + 1)); if (is_small_feature) { From d05898a873ea9ad6eb83dd3af5a481bd6043b350 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 11 Jul 2024 15:48:17 +0200 Subject: [PATCH 2/2] Add documentation, and remove compiler warning CURA-12038 --- src/LayerPlan.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 55626167eb..1ef4b35bda 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -1151,7 +1151,9 @@ void LayerPlan::addWall( for (size_t piece = 0; piece < pieces; ++piece) { const double average_progress = (double(piece) + 0.5) / pieces; // How far along this line to sample the line width in the middle of this piece. - const coord_t line_width = std::lrint(p0.w_ + average_progress * delta_line_width); + // Round the line_width value to overcome floating point rounding issues, otherwise we may end up with slightly different values + // and the generated GCodePath objects will not be merged together, which some subsequent algorithms rely on (e.g. coasting) + const coord_t line_width = std::lrint(static_cast(p0.w_) + average_progress * static_cast(delta_line_width)); const Point2LL destination = p0.p_ + normal(line_vector, piece_length * (piece + 1)); if (is_small_feature) {