From a09c2695842609ee5c01cbf7dda26b0372e6d702 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 8 Nov 2022 12:15:14 +0100 Subject: [PATCH] Measurement: make the edge endpoint detection threshold smaller for short edges --- src/libslic3r/Measure.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index fc27f0383e..26de9f0a6e 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -10,7 +10,6 @@ namespace Measure { constexpr double feature_hover_limit = 0.5; // how close to a feature the mouse must be to highlight it -constexpr double edge_endpoint_limit = 0.5; // how close to an edge endpoint the mouse ... static std::pair get_center_and_radius(const std::vector& border, int start_idx, int end_idx, const Transform3d& trafo) { @@ -467,6 +466,8 @@ std::optional MeasuringImpl::get_feature(size_t face_idx, const MeasurementResult res; SurfaceFeature point_sf(point); + assert(plane.surface_features.empty() || plane.surface_features.back().get_type() == SurfaceFeatureType::Plane); + for (size_t i=0; i MeasuringImpl::get_feature(size_t face_idx, const const SurfaceFeature& f = plane.surface_features[closest_feature_idx]; if (f.get_type() == SurfaceFeatureType::Edge) { // If this is an edge, check if we are not close to the endpoint. If so, - // we will include the endpoint as well. - constexpr double limit_sq = edge_endpoint_limit * edge_endpoint_limit; + // we will include the endpoint as well. Close = 10% of the lenghth of + // the edge, clamped between 0.025 and 0.5 mm. const auto& [sp, ep] = f.get_edge(); + double len_sq = (ep-sp).squaredNorm(); + double limit_sq = std::max(0.025*0.025, std::min(0.5*0.5, 0.1 * 0.1 * len_sq)); + if ((point-sp).squaredNorm() < limit_sq) return std::make_optional(SurfaceFeature(sp)); if ((point-ep).squaredNorm() < limit_sq)