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); }