Don't split tiny cracks on first layer (#9917)

Don't split tiny cracks on first layer to get an uninterrupted bottom surface
This commit is contained in:
Noisyfox 2025-06-17 19:22:16 +08:00 committed by GitHub
parent 5041e0772e
commit 1aee8a0783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1382,24 +1382,26 @@ void PrintObject::detect_surfaces_type()
if (! top.empty() && ! bottom.empty()) {
const auto cracks = intersection_ex(top, bottom);
if (!cracks.empty()) {
const float small_crack_threshold = -layerm->flow(frExternalPerimeter).scaled_width() * 1.5;
for (const auto& crack : cracks) {
if (offset_ex(crack, small_crack_threshold).empty()) {
// For small cracks, if it's part of a large bottom surface, then it should be added to bottom as well
if (std::any_of(bottom.begin(), bottom.end(), [&crack, small_crack_threshold](const Surface& s) {
const auto& se = s.expolygon;
return diff_ex(crack, se, ApplySafetyOffset::Yes).empty()
&& se.area() > crack.area() * 2
&& !offset_ex(diff_ex(se, crack), small_crack_threshold).empty();
})) continue;
if (lower_layer) { // Only detect small cracks for non-first layer, because first layer should always be bottom
const float small_crack_threshold = -layerm->flow(frExternalPerimeter).scaled_width() * 1.5;
for (const auto& crack : cracks) {
if (offset_ex(crack, small_crack_threshold).empty()) {
// For small cracks, if it's part of a large bottom surface, then it should be added to bottom as well
if (std::any_of(bottom.begin(), bottom.end(), [&crack, small_crack_threshold](const Surface& s) {
const auto& se = s.expolygon;
return diff_ex(crack, se, ApplySafetyOffset::Yes).empty()
&& se.area() > crack.area() * 2
&& !offset_ex(diff_ex(se, crack), small_crack_threshold).empty();
})) continue;
// Crack too small, leave it as part of the top surface, remove it from bottom surfaces
Surfaces bot_tmp;
for (auto& b : bottom) {
surfaces_append(bot_tmp, diff_ex(b.expolygon, offset_ex(crack, -small_crack_threshold)), b.surface_type);
// Crack too small, leave it as part of the top surface, remove it from bottom surfaces
Surfaces bot_tmp;
for (auto& b : bottom) {
surfaces_append(bot_tmp, diff_ex(b.expolygon, offset_ex(crack, -small_crack_threshold)), b.surface_type);
}
bottom = std::move(bot_tmp);
}
bottom = std::move(bot_tmp);
}
}