diff --git a/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp b/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp index 08439a63e5..4985231806 100644 --- a/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp +++ b/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp @@ -72,6 +72,7 @@ template<> struct ShapeTag { using Type = PointTag; }; template<> struct ShapeTag> { using Type = PathTag; }; template<> struct ShapeTag { using Type = PathTag; }; +template<> struct ShapeTag { using Type = PathTag; }; template<> struct ShapeTag { using Type = PolygonTag; }; template<> struct ShapeTag { using Type = MultiPolygonTag; }; @@ -104,11 +105,21 @@ struct OrientationType { static const constexpr Orientation Value = Orientation::COUNTER_CLOCKWISE; }; +template<> +struct OrientationType { + static const constexpr Orientation Value = Orientation::COUNTER_CLOCKWISE; +}; + template<> struct ClosureType { static const constexpr Closure Value = Closure::OPEN; }; +template<> +struct ClosureType { + static const constexpr Closure Value = Closure::OPEN; +}; + template<> struct MultiShape { using Type = Slic3r::ExPolygons; }; template<> struct ContourType { using Type = Slic3r::Polygon; }; diff --git a/src/libslic3r/MinAreaBoundingBox.cpp b/src/libslic3r/MinAreaBoundingBox.cpp index 15c04517d0..51fd8a45e7 100644 --- a/src/libslic3r/MinAreaBoundingBox.cpp +++ b/src/libslic3r/MinAreaBoundingBox.cpp @@ -14,55 +14,9 @@ #include #endif -#include +#include #include -namespace libnest2d { - -template<> struct PointType { using Type = Slic3r::Point; }; -template<> struct CoordType { using Type = coord_t; }; -template<> struct ShapeTag { using Type = PolygonTag; }; -template<> struct ShapeTag { using Type = PolygonTag; }; -template<> struct ShapeTag { using Type = PathTag; }; -template<> struct ShapeTag { using Type = PointTag; }; -template<> struct ContourType { using Type = Slic3r::Points; }; -template<> struct ContourType { using Type = Slic3r::Points; }; - -namespace pointlike { - -template<> inline coord_t x(const Slic3r::Point& p) { return p.x(); } -template<> inline coord_t y(const Slic3r::Point& p) { return p.y(); } -template<> inline coord_t& x(Slic3r::Point& p) { return p.x(); } -template<> inline coord_t& y(Slic3r::Point& p) { return p.y(); } - -} // pointlike - -namespace shapelike { -template<> inline Slic3r::Points& contour(Slic3r::ExPolygon& sh) { return sh.contour.points; } -template<> inline const Slic3r::Points& contour(const Slic3r::ExPolygon& sh) { return sh.contour.points; } -template<> inline Slic3r::Points& contour(Slic3r::Polygon& sh) { return sh.points; } -template<> inline const Slic3r::Points& contour(const Slic3r::Polygon& sh) { return sh.points; } - -template<> Slic3r::Points::iterator begin(Slic3r::Points& pts, const PathTag&) { return pts.begin();} -template<> Slic3r::Points::const_iterator cbegin(const Slic3r::Points& pts, const PathTag&) { return pts.cbegin(); } -template<> Slic3r::Points::iterator end(Slic3r::Points& pts, const PathTag&) { return pts.end();} -template<> Slic3r::Points::const_iterator cend(const Slic3r::Points& pts, const PathTag&) { return pts.cend(); } - -template<> inline Slic3r::ExPolygon create(Slic3r::Points&& contour) -{ - Slic3r::ExPolygon expoly; expoly.contour.points.swap(contour); - return expoly; -} - -template<> inline Slic3r::Polygon create(Slic3r::Points&& contour) -{ - Slic3r::Polygon poly; poly.points.swap(contour); - return poly; -} - -} // shapelike -} // libnest2d - namespace Slic3r { // Used as compute type. @@ -74,13 +28,22 @@ using Rational = boost::rational; using Rational = boost::rational<__int128>; #endif +template +libnest2d::RotatedBox minAreaBoundigBox_( + const P &p, MinAreaBoundigBox::PolygonLevel lvl) +{ + P chull = lvl == MinAreaBoundigBox::pcConvex ? + p : + libnest2d::sl::convexHull(p); + + libnest2d::removeCollinearPoints(chull); + + return libnest2d::minAreaBoundingBox(chull); +} + MinAreaBoundigBox::MinAreaBoundigBox(const Polygon &p, PolygonLevel pc) { - const Polygon &chull = pc == pcConvex ? p : - libnest2d::sl::convexHull(p); - - libnest2d::RotatedBox box = - libnest2d::minAreaBoundingBox(chull); + libnest2d::RotatedBox box = minAreaBoundigBox_(p, pc); m_right = libnest2d::cast(box.right_extent()); m_bottom = libnest2d::cast(box.bottom_extent()); @@ -89,11 +52,7 @@ MinAreaBoundigBox::MinAreaBoundigBox(const Polygon &p, PolygonLevel pc) MinAreaBoundigBox::MinAreaBoundigBox(const ExPolygon &p, PolygonLevel pc) { - const ExPolygon &chull = pc == pcConvex ? p : - libnest2d::sl::convexHull(p); - - libnest2d::RotatedBox box = - libnest2d::minAreaBoundingBox(chull); + libnest2d::RotatedBox box = minAreaBoundigBox_(p, pc); m_right = libnest2d::cast(box.right_extent()); m_bottom = libnest2d::cast(box.bottom_extent()); @@ -102,11 +61,7 @@ MinAreaBoundigBox::MinAreaBoundigBox(const ExPolygon &p, PolygonLevel pc) MinAreaBoundigBox::MinAreaBoundigBox(const Points &pts, PolygonLevel pc) { - const Points &chull = pc == pcConvex ? pts : - libnest2d::sl::convexHull(pts); - - libnest2d::RotatedBox box = - libnest2d::minAreaBoundingBox(chull); + libnest2d::RotatedBox box = minAreaBoundigBox_(pts, pc); m_right = libnest2d::cast(box.right_extent()); m_bottom = libnest2d::cast(box.bottom_extent()); diff --git a/src/libslic3r/MinAreaBoundingBox.hpp b/src/libslic3r/MinAreaBoundingBox.hpp index 30d0e9799d..242fc96111 100644 --- a/src/libslic3r/MinAreaBoundingBox.hpp +++ b/src/libslic3r/MinAreaBoundingBox.hpp @@ -26,12 +26,8 @@ public: }; // Constructors with various types of geometry data used in Slic3r. - // If the convexity is known apriory, pcConvex can be used to skip - // convex hull calculation. It is very important that the input polygons - // do NOT have any collinear points (except for the first and the last - // vertex being the same -- meaning a closed polygon for boost) - // To make sure this constraint is satisfied, you can call - // remove_collinear_points on the input polygon before handing over here) + // If the convexity is known apriory, pcConvex can be used to skip + // convex hull calculation. explicit MinAreaBoundigBox(const Polygon&, PolygonLevel = pcSimple); explicit MinAreaBoundigBox(const ExPolygon&, PolygonLevel = pcSimple); explicit MinAreaBoundigBox(const Points&, PolygonLevel = pcSimple); diff --git a/src/libslic3r/SLA/SupportPointGenerator.cpp b/src/libslic3r/SLA/SupportPointGenerator.cpp index 0d4eb4547e..5ef4eb0016 100644 --- a/src/libslic3r/SLA/SupportPointGenerator.cpp +++ b/src/libslic3r/SLA/SupportPointGenerator.cpp @@ -12,11 +12,9 @@ #include "ClipperUtils.hpp" #include "Tesselate.hpp" #include "ExPolygonCollection.hpp" +#include "MinAreaBoundingBox.hpp" #include "libslic3r.h" -#include "libnest2d/backends/libslic3r/geometries.hpp" -#include "libnest2d/utils/rotcalipers.hpp" - #include #include @@ -554,7 +552,7 @@ void SupportPointGenerator::uniformly_cover(const ExPolygons& islands, Structure if (flags & icfIsNew) { auto chull = ExPolygonCollection{islands}.convex_hull(); - auto rotbox = libnest2d::minAreaBoundingBox(chull); + auto rotbox = MinAreaBoundigBox{chull, MinAreaBoundigBox::pcConvex}; Vec2d bbdim = {unscaled(rotbox.width()), unscaled(rotbox.height())}; if (bbdim.x() > bbdim.y()) std::swap(bbdim.x(), bbdim.y());