From 0621b6f5f178b3c53e5096b5a0a87033212e3b10 Mon Sep 17 00:00:00 2001 From: supermerill Date: Tue, 23 Jan 2024 17:41:50 +0100 Subject: [PATCH] Fix wrong compute of width from external periemter spacing. Also better rounding for scripted float. supermerill/SuperSlicer#4082 --- src/libslic3r/Flow.cpp | 8 ++++++++ src/slic3r/GUI/ScriptExecutor.cpp | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Flow.cpp b/src/libslic3r/Flow.cpp index d81be3aeef9..26aea7e79a4 100644 --- a/src/libslic3r/Flow.cpp +++ b/src/libslic3r/Flow.cpp @@ -287,6 +287,14 @@ Flow Flow::new_from_config(FlowRole role, const DynamicConfig& print_config, flo if (role == frExternalPerimeter) { config_width = print_config.opt("external_perimeter_extrusion_width"); config_spacing = print_config.opt("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("perimeter_extrusion_width"); diff --git a/src/slic3r/GUI/ScriptExecutor.cpp b/src/slic3r/GUI/ScriptExecutor.cpp index 99bc3b438b1..e22e5eb1310 100644 --- a/src/slic3r/GUI/ScriptExecutor.cpp +++ b/src/slic3r/GUI/ScriptExecutor.cpp @@ -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; }