Skip to content

Commit

Permalink
Fix missing polygons when using simplify
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wawanbreton committed May 8, 2024
1 parent 42ad756 commit 64e94c0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/geometry/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}

Expand Down

0 comments on commit 64e94c0

Please sign in to comment.