Avoid using auto as type of Eigen expressions. (#8577)

According to https://eigen.tuxfamily.org/dox/TopicPitfalls.html one
should just avoid using `auto` as the type of an Eigen expression.

This PR fixes most of them I could found in the project. There might be
cases that I missed, and I might update those later if I noticed.

This should prevent issues like #7741 and hopefully fix some mysterious
crashes happened inside Eigen calls.
This commit is contained in:
Noisyfox 2025-02-26 23:07:23 +08:00 committed by GitHub
parent 41584cfae3
commit 51916ff058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 45 additions and 45 deletions

View file

@ -121,7 +121,7 @@ void Bed_2D::repaint(const std::vector<Vec2d>& shape)
auto x_end = Vec2d(origin_px(0) + axes_len, origin_px(1));
dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(x_end(0), x_end(1)));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1));
Vec2d end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1));
dc.DrawLine(wxPoint(x_end(0), x_end(1)), wxPoint(end(0), end(1)));
}
@ -129,7 +129,7 @@ void Bed_2D::repaint(const std::vector<Vec2d>& shape)
auto y_end = Vec2d(origin_px(0), origin_px(1) - axes_len);
dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(y_end(0), y_end(1)));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len);
Vec2d end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len);
dc.DrawLine(wxPoint(y_end(0), y_end(1)), wxPoint(end(0), end(1)));
}

View file

@ -2470,11 +2470,11 @@ void GLGizmoMeasure::set_distance(bool same_model_object, const Vec3d &displacem
selection->set_mode(same_model_object ? Selection::Volume : Selection::Instance);
m_pending_scale ++;
if (same_model_object == false) {
auto object_displacement = v->get_instance_transformation().get_matrix_no_offset().inverse() * displacement;
Vec3d object_displacement = v->get_instance_transformation().get_matrix_no_offset().inverse() * displacement;
v->set_instance_transformation(v->get_instance_transformation().get_matrix() * Geometry::translation_transform(object_displacement));
} else {
Geometry::Transformation tran(v->world_matrix());
auto local_displacement = tran.get_matrix_no_offset().inverse() * displacement;
Vec3d local_displacement = tran.get_matrix_no_offset().inverse() * displacement;
v->set_volume_transformation(v->get_volume_transformation().get_matrix() * Geometry::translation_transform(local_displacement));
}
wxGetApp().plater()->canvas3D()->do_move("");
@ -2647,7 +2647,7 @@ void GLGizmoMeasure::set_parallel_distance(bool same_model_object, float dist)
const auto [idx2, normal2, pt2] = m_selected_features.second.feature->get_plane();
Vec3d proj_pt2;
Measure::get_point_projection_to_plane(pt2, pt1, normal1, proj_pt2);
auto new_pt2 = proj_pt2 + normal1 * dist;
Vec3d new_pt2 = proj_pt2 + normal1 * dist;
Vec3d displacement = new_pt2 - pt2;

View file

@ -596,7 +596,7 @@ Transform3d get_volume_transformation(
std::optional<float> current_angle,
const std::optional<double> &up_limit)
{
auto world_linear = world.linear();
auto world_linear = world.linear().eval();
// Calculate offset: transformation to wanted position
{
// Reset skew of the text Z axis:
@ -609,7 +609,7 @@ Transform3d get_volume_transformation(
Vec3d text_z_world = world_linear.col(2); // world_linear * Vec3d::UnitZ()
auto z_rotation = Eigen::Quaternion<double, Eigen::DontAlign>::FromTwoVectors(text_z_world, world_dir);
Transform3d world_new = z_rotation * world;
auto world_new_linear = world_new.linear();
auto world_new_linear = world_new.linear().eval();
// Fix direction of up vector to zero initial rotation
if(up_limit.has_value()){