mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-10 02:37:04 +00:00
Scale Min Junction Width to Prevent Fuzzy Skin From Failing Slice (#15566)
* Fix fuzzy skin failing the slice: the minimum junction width was unscaled * Unit Tests For Fuzzy Fix * Cover ridged multifractal noise in the fuzzy skin width floor test Its output is not bounded to [-1, 1], so it scales past the configured thickness and drives the junction width negative. The floor has to hold for any noise value, not just an in-range one.
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
#include "libslic3r/Arachne/utils/ExtrusionLine.hpp"
|
||||
#include "libslic3r/Arachne/BeadingStrategy/BeadingStrategyFactory.hpp"
|
||||
#include "libslic3r/Arachne/BeadingStrategy/BeadingStrategy.hpp"
|
||||
#include "libslic3r/Feature/FuzzySkin/FuzzySkin.hpp"
|
||||
#include "libslic3r/Flow.hpp"
|
||||
#include "libslic3r/Polygon.hpp"
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
@@ -309,3 +311,71 @@ TEST_CASE("Beading interpolation tolerates a thicker side with fewer insets", "[
|
||||
CHECK(result.bead_widths[i] == expected.bead_widths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Closed 20 mm square loop at a uniform width.
|
||||
Arachne::ExtrusionJunctions square_loop(coord_t width)
|
||||
{
|
||||
const coord_t s = scaled<coord_t>(20.);
|
||||
return {{Point(0, 0), width, 0}, {Point(s, 0), width, 0}, {Point(s, s), width, 0}, {Point(0, s), width, 0}, {Point(0, 0), width, 0}};
|
||||
}
|
||||
|
||||
FuzzySkinConfig thick_fuzzy_config(FuzzySkinMode mode, NoiseType noise_type, double thickness_mm)
|
||||
{
|
||||
FuzzySkinConfig cfg{};
|
||||
cfg.type = FuzzySkinType::All;
|
||||
cfg.thickness = scaled<coord_t>(thickness_mm);
|
||||
cfg.point_distance = scaled<coord_t>(0.3);
|
||||
cfg.fuzzy_first_layer = true;
|
||||
cfg.noise_type = noise_type;
|
||||
cfg.noise_scale = 1.0;
|
||||
cfg.noise_octaves = 4;
|
||||
cfg.noise_persistence = 0.5;
|
||||
cfg.mode = mode;
|
||||
cfg.layer_id = 5;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Extrusion and Combined mode add noise to each junction's width. A junction narrower than
|
||||
// height * (1 - PI/4) makes Flow::rounded_rectangle_extrusion_spacing() throw and fails the slice.
|
||||
// The fuzz thickness is 3x the line width so the clamp is hit on every run regardless of RNG seed.
|
||||
// Ridged multifractal is covered because its output is not bounded to [-1, 1], so it scales past
|
||||
// the configured thickness; the floor has to hold for any noise value, not just an in-range one.
|
||||
TEST_CASE("Fuzzy skin extrusion width is floored at the minimum the flow accepts", "[Arachne][FuzzySkin]") {
|
||||
using namespace Slic3r::Feature::FuzzySkin;
|
||||
|
||||
const double layer_height = GENERATE(0.08, 0.2, 0.28);
|
||||
const auto mode = GENERATE(FuzzySkinMode::Extrusion, FuzzySkinMode::Combined);
|
||||
const auto noise_type = GENERATE(NoiseType::Classic, NoiseType::Perlin, NoiseType::Billow, NoiseType::RidgedMulti, NoiseType::Voronoi);
|
||||
CAPTURE(layer_height, int(mode), int(noise_type));
|
||||
|
||||
const double line_width_mm = 0.42;
|
||||
auto loop = square_loop(scaled<coord_t>(line_width_mm));
|
||||
fuzzy_extrusion_line(loop, /*slice_z*/ 1.0, layer_height, thick_fuzzy_config(mode, noise_type, 3 * line_width_mm));
|
||||
|
||||
REQUIRE(loop.size() > 100);
|
||||
|
||||
const auto narrowest = std::min_element(loop.begin(), loop.end(), [](const auto& a, const auto& b) { return a.w < b.w; });
|
||||
const double narrowest_mm = unscaled<double>(narrowest->w);
|
||||
const double floor_mm = layer_height * (1. - 0.25 * PI);
|
||||
CAPTURE(narrowest_mm, floor_mm);
|
||||
|
||||
CHECK(narrowest_mm < line_width_mm); // the clamp was exercised
|
||||
CHECK(narrowest_mm > floor_mm);
|
||||
CHECK_NOTHROW(Flow::rounded_rectangle_extrusion_spacing(float(narrowest_mm), float(layer_height)));
|
||||
}
|
||||
|
||||
// Displacement mode only moves points; widths must pass through unchanged.
|
||||
TEST_CASE("Fuzzy skin displacement mode leaves widths untouched", "[Arachne][FuzzySkin]") {
|
||||
using namespace Slic3r::Feature::FuzzySkin;
|
||||
|
||||
const coord_t width = scaled<coord_t>(0.42);
|
||||
auto loop = square_loop(width);
|
||||
fuzzy_extrusion_line(loop, /*slice_z*/ 1.0, /*layer_height*/ 0.2, thick_fuzzy_config(FuzzySkinMode::Displacement, NoiseType::Classic, 1.26));
|
||||
|
||||
REQUIRE(loop.size() > 100);
|
||||
CHECK(std::all_of(loop.begin(), loop.end(), [width](const auto& j) { return j.w == width; }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user