diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index d9b8b3313..214a2a634 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -804,6 +804,8 @@ sub generate_toolpaths { $to_infill, offset($object->get_layer(0)->slices->polygons, $d), ); + } else { + $to_infill = union_ex($to_infill); } } else { # draw a perimeter all around support infill diff --git a/t/fill.t b/t/fill.t index 710e60536..765cfd479 100644 --- a/t/fill.t +++ b/t/fill.t @@ -22,7 +22,7 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ } { my $print = Slic3r::Print->new; my $surface_width = 250; - my $distance = Slic3r::Filler::adjust_solid_spacing($surface_width, 47); + my $distance = Slic3r::Flow::solid_spacing($surface_width, 47); is $distance, 50, 'adjusted solid distance'; is $surface_width % $distance, 0, 'adjusted solid distance'; } diff --git a/xs/src/libslic3r/Fill/Fill.cpp b/xs/src/libslic3r/Fill/Fill.cpp index 555081616..39c9107b9 100644 --- a/xs/src/libslic3r/Fill/Fill.cpp +++ b/xs/src/libslic3r/Fill/Fill.cpp @@ -72,36 +72,6 @@ Fill::fill_surface(const Surface &surface) return polylines_out; } -// Calculate a new spacing to fill width with possibly integer number of lines, -// the first and last line being centered at the interval ends. -// This function possibly increases the spacing, never decreases, -// and for a narrow width the increase in spacing may become severe, -// therefore the adjustment is limited to 20% increase. -coord_t -Fill::adjust_solid_spacing(const coord_t width, const coord_t distance) -{ - assert(width >= 0); - assert(distance > 0); - const int number_of_intervals = floor(width / distance); - if (number_of_intervals == 0) return distance; - - coord_t distance_new = (width / number_of_intervals); - - const coordf_t factor = coordf_t(distance_new) / coordf_t(distance); - assert(factor > 1. - 1e-5); - - // How much could the extrusion width be increased? By 20%. - // Because of this limit, this method is not idempotent: each run - // will increment distance by 20%. - const coordf_t factor_max = 1.2; - if (factor > factor_max) - distance_new = floor((double)distance * factor_max + 0.5); - - assert((distance_new * number_of_intervals) <= width); - - return distance_new; -} - // Returns orientation of the infill and the reference point of the infill pattern. // For a normal print, the reference point is the center of a bounding box of the STL. Fill::direction_t diff --git a/xs/src/libslic3r/Fill/Fill.hpp b/xs/src/libslic3r/Fill/Fill.hpp index abb9e1c65..a72d5528c 100644 --- a/xs/src/libslic3r/Fill/Fill.hpp +++ b/xs/src/libslic3r/Fill/Fill.hpp @@ -64,7 +64,6 @@ public: public: static Fill* new_from_type(const InfillPattern type); static Fill* new_from_type(const std::string &type); - static coord_t adjust_solid_spacing(const coord_t width, const coord_t distance); virtual Fill* clone() const = 0; virtual ~Fill() {}; diff --git a/xs/src/libslic3r/Fill/FillConcentric.cpp b/xs/src/libslic3r/Fill/FillConcentric.cpp index 24d8f318a..992dfaa3b 100644 --- a/xs/src/libslic3r/Fill/FillConcentric.cpp +++ b/xs/src/libslic3r/Fill/FillConcentric.cpp @@ -1,5 +1,6 @@ #include "../ClipperUtils.hpp" #include "../ExPolygon.hpp" +#include "../Flow.hpp" #include "../Surface.hpp" #include "FillConcentric.hpp" @@ -20,7 +21,7 @@ FillConcentric::_fill_surface_single( if (this->density > 0.9999f && !this->dont_adjust) { BoundingBox bounding_box = expolygon.contour.bounding_box(); - distance = this->adjust_solid_spacing(bounding_box.size().x, distance); + distance = Flow::solid_spacing(bounding_box.size().x, distance); this->_spacing = unscale(distance); } diff --git a/xs/src/libslic3r/Fill/FillRectilinear.cpp b/xs/src/libslic3r/Fill/FillRectilinear.cpp index e02c3a298..bfee321ed 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.cpp @@ -6,6 +6,7 @@ #include "../ClipperUtils.hpp" #include "../ExPolygon.hpp" +#include "../Flow.hpp" #include "../PolylineCollection.hpp" #include "../Surface.hpp" #include @@ -48,7 +49,7 @@ FillRectilinear::_fill_single_direction(ExPolygon expolygon, // define flow spacing according to requested density if (this->density > 0.9999f && !this->dont_adjust) { - line_spacing = this->adjust_solid_spacing(bounding_box.size().x, line_spacing); + line_spacing = Flow::solid_spacing(bounding_box.size().x, line_spacing); this->_spacing = unscale(line_spacing); } else { // extend bounding box so that our pattern will be aligned with other layers diff --git a/xs/src/libslic3r/Flow.cpp b/xs/src/libslic3r/Flow.cpp index a0cd62236..42caf9f1a 100644 --- a/xs/src/libslic3r/Flow.cpp +++ b/xs/src/libslic3r/Flow.cpp @@ -120,4 +120,37 @@ Flow::_width_from_spacing(float spacing, float nozzle_diameter, float height, bo return spacing + OVERLAP_FACTOR * height * (1 - PI/4.0); } +// Calculate a new spacing to fill width with possibly integer number of lines, +// the first and last line being centered at the interval ends. +// This function possibly increases the spacing, never decreases, +// and for a narrow width the increase in spacing may become severe, +// therefore the adjustment is limited to 20% increase. +template +T +Flow::solid_spacing(const T total_width, const T spacing) +{ + assert(total_width >= 0); + assert(spacing > 0); + const int number_of_intervals = floor(total_width / spacing); + if (number_of_intervals == 0) return spacing; + + T spacing_new = (total_width / number_of_intervals); + + const double factor = (double)spacing_new / (double)spacing; + assert(factor > 1. - 1e-5); + + // How much could the extrusion width be increased? By 20%. + // Because of this limit, this method is not idempotent: each run + // will increment spacing by 20%. + const double factor_max = 1.2; + if (factor > factor_max) + spacing_new = floor((double)spacing * factor_max + 0.5); + + assert((spacing_new * number_of_intervals) <= total_width); + + return spacing_new; +} +template coord_t Flow::solid_spacing(const coord_t total_width, const coord_t spacing); +template coordf_t Flow::solid_spacing(const coordf_t total_width, const coordf_t spacing); + } diff --git a/xs/src/libslic3r/Flow.hpp b/xs/src/libslic3r/Flow.hpp index 8284cc6d6..7149df6b4 100644 --- a/xs/src/libslic3r/Flow.hpp +++ b/xs/src/libslic3r/Flow.hpp @@ -31,6 +31,12 @@ class Flow float spacing() const; float spacing(const Flow &other) const; void set_spacing(float spacing); + void set_solid_spacing(const coord_t total_width) { + this->set_spacing(Flow::solid_spacing(total_width, this->scaled_spacing())); + }; + void set_solid_spacing(const coordf_t total_width) { + this->set_spacing(Flow::solid_spacing(total_width, (coordf_t)this->spacing())); + }; double mm3_per_mm() const; coord_t scaled_width() const { return scale_(this->width); @@ -44,6 +50,7 @@ class Flow static Flow new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &width, float nozzle_diameter, float height, float bridge_flow_ratio); static Flow new_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge); + template static T solid_spacing(const T total_width, const T spacing); private: static float _bridge_width(float nozzle_diameter, float bridge_flow_ratio); diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 118c73e96..deb1d3135 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -771,7 +771,8 @@ Print::brim_flow() const 0 ); - flow.set_spacing(unscale(Fill::adjust_solid_spacing(scale_(this->config.brim_width.value), scale_(flow.spacing())))); + // Adjust extrusion width in order to fill the total brim width with an integer number of lines. + flow.set_solid_spacing(this->config.brim_width.value); return flow; } diff --git a/xs/xsp/Filler.xsp b/xs/xsp/Filler.xsp index 0c5c08b6c..3208ac29a 100644 --- a/xs/xsp/Filler.xsp +++ b/xs/xsp/Filler.xsp @@ -78,8 +78,3 @@ new_from_type(CLASS, type) %} }; - -%package{Slic3r::Filler}; - -coord_t adjust_solid_spacing(coord_t width, coord_t distance) - %code{% RETVAL = Fill::adjust_solid_spacing(width, distance); %}; diff --git a/xs/xsp/Flow.xsp b/xs/xsp/Flow.xsp index d09f0b351..05cc828b9 100644 --- a/xs/xsp/Flow.xsp +++ b/xs/xsp/Flow.xsp @@ -81,3 +81,6 @@ _constant() %} +coord_t solid_spacing(coord_t width, coord_t distance) + %code{% RETVAL = Flow::solid_spacing(width, distance); %}; +