From 18eeba6e7ae9f1dca34e7f319bfef8f4dddbacd8 Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Wed, 21 Aug 2024 12:28:13 +0800 Subject: [PATCH] FIX: negative width in spacing function JIRA:NONE Signed-off-by: xun.zhang Change-Id: Ie84ff1b6ca3faac733c004def484401872c707ff (cherry picked from commit b1bd0738f78c4e253fd34d39fa32e0dcf959f418) --- src/libslic3r/Flow.cpp | 4 +++- src/libslic3r/VariableWidth.cpp | 14 +++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/Flow.cpp b/src/libslic3r/Flow.cpp index 0fbefb724..97b3c1427 100644 --- a/src/libslic3r/Flow.cpp +++ b/src/libslic3r/Flow.cpp @@ -190,8 +190,10 @@ Flow Flow::with_cross_section(float area_new) const float Flow::rounded_rectangle_extrusion_spacing(float width, float height) { auto out = width - height * float(1. - 0.25 * PI); - if (out <= 0.f) + if (out <= 0.f) { + BOOST_LOG_TRIVIAL(error)<< __FUNCTION__ << boost::format("negative extrusion : width %1% height %2%") % width % height; throw FlowErrorNegativeSpacing(); + } return out; } diff --git a/src/libslic3r/VariableWidth.cpp b/src/libslic3r/VariableWidth.cpp index e01050e4a..c7c2a6908 100644 --- a/src/libslic3r/VariableWidth.cpp +++ b/src/libslic3r/VariableWidth.cpp @@ -122,10 +122,8 @@ static ExtrusionPaths thick_polyline_to_extrusion_paths_2(const ThickPolyline& t //BBS: 1 generate path from start_index to i(not included) if (start_index != i){ path = ExtrusionPath(role); - double length = lines[start_index].length(); - double sum = lines[start_index].length() * 0.5 * (lines[start_index].a_width + lines[start_index].b_width); - path.polyline.append(lines[start_index].a); - for (int idx = start_index + 1; idx < i; idx++) { + double length = 0, sum = 0; + for (int idx = start_index; idx < i; idx++) { length += lines[idx].length(); sum += lines[idx].length() * 0.5 * (lines[idx].a_width + lines[idx].b_width); path.polyline.append(lines[idx].a); @@ -191,12 +189,10 @@ static ExtrusionPaths thick_polyline_to_extrusion_paths_2(const ThickPolyline& t size_t final_size = lines.size(); if (start_index < final_size) { path = ExtrusionPath(role); - double length = lines[start_index].length(); - double sum = lines[start_index].length() * lines[start_index].a_width; - path.polyline.append(lines[start_index].a); - for (int idx = start_index + 1; idx < final_size; idx++) { + double length = 0, sum = 0; + for (int idx = start_index; idx < final_size; idx++) { length += lines[idx].length(); - sum += lines[idx].length() * lines[idx].a_width; + sum += lines[idx].length() * (lines[idx].a_width + lines[idx].b_width) * 0.5; path.polyline.append(lines[idx].a); } path.polyline.append(lines[final_size - 1].b);