From 60ea0561ec901cde0b1a73cdf1f7a2d4b83704f3 Mon Sep 17 00:00:00 2001 From: Sakari Kapanen Date: Wed, 2 Nov 2016 22:31:03 +0200 Subject: [PATCH] Copy and move variants of chained_path functions --- xs/src/libslic3r/PolylineCollection.cpp | 54 +++++++++++++++---------- xs/src/libslic3r/PolylineCollection.hpp | 18 ++++++--- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/xs/src/libslic3r/PolylineCollection.cpp b/xs/src/libslic3r/PolylineCollection.cpp index d386d5ba5c..ca46930c5b 100644 --- a/xs/src/libslic3r/PolylineCollection.cpp +++ b/xs/src/libslic3r/PolylineCollection.cpp @@ -46,14 +46,14 @@ inline int nearest_point_index(const std::vector &pairs, const Point & return idx; } -Polylines PolylineCollection::chained_path_from( -#if SLIC3R_CPPVER >= 11 - Polylines &&src, -#else +Polylines PolylineCollection::_chained_path_from( const Polylines &src, + Point start_near, + bool no_reverse +#if SLIC3R_CPPVER >= 11 + , bool move_from_src #endif - Point start_near, - bool no_reverse) + ) { std::vector endpoints; endpoints.reserve(src.size()); @@ -70,8 +70,12 @@ Polylines PolylineCollection::chained_path_from( // find nearest point int endpoint_index = nearest_point_index(endpoints, start_near, no_reverse); assert(endpoint_index >= 0 && endpoint_index < endpoints.size() * 2); -#if SLIC3R_CPPVER >= 11 - retval.push_back(std::move(src[endpoints[endpoint_index/2].idx])); +#if SLIC3R_CPPVER > 11 + if (move_from_src) { + retval.push_back(std::move(src[endpoints[endpoint_index/2].idx])); + } else { + retval.push_back(src[endpoints[endpoint_index/2].idx]); + } #else retval.push_back(src[endpoints[endpoint_index/2].idx]); #endif @@ -86,28 +90,36 @@ Polylines PolylineCollection::chained_path_from( #if SLIC3R_CPPVER >= 11 Polylines PolylineCollection::chained_path(Polylines &&src, bool no_reverse) { - return (src.empty() || src.front().empty()) ? + return (src.empty() || src.front().points.empty()) ? Polylines() : - chained_path_from(std::move(src), src.front().first_point(), no_reverse); + _chained_path_from(src, src.front().first_point(), no_reverse, true); } -Polylines PolylineCollection::chained_path_from(Polylines src, Point start_near, bool no_reverse) + +Polylines PolylineCollection::chained_path_from(Polylines &&src, Point start_near, bool no_reverse) { - return chained_path_from(std::move(src), start_near, no_reverse); + return _chained_path_from(src, start_near, no_reverse, true); } -Polylines PolylineCollection::chained_path(Polylines src, bool no_reverse) -{ - return (src.empty() || src.front().empty()) ? - Polylines() : - chained_path_from(std::move(src), src.front().first_point(), no_reverse); -} -#else +#endif + Polylines PolylineCollection::chained_path(const Polylines &src, bool no_reverse) { return (src.empty() || src.front().points.empty()) ? Polylines() : - chained_path_from(src, src.front().first_point(), no_reverse); -} + _chained_path_from(src, src.front().first_point(), no_reverse +#if SLIC3R_CPPVER >= 11 + , false #endif + ); +} + +Polylines PolylineCollection::chained_path_from(const Polylines &src, Point start_near, bool no_reverse) +{ + return _chained_path_from(src, start_near, no_reverse +#if SLIC3R_CPPVER >= 11 + , false +#endif + ); +} Point PolylineCollection::leftmost_point(const Polylines &polylines) { diff --git a/xs/src/libslic3r/PolylineCollection.hpp b/xs/src/libslic3r/PolylineCollection.hpp index f53e8a3a2d..80d609410d 100644 --- a/xs/src/libslic3r/PolylineCollection.hpp +++ b/xs/src/libslic3r/PolylineCollection.hpp @@ -8,11 +8,20 @@ namespace Slic3r { class PolylineCollection { + static Polylines _chained_path_from( + const Polylines &src, + Point start_near, + bool no_reverse +#if SLIC3R_CPPVER >= 11 + , bool move_from_src +#endif + ); + public: Polylines polylines; void chained_path(PolylineCollection* retval, bool no_reverse = false) const { retval->polylines = chained_path(this->polylines, no_reverse); } - void chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse = false) const + void chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse = false) const { retval->polylines = chained_path_from(this->polylines, start_near, no_reverse); } Point leftmost_point() const { return leftmost_point(polylines); } @@ -22,12 +31,9 @@ public: #if SLIC3R_CPPVER >= 11 static Polylines chained_path(Polylines &&src, bool no_reverse = false); static Polylines chained_path_from(Polylines &&src, Point start_near, bool no_reverse = false); - static Polylines chained_path(Polylines src, bool no_reverse = false); - static Polylines chained_path_from(Polylines src, Point start_near, bool no_reverse = false); -#else - static Polylines chained_path(const Polylines &src, bool no_reverse = false); - static Polylines chained_path_from(const Polylines &src, Point start_near, bool no_reverse = false); #endif + static Polylines chained_path(const Polylines &src, bool no_reverse = false); + static Polylines chained_path_from(const Polylines &src, Point start_near, bool no_reverse = false); }; }