From df3e55d4a8e9ad711a640c8980254d318c710938 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 16 Oct 2023 14:41:34 +0200 Subject: [PATCH] SPE-1949 Fixed selection of closest point to center --- src/libslic3r/CutSurface.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 58c311476c..b2cf3d9659 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -1921,6 +1921,26 @@ uint32_t priv::find_closest_point_index(const Point &p, const std::vector &mask) { SearchData sd = create_search_data(shapes, mask); + if (sd.tree.nodes().size() == 0){ + // no lines in expolygon, check whether exist point to start + double closest_square_distance = INFINITY; + uint32_t closest_id = -1; + for (uint32_t i = 0; i < mask.size(); i++) + if (mask[i]){ + ExPolygonsIndex ei = s2i.cvt(i); + const Point& s_p = ei.is_contour()? + shapes[ei.expolygons_index].contour[ei.point_index]: + shapes[ei.expolygons_index].holes[ei.hole_index()][ei.point_index]; + double square_distance = (p - s_p).cast().squaredNorm(); + if (closest_id >= mask.size() || + closest_square_distance > square_distance) { + closest_id = i; + closest_square_distance = square_distance; + } + } + assert(closest_id < mask.size()); + return closest_id; + } size_t line_idx = std::numeric_limits::max(); Vec2d hit_point; Vec2d p_d = p.cast(); @@ -2226,7 +2246,11 @@ priv::ProjectionDistances priv::choose_best_distance( // Select point from shapes(text contour) which is closest to center (all in 2d) uint32_t unfinished_index = find_closest_point_index(start, shapes, s2i, mask_distances); - + assert(unfinished_index < s2i.get_count()); + if (unfinished_index >= s2i.get_count()) + // no point to select + return result; + #ifdef DEBUG_OUTPUT_DIR Connections connections; connections.reserve(shapes.size());