diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 4a54aefc7..5dc281b51 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -414,15 +414,24 @@ void insert_points(std::vector &pl, int idx, Vec2f pos, int pair_ } } -Polylines remove_points_from_polygon(const Polygon &polygon, const std::vector &skip_points, double range, bool is_left ,Polygon& insert_skip_pg) +Polylines remove_points_from_polygon(const Polygon &polygon, const std::vector &skip_points, double range, bool is_left, Polygon &insert_skip_pg) { - Polylines result; - std::vector new_pl; // add intersection points for gaps, where bool indicates whether it's a gap point. + assert(polygon.size() > 2); + Polylines result; + std::vector new_pl; // add intersection points for gaps, where bool indicates whether it's a gap point. std::vector inter_info; Vec2f ray = is_left ? Vec2f(-1, 0) : Vec2f(1, 0); + auto polygon_box = get_extents(polygon); + Point anchor_point = is_left ? Point{polygon_box.max[0], polygon_box.min[1]} : polygon_box.min; // rd:ld std::vector points; - points.reserve(polygon.points.size()); - for (auto &p : polygon.points) points.push_back(unscale(p).cast()); + { + points.reserve(polygon.points.size()); + int idx = polygon.closest_point_index(anchor_point); + Polyline tmp_poly = polygon.split_at_index(idx); + for (auto &p : tmp_poly) points.push_back(unscale(p).cast()); + points.pop_back(); + } + for (int i = 0; i < skip_points.size(); i++) { for (int j = 0; j < points.size(); j++) { Vec2f& p1 = points[j]; @@ -453,30 +462,7 @@ Polylines remove_points_from_polygon(const Polygon &polygon, const std::vector