Skip to content

Commit

Permalink
correct error with Polygon / ExPolygon
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Dec 3, 2018
1 parent 418c770 commit 0143d53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions xs/src/libslic3r/ExPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ void
ExPolygon::remove_point_too_near(const coord_t tolerance) {
size_t id = 1;
while (id < this->contour.points.size() - 1) {
size_t newdist = min(this->contour.points[id].distance_to(this->contour.points[id - 1])
double newdist = min(this->contour.points[id].distance_to(this->contour.points[id - 1])
, this->contour.points[id].distance_to(this->contour.points[id + 1]));
if (newdist < tolerance) {
if (newdist < (double)tolerance) {
this->contour.points.erase(this->contour.points.begin() + id);
newdist = this->contour.points[id].distance_to(this->contour.points[id - 1]);
}
//go to next one
//if you removed a point, it check if the next one isn't too near from the previous one.
// if not, it byepass it.
if (newdist > tolerance) {
if (newdist > (double)tolerance) {
++id;
}
}
Expand Down
3 changes: 2 additions & 1 deletion xs/src/libslic3r/MedialAxis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ namespace Slic3r {
public:
Lines lines; //lines is here only to avoid appassing it in argument of amny method. Initialized in polyline_from_voronoi.
ExPolygon expolygon;
const ExPolygon& bounds;
const ExPolygon& surface;
const ExPolygon& bounds;
const double max_width;
const double min_width;
const double height;
Expand Down
11 changes: 6 additions & 5 deletions xs/src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,21 @@ PerimeterGenerator::process()
// medial axis requires non-overlapping geometry
Polygons thin_zones = diff(last, no_thin_zone, true);
//don't use offset2_ex, because we don't want to merge the zones that have been separated.
Polygons expp = offset(thin_zones, (float)(-min_width / 2));
ExPolygons expp = offset_ex(thin_zones, (float)(-min_width / 2));
//we push the bits removed and put them into what we will use as our anchor
if (expp.size() > 0) {
no_thin_zone = diff(last, offset(expp, (float)(min_width / 2)), true);
no_thin_zone = diff(last, to_polygons(offset_ex(expp, (float)(min_width / 2))), true);
}
// compute a bit of overlap to anchor thin walls inside the print.
for (Polygon &ex : expp) {
for (ExPolygon &ex : expp) {
//growing back the polygon
//a very little bit of overlap can be created here with other thin polygons, but it's more useful than worisome.
ex.remove_point_too_near(SCALED_RESOLUTION);
ExPolygons ex_bigger = offset_ex(ex, (float)(min_width / 2));
if (ex_bigger.size() != 1) continue; // impossible error, growing a single polygon can't create multiple or 0.
ExPolygons anchor = intersection_ex(offset(ex, (float)(ext_pwidth / 2),
CLIPPER_OFFSET_SCALE, jtSquare, 3), no_thin_zone, true);
ExPolygons anchor = intersection_ex(
to_polygons(offset_ex(ex, (float)(ext_pwidth / 2), CLIPPER_OFFSET_SCALE, jtSquare, 3)),
no_thin_zone, true);
ExPolygons bounds = _clipper_ex(ClipperLib::ctUnion, to_polygons(ex_bigger), to_polygons(anchor), true);
for (ExPolygon &bound : bounds) {
if (!intersection_ex(ex_bigger[0], bound).empty()) {
Expand Down

0 comments on commit 0143d53

Please sign in to comment.