Skip to content

Commit

Permalink
slic3r#4654 Add a check for a 0 from the math to calculate the spacin…
Browse files Browse the repository at this point in the history
…g; added a regression test to ensure that the spacing can't be 0 with otherwise valid inputs.
  • Loading branch information
lordofhyphens committed Dec 31, 2018
1 parent f19fc3b commit 8e5a9cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test/libslic3r/test_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ SCENARIO("Flow: Flow math for non-bridges", "[!mayfail]") {
}
}
}


/// Check for an edge case in the maths where the spacing could be 0; original
/// math is 0.99. Slic3r issue #4654
GIVEN("Input spacing of 0.414159 and a total width of 2") {
double in_spacing = 0.414159;
double total_width = 2.0;
auto flow {Flow::new_from_spacing(1.0, 0.4, 0.3, false)};
WHEN("solid_spacing() is called") {
double result = flow.solid_spacing(total_width, in_spacing);
THEN("Yielded spacing is greater than 0") {
REQUIRE(result > 0);
}
}
}

}

/// Spacing, width calculation for bridge extrusions
Expand Down
4 changes: 4 additions & 0 deletions xs/src/libslic3r/Flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Flow::solid_spacing(const T total_width, const T spacing)
const double factor_max = 1.2;
if (factor > factor_max)
spacing_new = floor((double)spacing * factor_max + 0.5);
// There is an edge case where spacing with the max factor still ends up to be 0
// In this case, use the full factor and don't round it
if (spacing_new == 0)
spacing_new = (static_cast<double>(spacing) * factor);

assert((spacing_new * number_of_intervals) <= total_width);

Expand Down

0 comments on commit 8e5a9cb

Please sign in to comment.