From 64e94c086ccbf31c59f1de333f0d30dc0543596f Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 8 May 2024 17:09:30 +0200 Subject: [PATCH] Fix missing polygons when using simplify When simplifying polygons, more polygons could be returned than initially. The new simplify implementation didn't handle this case, and polygons could be lost. We now resize the list to the proper polygons count. CURA-9830 --- src/geometry/Shape.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/geometry/Shape.cpp b/src/geometry/Shape.cpp index 2145ec5d70..8156bb5fa2 100644 --- a/src/geometry/Shape.cpp +++ b/src/geometry/Shape.cpp @@ -842,16 +842,20 @@ void Shape::simplify(ClipperLib::PolyFillType fill_type) } // This is the actual content from clipper.cpp::SimplifyPolygons, but rewritten here in order - // to avoid a list copy + // to avoid having to put all the polygons in a transitory list ClipperLib::Clipper clipper; ClipperLib::Paths ret; clipper.StrictlySimple(true); addPaths(clipper, ClipperLib::ptSubject); clipper.Execute(ClipperLib::ctUnion, ret, fill_type, fill_type); - for (size_t i = 0; i < size(); ++i) + resize(ret.size()); + + for (size_t i = 0; i < ret.size(); i++) { - getLines()[i].setPoints(std::move(ret[i])); + Polygon& polygon = getLines()[i]; + polygon.setExplicitelyClosed(clipper_explicitely_closed_); // Required for polygon newly created by resize() + polygon.setPoints(std::move(ret[i])); } }