From 643d50813d62004f8ad7cf3f2aa6ecfc582d839c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 26 Jan 2023 10:00:35 +0100 Subject: [PATCH] Removed function double rotation_diff_z(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to) and remaining code using it --- src/libslic3r/Geometry.cpp | 16 +--------------- src/libslic3r/Geometry.hpp | 1 - src/libslic3r/Model.cpp | 2 +- src/libslic3r/PrintObject.cpp | 4 ++-- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index 7bab0ed7a0..441825654c 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -872,24 +872,10 @@ Eigen::Quaterniond rotation_xyz_diff(const Vec3d &rot_xyz_from, const Vec3d &rot } // This should only be called if it is known, that the two rotations only differ in rotation around the Z axis. -double rotation_diff_z(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to) -{ - const Eigen::AngleAxisd angle_axis(rotation_xyz_diff(rot_xyz_from, rot_xyz_to)); - const Vec3d& axis = angle_axis.axis(); - const double angle = angle_axis.angle(); -#ifndef NDEBUG - if (std::abs(angle) > 1e-8) { - assert(std::abs(axis.x()) < 1e-8); - assert(std::abs(axis.y()) < 1e-8); - } -#endif /* NDEBUG */ - return (axis.z() < 0) ? -angle : angle; -} - double rotation_diff_z(const Transform3d &trafo_from, const Transform3d &trafo_to) { auto m = trafo_to.linear() * trafo_from.linear().inverse(); - assert(std::abs(m.determinant() - 1)); + assert(std::abs(m.determinant() - 1) < EPSILON); Vec3d vx = m * Vec3d(1., 0., 0); // Verify that the linear part of rotation from trafo_from to trafo_to rotates around Z and is unity. assert(std::abs(std::hypot(vx.x(), vx.y()) - 1.) < 1e-5); diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index d7cf326114..0421c08068 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -546,7 +546,6 @@ extern Transform3d transform3d_from_string(const std::string& transform_str); extern Eigen::Quaterniond rotation_xyz_diff(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to); // Rotation by Z to align rot_xyz_from to rot_xyz_to. // This should only be called if it is known, that the two rotations only differ in rotation around the Z axis. -extern double rotation_diff_z(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to); extern double rotation_diff_z(const Transform3d &trafo_from, const Transform3d &trafo_to); // Is the angle close to a multiple of 90 degrees? diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index b823eb4fab..bdd9bfd705 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1780,7 +1780,7 @@ void ModelObject::bake_xy_rotation_into_meshes(size_t instance_idx) // Adjust the instances. for (size_t i = 0; i < this->instances.size(); ++ i) { ModelInstance &model_instance = *this->instances[i]; - model_instance.set_rotation(Vec3d(0., 0., Geometry::rotation_diff_z(reference_trafo.get_rotation(), model_instance.get_rotation()))); + model_instance.set_rotation(Vec3d(0., 0., Geometry::rotation_diff_z(reference_trafo.get_matrix(), model_instance.get_matrix()))); model_instance.set_scaling_factor(Vec3d(new_scaling_factor, new_scaling_factor, new_scaling_factor)); model_instance.set_mirror(Vec3d(1., 1., 1.)); } diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index dc75fb8a32..dfa280f459 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -69,8 +69,8 @@ PrintObject::PrintObject(Print* print, ModelObject* model_object, const Transfor BoundingBoxf3 bbox = model_object->raw_bounding_box(); Vec3d bbox_center = bbox.center(); // We may need to rotate the bbox / bbox_center from the original instance to the current instance. - double z_diff = Geometry::rotation_diff_z(model_object->instances.front()->get_rotation(), instances.front().model_instance->get_rotation()); - if (std::abs(z_diff) > EPSILON) { + double z_diff = Geometry::rotation_diff_z(model_object->instances.front()->get_matrix(), instances.front().model_instance->get_matrix()); + if (std::abs(z_diff) > EPSILON) { auto z_rot = Eigen::AngleAxisd(z_diff, Vec3d::UnitZ()); bbox = bbox.transformed(Transform3d(z_rot)); bbox_center = (z_rot * bbox_center).eval();