From 2fbde46b4d6c7891725db2fec3b26ea6402677cb Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 23 Jan 2025 16:07:32 +0800 Subject: [PATCH] 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 --- src/libslic3r/Arrange.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 49198b345..279b635ee 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -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, boost::rational>(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) {