Skip to content

Commit

Permalink
Fix a clipper bug when a line in a polyline is horizontal.
Browse files Browse the repository at this point in the history
Have to do a hack to prevent horizontal lines.
If someone can modify clipper to take into account this corner case,
please submit a fix. But maybe it's better to go to clipper2 directly.
Note: I tested with clipper 6.4.2, but it doesn't fix this bug.
supermerill#1624
  • Loading branch information
supermerill committed Oct 9, 2021
1 parent 812dfdb commit 37838be
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/libslic3r/ClipperUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,21 @@ ClipperLib::PolyTree _clipper_do_pl(const ClipperLib::ClipType clipType, const P
// read input
ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject);
ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(clip);


//perform y safing : if a line is on the same Y, clipper may not pick the good point.
std::set<coord_t> bad_y;
for (ClipperLib::Paths* input : {&input_subject, &input_clip} )
for (ClipperLib::Path& path : *input) {
coord_t lasty = 0;
for (ClipperLib::IntPoint& pt : path) {
if (lasty == pt.Y) {
pt.Y+=1;
bad_y.insert(pt.Y);
}
lasty = pt.Y;
}
}

// perform safety offset
if (safety_offset_) safety_offset(&input_clip);

Expand All @@ -613,6 +627,23 @@ ClipperLib::PolyTree _clipper_do_pl(const ClipperLib::ClipType clipType, const P
// perform operation
ClipperLib::PolyTree retval;
clipper.Execute(clipType, retval, fillType, fillType);

//restore good y
if (!bad_y.empty()) {
std::vector<ClipperLib::PolyNode*> to_check;
to_check.push_back(&retval);
while (!to_check.empty()) {
ClipperLib::PolyNode* node = to_check.back();
to_check.pop_back();
for (ClipperLib::IntPoint& pt : node->Contour) {
if (bad_y.find(pt.Y) != bad_y.end()) {
pt.Y-=1;
}
}
to_check.insert(to_check.end(), node->Childs.begin(), node->Childs.end());
}
}

return retval;
}

Expand Down

0 comments on commit 37838be

Please sign in to comment.