ENH: improve align_to_Y_axis of A1 series printers

only rotate the object if its long axis is significanly larger than its short axis (more than 10%)

jira: none
Change-Id: I63fede8a55f8dc82f4388e630d58b2e62f7922b2
This commit is contained in:
Arthur 2025-01-23 16:07:32 +08:00 committed by lane.wei
parent 96512530b2
commit 2fbde46b4d
1 changed files with 9 additions and 2 deletions

View File

@ -885,8 +885,15 @@ void _arrange(
// polygon nesting, a convex hull needs to be calculated.
if (params.align_to_y_axis) {
for (auto &itm : shapes) {
auto angle = min_area_boundingbox_rotation(itm.transformedShape());
itm.rotate(angle + PI / 2);
// only rotate the object if its long axis is significanly larger than its short axis (more than 10%)
try {
auto bbox = minAreaBoundingBox<ExPolygon, TCompute<ExPolygon>, boost::rational<LargeInt>>(itm.transformedShape());
auto w = bbox.width(), h=bbox.height();
if (w > h * 1.1 || h > w * 1.1) { itm.rotate(bbox.angleToX() + PI / 2); }
} catch (const std::exception &e) {
// min_area_boundingbox_rotation may throw exception of dividing 0 if the object is already perfectly aligned to X
BOOST_LOG_TRIVIAL(error) << "arranging min_area_boundingbox_rotation fails, msg=" << e.what();
}
}
}
else if (params.allow_rotations) {