diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index 74039bacc..2a595d36a 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -59,6 +59,13 @@ extern BoundingBox get_extents_rotated(const Polygon &poly, double angle); extern BoundingBox get_extents_rotated(const Polygons &polygons, double angle); extern std::vector get_extents_vector(const Polygons &polygons); +inline double total_length(const Polygons &polylines) { + double total = 0; + for (Polygons::const_iterator it = polylines.begin(); it != polylines.end(); ++it) + total += it->length(); + return total; +} + // Remove sticks (tentacles with zero area) from the polygon. extern bool remove_sticks(Polygon &poly); extern bool remove_sticks(Polygons &polys); diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index d304ba19a..ac59c6378 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -69,6 +69,13 @@ public: extern BoundingBox get_extents(const Polyline &polyline); extern BoundingBox get_extents(const Polylines &polylines); +inline double total_length(const Polylines &polylines) { + double total = 0; + for (Polylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it) + total += it->length(); + return total; +} + inline Lines to_lines(const Polyline &poly) { Lines lines; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 1f58d308d..9b4a0e7e4 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -204,7 +204,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("extra_perimeters", coBool); def->label = "Extra perimeters if needed"; def->category = "Layers and Perimeters"; - def->tooltip = "Add more perimeters when needed for avoiding gaps in sloping walls."; + def->tooltip = "Add more perimeters when needed for avoiding gaps in sloping walls. Slic3r keeps adding perimeters, until more than 70% of the loop immediately above is supported."; def->cli = "extra-perimeters!"; def->default_value = new ConfigOptionBool(true); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 1c1d0113e..94001cb38 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -1168,10 +1168,7 @@ PrintObject::_make_perimeters() // Filter upper layer polygons in intersection_ppl by their bounding boxes? // my $upper_layerm_poly_bboxes= [ map $_->bounding_box, @{$upper_layerm_polygons} ]; - double total_loop_length = 0; - for (Polygons::const_iterator it = upper_layerm_polygons.begin(); it != upper_layerm_polygons.end(); ++it) - total_loop_length += it->length(); - + const double total_loop_length = total_length(upper_layerm_polygons); const coord_t perimeter_spacing = layerm.flow(frPerimeter).scaled_spacing(); const Flow ext_perimeter_flow = layerm.flow(frExternalPerimeter); const coord_t ext_perimeter_width = ext_perimeter_flow.scaled_width(); @@ -1199,12 +1196,8 @@ PrintObject::_make_perimeters() ); // only add an additional loop if at least 30% of the slice loop would benefit from it - { - double total_intersection_length = 0; - for (Polylines::const_iterator it = intersection.begin(); it != intersection.end(); ++it) - total_intersection_length += it->length(); - if (total_intersection_length <= total_loop_length*0.3) break; - } + if (total_length(intersection) <= total_loop_length*0.3) + break; /* if (0) {