From 82d5935a5eeab3834d925d543e558265cc2584d7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 9 Nov 2023 20:03:04 +0800 Subject: [PATCH] FIX: align to Y not working This is a bug introduced in 7fbb650 when solving jira STUDIO-4695. Now we use a more decent way to solve it. Change-Id: I92deffcb9fe53e8a24c93fe973446ae37df07375 (cherry picked from commit bd98430dbd15eb6c9bb4b447990e0dcf8a50eef0) --- 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 3483ae729..a9fc56015 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -228,16 +228,23 @@ void update_selected_items_axis_align(ArrangePolygons& selected, const DynamicPr double c = m02 / m00 - cy * cy; //if a and c are close, there is no dominant axis, then do not rotate - if (std::abs(a) < 1.5*std::abs(c) || std::abs(c) < 1.5*std::abs(a)) { + // ratio is always no more than 1 + double ratio = std::abs(a) > std::abs(c) ? std::abs(c / a) : + std::abs(c) > 0 ? std::abs(a / c) : 0; + if (ratio>0.66) { validResult = false; } else { angle = std::atan2(2 * b, (a - c)) / 2; + angle = PI / 2 - angle; + // if the angle is close to PI or -PI, it means the object is vertical, then do not rotate + if (std::abs(std::abs(angle) - PI) < 0.01) + angle = 0; validResult = true; } } } - if (validResult) { ap.rotation += (PI / 2 - angle); } + if (validResult) { ap.rotation += angle; } } }