From bcfbe02c8d1adba805d87e00209df2a269b6faee Mon Sep 17 00:00:00 2001 From: bubnikv Date: Sun, 10 Apr 2016 19:12:32 +0200 Subject: [PATCH] New method to rotate only polygons, not translate. New free function to_polygons. Whithout this function one needs to construct the ExPolygonCollection, which means a deep copy. --- xs/src/libslic3r/ExPolygon.cpp | 9 +++++++++ xs/src/libslic3r/ExPolygon.hpp | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index c84812fdf..ee40a3e06 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -52,6 +52,15 @@ ExPolygon::translate(double x, double y) } } +void +ExPolygon::rotate(double angle) +{ + contour.rotate(angle); + for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) { + (*it).rotate(angle); + } +} + void ExPolygon::rotate(double angle, const Point ¢er) { diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index f23178cc0..938913cea 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -20,6 +20,7 @@ class ExPolygon operator Polygons() const; void scale(double factor); void translate(double x, double y); + void rotate(double angle); void rotate(double angle, const Point ¢er); double area() const; bool is_valid() const; @@ -44,6 +45,32 @@ class ExPolygon Lines lines() const; }; +inline Polygons to_polygons(const ExPolygons &src) +{ + Polygons polygons; + for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) { + polygons.push_back(it->contour); + for (Polygons::const_iterator ith = it->holes.begin(); ith != it->holes.end(); ++ith) { + polygons.push_back(*ith); + } + } + return polygons; +} + +#if SLIC3R_CPPVER > 11 +inline Polygons to_polygons(ExPolygons &&src) +{ + Polygons polygons; + for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) { + polygons.push_back(std::move(it->contour)); + for (Polygons::const_iterator ith = it->holes.begin(); ith != it->holes.end(); ++ith) { + polygons.push_back(std::move(*ith)); + } + } + return polygons; +} +#endif + } // start Boost