Skip to content

Commit

Permalink
fix reversed perimeters
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Mar 27, 2023
2 parents 603c301 + 7c92519 commit a0ec413
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 180 deletions.
10 changes: 5 additions & 5 deletions src/libslic3r/Brim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,11 @@ void extrude_brim_from_tree(const Print& print, std::vector<std::vector<BrimLoop
for (Polyline& pline : to_cut.lines) {
assert(pline.size() > 0);
if (pline.back() == pline.front()) {
ExtrusionPath path(erSkirt, mm3_per_mm, width, height);
ExtrusionPath path(erSkirt, mm3_per_mm, width, height, false);
path.polyline = pline;
to_add.push_back(new ExtrusionLoop(std::move(path), elrSkirt));
} else {
ExtrusionPath* extrusion_path = new ExtrusionPath(erSkirt, mm3_per_mm, width, height);
ExtrusionPath* extrusion_path = new ExtrusionPath(erSkirt, mm3_per_mm, width, height, false);
to_add.push_back(extrusion_path);
extrusion_path->polyline = pline;
}
Expand All @@ -851,16 +851,16 @@ void extrude_brim_from_tree(const Print& print, std::vector<std::vector<BrimLoop
} else {
ExtrusionEntityCollection* print_me_first = new ExtrusionEntityCollection();
print_me_first->set_can_sort_reverse(false, false);
parent->append({ print_me_first });
parent->append(ExtrusionEntitiesPtr{ print_me_first });
ExtrusionEntitiesPtr to_add;
for (Polyline& pline : to_cut.lines) {
assert(pline.size() > 0);
if (pline.back() == pline.front()) {
ExtrusionPath path(erSkirt, mm3_per_mm, width, height);
ExtrusionPath path(erSkirt, mm3_per_mm, width, height, false);
path.polyline = pline;
to_add.push_back(new ExtrusionLoop(std::move(path), elrSkirt));
} else {
ExtrusionPath* extrusion_path = new ExtrusionPath(erSkirt, mm3_per_mm, width, height);
ExtrusionPath* extrusion_path = new ExtrusionPath(erSkirt, mm3_per_mm, width, height, false);
to_add.push_back(extrusion_path);
extrusion_path->polyline = pline;
}
Expand Down
29 changes: 22 additions & 7 deletions src/libslic3r/ClipperUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,22 +825,37 @@ ClipperLib_Z::Paths clip_extrusion(const ClipperLib_Z::Paths& subjects, const Cl
ClipperLib_Z::Clipper clipper;
clipper.ZFillFunction([](const ClipperLib_Z::IntPoint& e1bot, const ClipperLib_Z::IntPoint& e1top, const ClipperLib_Z::IntPoint& e2bot,
const ClipperLib_Z::IntPoint& e2top, ClipperLib_Z::IntPoint& pt) {
// The clipping contour may be simplified by clipping it with a bounding box of "subject" path.
// The clipping function used may produce self intersections outside of the "subject" bounding box. Such self intersections are
// harmless to the result of the clipping operation,
// Both ends of each edge belong to the same source: Either they are from subject or from clipping path.
assert(e1bot.z() >= 0 && e1top.z() >= 0);
assert(e2bot.z() >= 0 && e2top.z() >= 0);
assert((e1bot.z() == 0) == (e1top.z() == 0));
assert((e2bot.z() == 0) == (e2top.z() == 0));

// Start & end points of the clipped polyline (extrusion path with a non-zero width).
ClipperLib_Z::IntPoint start = e1bot;
ClipperLib_Z::IntPoint end = e1top;

if (start.z() <= 0 && end.z() <= 0) {
start = e2bot;
end = e2top;
}

assert(start.z() > 0 && end.z() > 0);
if (start.z() <= 0 && end.z() <= 0) {
// Self intersection on the source contour.
assert(start.z() == 0 && end.z() == 0);
pt.z() = 0;
} else {
// Interpolate extrusion line width.
assert(start.z() > 0 && end.z() > 0);

// Interpolate extrusion line width.
double length_sqr = (end - start).cast<double>().squaredNorm();
double dist_sqr = (pt - start).cast<double>().squaredNorm();
double t = std::sqrt(dist_sqr / length_sqr);
double length_sqr = (end - start).cast<double>().squaredNorm();
double dist_sqr = (pt - start).cast<double>().squaredNorm();
double t = std::sqrt(dist_sqr / length_sqr);

pt.z() = start.z() + coord_t((end.z() - start.z()) * t);
pt.z() = start.z() + coord_t((end.z() - start.z()) * t);
}
});

//TODO: //scale to have some more precision to do some Y-bugfix like in _clipper_pl_open
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/ExtrusionEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ void ExtrusionLoop::split_at(const Point &point, bool prefer_non_overhang, const

// now split path_idx in two parts
const ExtrusionPath &path = this->paths[path_idx];
ExtrusionPath p1(path.role(), path.mm3_per_mm, path.width, path.height);
ExtrusionPath p2(path.role(), path.mm3_per_mm, path.width, path.height);
ExtrusionPath p1(path.role(), path.mm3_per_mm, path.width, path.height, can_reverse());
ExtrusionPath p2(path.role(), path.mm3_per_mm, path.width, path.height, can_reverse());
path.polyline.split_at(p, &p1.polyline, &p2.polyline);

if (this->paths.size() == 1) {
Expand Down
Loading

0 comments on commit a0ec413

Please sign in to comment.