diff --git a/src/libslic3r/Arachne/utils/ExtrusionLine.hpp b/src/libslic3r/Arachne/utils/ExtrusionLine.hpp index 7ac1a3c4c..c0c5e7db1 100644 --- a/src/libslic3r/Arachne/utils/ExtrusionLine.hpp +++ b/src/libslic3r/Arachne/utils/ExtrusionLine.hpp @@ -14,7 +14,7 @@ #include "../../../clipper/clipper_z.hpp" namespace Slic3r { -class ThickPolyline; +struct ThickPolyline; } namespace Slic3r::Arachne diff --git a/src/libslic3r/ExPolygon.cpp b/src/libslic3r/ExPolygon.cpp index 8dc0ff547..dc991e46d 100644 --- a/src/libslic3r/ExPolygon.cpp +++ b/src/libslic3r/ExPolygon.cpp @@ -320,7 +320,9 @@ void ExPolygon::medial_axis(double min_width, double max_width, Polylines* polyl { ThickPolylines tp; this->medial_axis(min_width, max_width, &tp); - polylines->insert(polylines->end(), tp.begin(), tp.end()); + polylines->reserve(polylines->size() + tp.size()); + for (auto &pl : tp) + polylines->emplace_back(pl.points); } Lines ExPolygon::lines() const diff --git a/src/libslic3r/Geometry/MedialAxis.cpp b/src/libslic3r/Geometry/MedialAxis.cpp index c92796f41..4f614169c 100644 --- a/src/libslic3r/Geometry/MedialAxis.cpp +++ b/src/libslic3r/Geometry/MedialAxis.cpp @@ -498,6 +498,7 @@ void MedialAxis::build(ThickPolylines* polylines) polyline.width.emplace_back(seed_edge_data.width_end); // Grow the polyline in a forward direction. this->process_edge_neighbors(&*seed_edge, &polyline); + assert(polyline.width.size() == polyline.points.size() * 2 - 2); // Grow the polyline in a backward direction. reverse_polyline.clear(); @@ -505,7 +506,6 @@ void MedialAxis::build(ThickPolylines* polylines) polyline.points.insert(polyline.points.begin(), reverse_polyline.points.rbegin(), reverse_polyline.points.rend()); polyline.width.insert(polyline.width.begin(), reverse_polyline.width.rbegin(), reverse_polyline.width.rend()); polyline.endpoints.first = reverse_polyline.endpoints.second; - assert(polyline.width.size() == polyline.points.size() * 2 - 2); // Prevent loop endpoints from being extended. @@ -538,7 +538,9 @@ void MedialAxis::build(Polylines* polylines) { ThickPolylines tp; this->build(&tp); - polylines->insert(polylines->end(), tp.begin(), tp.end()); + polylines->reserve(polylines->size() + tp.size()); + for (auto &pl : tp) + polylines->emplace_back(pl.points); } void MedialAxis::process_edge_neighbors(const VD::edge_type *edge, ThickPolyline* polyline) diff --git a/src/libslic3r/Polyline.hpp b/src/libslic3r/Polyline.hpp index bee5e51ba..8ca8e4f16 100644 --- a/src/libslic3r/Polyline.hpp +++ b/src/libslic3r/Polyline.hpp @@ -10,7 +10,7 @@ namespace Slic3r { class Polyline; -class ThickPolyline; +struct ThickPolyline; typedef std::vector Polylines; typedef std::vector ThickPolylines; @@ -160,20 +160,28 @@ bool remove_degenerate(Polylines &polylines); // Returns index of a segment of a polyline and foot point of pt on polyline. std::pair foot_pt(const Points &polyline, const Point &pt); -class ThickPolyline : public Polyline { -public: - ThickPolyline() : endpoints(std::make_pair(false, false)) {} +struct ThickPolyline { + ThickPolyline() = default; ThickLines thicklines() const; + + const Point& first_point() const { return this->points.front(); } + const Point& last_point() const { return this->points.back(); } + bool is_valid() const { return this->points.size() >= 2; } + double length() const { return Slic3r::length(this->points); } + + void clear() { this->points.clear(); this->width.clear(); } + void reverse() { - Polyline::reverse(); + std::reverse(this->points.begin(), this->points.end()); std::reverse(this->width.begin(), this->width.end()); std::swap(this->endpoints.first, this->endpoints.second); } void clip_end(double distance); - std::vector width; - std::pair endpoints; + Points points; + std::vector width; + std::pair endpoints { false, false }; }; inline ThickPolylines to_thick_polylines(Polylines &&polylines, const coordf_t width) diff --git a/src/libslic3r/SVG.cpp b/src/libslic3r/SVG.cpp index d4088089b..4770334de 100644 --- a/src/libslic3r/SVG.cpp +++ b/src/libslic3r/SVG.cpp @@ -179,8 +179,8 @@ void SVG::draw(const ThickLines &thicklines, const std::string &fill, const std: void SVG::draw(const ThickPolylines &polylines, const std::string &stroke, coordf_t stroke_width) { - for (ThickPolylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it) - this->draw((Polyline)*it, stroke, stroke_width); + for (const ThickPolyline &pl : polylines) + this->draw(Polyline(pl.points), stroke, stroke_width); } void SVG::draw(const ThickPolylines &thickpolylines, const std::string &fill, const std::string &stroke, coordf_t stroke_width)