Skip to content

Commit

Permalink
Fix wrong compute of width from external periemter spacing.
Browse files Browse the repository at this point in the history
Also better rounding for scripted float.
#4082
  • Loading branch information
supermerill committed Jan 23, 2024
1 parent 16d322a commit 0621b6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/libslic3r/Flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ Flow Flow::new_from_config(FlowRole role, const DynamicConfig& print_config, flo
if (role == frExternalPerimeter) {
config_width = print_config.opt<ConfigOptionFloatOrPercent>("external_perimeter_extrusion_width");
config_spacing = print_config.opt<ConfigOptionFloatOrPercent>("external_perimeter_extrusion_spacing");
// external peri spacing is only half spacing -> transform it into a full spacing
if (!config_spacing.is_phony() && !config_spacing.value == 0) {
double raw_spacing = config_spacing.get_abs_value(nozzle_diameter);
config_spacing.percent = false;
config_spacing.value = rounded_rectangle_extrusion_spacing(
rounded_rectangle_extrusion_width_from_spacing(raw_spacing, layer_height, 0.5f),
layer_height, 1.f);
}
overlap = (float)print_config.get_abs_value("external_perimeter_overlap", 1.0);
} else if (role == frPerimeter) {
config_width = print_config.opt<ConfigOptionFloatOrPercent>("perimeter_extrusion_width");
Expand Down
14 changes: 12 additions & 2 deletions src/slic3r/GUI/ScriptExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,20 @@ float as_get_float(std::string& key)
}
}

double round(float f) {
double round(float value) {
double intpart;
if (modf(value, &intpart) == 0.0) {
// shortcut for int
return value;
}
std::stringstream ss;
//first, get the int part, to see how many digit it takes
int long10 = 0;
if (intpart > 9)
long10 = (int)std::floor(std::log10(std::abs(intpart)));
//set the usable precision: there is only ~7 decimal digit in a float (15-16 decimal digit in a double)
ss << std::fixed << std::setprecision(7 - long10) << value;
double dbl_val;
ss << f;
ss >> dbl_val;
return dbl_val;
}
Expand Down

0 comments on commit 0621b6f

Please sign in to comment.