From 735f5146e9a491454865ad7e2ea8cd3f563e3ba7 Mon Sep 17 00:00:00 2001
From: bubnikv <bubnikv@gmail.com>
Date: Mon, 9 Sep 2019 16:44:29 +0200
Subject: [PATCH] Fix of d146a0237e51b15ba39bb5c2a45e9d208e50b4cf (reworked
 infill generator to merge regions with the same properties).

---
 src/libslic3r/Fill/Fill.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp
index 9642f3629..77cb5f47f 100644
--- a/src/libslic3r/Fill/Fill.cpp
+++ b/src/libslic3r/Fill/Fill.cpp
@@ -198,11 +198,12 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
 	{
 		Polygons all_polygons;
 		for (SurfaceFill &fill : surface_fills)
-			if (! fill.expolygons.empty() && (fill.expolygons.size() > 1 || ! all_polygons.empty())) {
+			if (! fill.expolygons.empty()) {
 				Polygons polys = to_polygons(std::move(fill.expolygons));
-	            // Make a union of polygons, use a safety offset, subtract the preceding polygons.
-			    // Bridges are processed first (see SurfaceFill::operator<())
-	            fill.expolygons = all_polygons.empty() ? union_ex(polys, true) : diff_ex(polys, all_polygons, true);
+				if (fill.expolygons.size() > 1 || ! all_polygons.empty())
+		            // Make a union of polygons, use a safety offset, subtract the preceding polygons.
+				    // Bridges are processed first (see SurfaceFill::operator<())
+		            fill.expolygons = all_polygons.empty() ? union_ex(polys, true) : diff_ex(polys, all_polygons, true);
 				append(all_polygons, std::move(polys));
 	        }
 	}
@@ -309,7 +310,6 @@ void Layer::make_fills()
         f->layer_id = this->id();
         f->z 		= this->print_z;
         f->angle 	= surface_fill.params.angle;
-        f->spacing  = surface_fill.params.spacing;
 
         // calculate flow spacing for infill pattern generation
         bool using_internal_flow = ! surface_fill.surface.is_solid() && ! surface_fill.params.flow.bridge;
@@ -335,8 +335,10 @@ void Layer::make_fills()
         params.dont_adjust 	= surface_fill.params.dont_adjust; // false
 
         for (ExPolygon &expoly : surface_fill.expolygons) {
-        	surface_fill.surface.expolygon = std::move(expoly);
-	        Polylines polylines = f->fill_surface(&surface_fill.surface, params);
+			// Spacing is modified by the filler to indicate adjustments. Reset it for each expolygon.
+			f->spacing = surface_fill.params.spacing;
+			surface_fill.surface.expolygon = std::move(expoly);
+			Polylines polylines = f->fill_surface(&surface_fill.surface, params);
 	        if (! polylines.empty()) {
 		        // calculate actual flow from spacing (which might have been adjusted by the infill
 		        // pattern generator)