From e17e6b4d0e6974eb560ee8c86dff1a28f91d271a Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 20 Nov 2020 09:28:09 +0100 Subject: [PATCH] Add minimum bounding box rotation as starting point --- src/libslic3r/Arrange.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 00656a629..e581f4c0f 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -449,6 +450,12 @@ template void remove_large_items(std::vector &items, Bin &&bin) ++it : it = items.erase(it); } +template Radians min_area_boundingbox_rotation(const S &sh) +{ + return minAreaBoundingBox, boost::rational>(sh) + .angleToX(); +} + template // Arrange for arbitrary bin type void _arrange( std::vector & shapes, @@ -483,6 +490,13 @@ void _arrange( for (auto &itm : shapes ) inp.emplace_back(itm); for (auto &itm : excludes) inp.emplace_back(itm); + // Use the minimum bounding box rotation as a starting point. + // TODO: This only works for convex hull. If we ever switch to concave + // polygon nesting, a convex hull needs to be calculated. + if (params.allow_rotations) + for (auto &itm : shapes) + itm.rotation(min_area_boundingbox_rotation(itm.rawShape())); + arranger(inp.begin(), inp.end()); for (Item &itm : inp) itm.inflate(-infl); }