#4654 Add a check for a 0 from the math to calculate the spacing; added a regression test to ensure that the spacing can't be 0 with otherwise valid inputs.

This commit is contained in:
Joseph Lenox 2018-12-30 22:38:36 -06:00 committed by Joseph Lenox
parent f19fc3b6dc
commit 8e5a9cba71
2 changed files with 20 additions and 0 deletions

View File

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

View File

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