From 0d70bbba8b94ada8d7efd6c9ba50e70afadcc485 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 16 Sep 2022 11:24:44 +0200 Subject: [PATCH] Measuring: Use eigen library in distance calculations for Gizmo measure --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index bc8905152..bfcef7365 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -70,23 +70,22 @@ static std::string point_on_feature_type_as_string(Measure::SurfaceFeatureType t static std::tuple distance_point_plane(const Vec3d& v, const Plane& p) { - const double distance = std::get<1>(p).dot(v - std::get<2>(p)); - return std::make_tuple(std::abs(distance), v, v - distance * std::get<1>(p)); + const auto& [idx, normal, origin] = p; + const Eigen::Hyperplane plane(normal, origin); + return std::make_tuple(plane.absDistance(v), v, plane.projection(v)); } static std::tuple distance_point_edge(const Vec3d& v, const Edge& e) { - const Vec3d e1v = v - e.first; - const Vec3d e1e2_unit = (e.second - e.first).normalized(); - const Vec3d v_proj = e.first + e1e2_unit.dot(e1v) * e1e2_unit; - return std::make_tuple((e1v - v_proj).norm(), v, v_proj); + const Eigen::ParametrizedLine line(e.first, (e.second - e.first).normalized()); + return std::make_tuple(line.distance(v), v, line.projection(v)); } static std::tuple distance_point_circle(const Vec3d& v, const Circle& c) { const auto& [center, radius, normal] = c; - const auto [distance, v1, v2] = distance_point_plane(v, std::make_tuple(0, normal, center)); - const Vec3d p_on_circle = center + radius * (v2 - center).normalized(); + const Eigen::Hyperplane plane(normal, center); + const Vec3d p_on_circle = center + radius * (plane.projection(v) - center).normalized(); return std::make_tuple((v - p_on_circle).norm(), v, p_on_circle); }