FIX: negative width in spacing function

JIRA:NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ie84ff1b6ca3faac733c004def484401872c707ff
(cherry picked from commit b1bd0738f78c4e253fd34d39fa32e0dcf959f418)
This commit is contained in:
xun.zhang 2024-08-21 12:28:13 +08:00 committed by Lane.Wei
parent 2d4655e780
commit 18eeba6e7a
2 changed files with 8 additions and 10 deletions

View File

@ -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;
}

View File

@ -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);