From cf6b6ff4e4c47ebbe08f97cf80d923cde81c29af Mon Sep 17 00:00:00 2001
From: Pavel Mikus <pavel.mikus.mail@seznam.cz>
Date: Tue, 30 May 2023 15:46:03 +0200
Subject: [PATCH] Fix SPE-1726 - hole between bridges and perimeters caused by
 thin internal fill surface GithubIssue
 https://github.com/prusa3d/PrusaSlicer/issues/10231#issuecomment-1546779200
 During sorting of surfaces into top, bottom and internal, expand bottom
 bridges by one spacing unit, to ensure better anchoring

---
 src/libslic3r/PrintObject.cpp | 11 +++++------
 src/libslic3r/utils.cpp       |  1 +
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp
index ff7906da0..f9fa624fe 100644
--- a/src/libslic3r/PrintObject.cpp
+++ b/src/libslic3r/PrintObject.cpp
@@ -981,12 +981,11 @@ void PrintObject::detect_surfaces_type()
                             surface_type_bottom_other);
 #else
                         // Any surface lying on the void is a true bottom bridge (an overhang)
-                        surfaces_append(
-                            bottom,
-                            opening_ex(
-                                diff_ex(layerm->slices().surfaces, lower_layer->lslices, ApplySafetyOffset::Yes),
-                                offset),
-                            surface_type_bottom_other);
+                        ExPolygons true_bridge = diff_ex(layerm->slices().surfaces, lower_layer->lslices, ApplySafetyOffset::Yes);
+                        // expand the bridges by one extrusion width, to ensure reasonable anchoring whenever possible
+                        true_bridge = intersection_ex(layerm->slices().surfaces,
+                                                      offset_ex(true_bridge, layerm->bridging_flow(frSolidInfill).scaled_spacing()));
+                        surfaces_append(bottom, true_bridge, surface_type_bottom_other);
                         // if user requested internal shells, we need to identify surfaces
                         // lying on other slices not belonging to this region
                         if (interface_shells) {
diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp
index db9537edb..d934819bf 100644
--- a/src/libslic3r/utils.cpp
+++ b/src/libslic3r/utils.cpp
@@ -9,6 +9,7 @@
 
 #include "Platform.hpp"
 #include "Time.hpp"
+#include "format.hpp"
 #include "libslic3r.h"
 
 #ifdef WIN32