From 0143d532fe874309139873e245549e4ac3a4cf44 Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 3 Dec 2018 14:09:21 +0100 Subject: [PATCH] correct error with Polygon / ExPolygon --- xs/src/libslic3r/ExPolygon.cpp | 6 +++--- xs/src/libslic3r/MedialAxis.hpp | 3 ++- xs/src/libslic3r/PerimeterGenerator.cpp | 11 ++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index 8eef314e0d..87c119a04f 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -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; } } diff --git a/xs/src/libslic3r/MedialAxis.hpp b/xs/src/libslic3r/MedialAxis.hpp index c65cbdb84b..93f6725db2 100644 --- a/xs/src/libslic3r/MedialAxis.hpp +++ b/xs/src/libslic3r/MedialAxis.hpp @@ -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; diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index 165708929a..31ac2eaf2f 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -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()) {