diff options
author | Sakari Kapanen <sakari.m.kapanen@gmail.com> | 2016-11-02 23:31:03 +0300 |
---|---|---|
committer | Sakari Kapanen <sakari.m.kapanen@gmail.com> | 2016-11-02 23:31:03 +0300 |
commit | 60ea0561ec901cde0b1a73cdf1f7a2d4b83704f3 (patch) | |
tree | 2ac989d11fc2cdc9508c735f21b21e9e07df5715 /xs | |
parent | 381c88ce0c71d0f0c149dc655090a9ad907b0faf (diff) |
Copy and move variants of chained_path functions
Diffstat (limited to 'xs')
-rw-r--r-- | xs/src/libslic3r/PolylineCollection.cpp | 52 | ||||
-rw-r--r-- | xs/src/libslic3r/PolylineCollection.hpp | 18 |
2 files changed, 44 insertions, 26 deletions
diff --git a/xs/src/libslic3r/PolylineCollection.cpp b/xs/src/libslic3r/PolylineCollection.cpp index d386d5ba5..ca46930c5 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<Chaining> &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<Chaining> endpoints; endpoints.reserve(src.size()); @@ -70,8 +70,12 @@ Polylines PolylineCollection::chained_path_from( // find nearest point int endpoint_index = nearest_point_index<double>(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); -} -Polylines PolylineCollection::chained_path_from(Polylines src, Point start_near, bool no_reverse) -{ - return chained_path_from(std::move(src), start_near, no_reverse); + _chained_path_from(src, src.front().first_point(), no_reverse, true); } -Polylines PolylineCollection::chained_path(Polylines src, bool no_reverse) + +Polylines PolylineCollection::chained_path_from(Polylines &&src, Point start_near, bool no_reverse) { - return (src.empty() || src.front().empty()) ? - Polylines() : - chained_path_from(std::move(src), src.front().first_point(), no_reverse); + return _chained_path_from(src, start_near, no_reverse, true); } -#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 f53e8a3a2..80d609410 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); }; } |