diff --git a/include/utils/polygonUtils.h b/include/utils/polygonUtils.h index 59d71a9354..ecda641626 100644 --- a/include/utils/polygonUtils.h +++ b/include/utils/polygonUtils.h @@ -207,7 +207,7 @@ class PolygonUtils * \param max_dist2 The squared maximal allowed distance from the point to the nearest polygon. * \return The index to the polygon onto which we have moved the point. */ - static unsigned int moveInside(const Polygons& polygons, Point2LL& from, int distance = 0, int64_t max_dist2 = std::numeric_limits::max()); + static size_t moveInside(const Polygons& polygons, Point2LL& from, int distance = 0, int64_t max_dist2 = std::numeric_limits::max()); /** * \brief Moves the point \p from onto the nearest polygon or leaves the diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 6077daa44d..7d4ede0d0f 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -2283,8 +2283,8 @@ bool LayerPlan::writePathWithCoasting( bool length_is_less_than_min_dist = true; - unsigned int acc_dist_idx_gt_coast_dist = NO_INDEX; // the index of the first point with accumulated_dist more than coasting_dist (= index into accumulated_dist_per_point) - // == the point printed BEFORE the start point for coasting + std::optional acc_dist_idx_gt_coast_dist; // the index of the first point with accumulated_dist more than coasting_dist (= index into accumulated_dist_per_point) + // == the point printed BEFORE the start point for coasting const Point2LL* last = &path.points[path.points.size() - 1]; for (unsigned int backward_point_idx = 1; backward_point_idx < path.points.size(); backward_point_idx++) @@ -2294,7 +2294,7 @@ bool LayerPlan::writePathWithCoasting( accumulated_dist += distance; accumulated_dist_per_point.push_back(accumulated_dist); - if (acc_dist_idx_gt_coast_dist == NO_INDEX && accumulated_dist >= coasting_dist) + if (! acc_dist_idx_gt_coast_dist.has_value() && accumulated_dist >= coasting_dist) { acc_dist_idx_gt_coast_dist = backward_point_idx; // the newly added point } @@ -2321,22 +2321,23 @@ bool LayerPlan::writePathWithCoasting( { return false; // Skip coasting at all then. } - for (acc_dist_idx_gt_coast_dist = 1; acc_dist_idx_gt_coast_dist < accumulated_dist_per_point.size(); acc_dist_idx_gt_coast_dist++) + for (acc_dist_idx_gt_coast_dist = 1; acc_dist_idx_gt_coast_dist.value() < accumulated_dist_per_point.size(); acc_dist_idx_gt_coast_dist.value()++) { // search for the correct coast_dist_idx - if (accumulated_dist_per_point[acc_dist_idx_gt_coast_dist] >= actual_coasting_dist) + if (accumulated_dist_per_point[acc_dist_idx_gt_coast_dist.value()] >= actual_coasting_dist) { break; } } } - assert(acc_dist_idx_gt_coast_dist < accumulated_dist_per_point.size()); // something has gone wrong; coasting_min_dist < coasting_dist ? + assert( + acc_dist_idx_gt_coast_dist.has_value() && acc_dist_idx_gt_coast_dist < accumulated_dist_per_point.size()); // something has gone wrong; coasting_min_dist < coasting_dist ? - const size_t point_idx_before_start = path.points.size() - 1 - acc_dist_idx_gt_coast_dist; + const size_t point_idx_before_start = path.points.size() - 1 - acc_dist_idx_gt_coast_dist.value(); Point2LL start; { // computation of begin point of coasting - const coord_t residual_dist = actual_coasting_dist - accumulated_dist_per_point[acc_dist_idx_gt_coast_dist - 1]; + const coord_t residual_dist = actual_coasting_dist - accumulated_dist_per_point[acc_dist_idx_gt_coast_dist.value() - 1]; const Point2LL& a = path.points[point_idx_before_start]; const Point2LL& b = path.points[point_idx_before_start + 1]; start = b + normal(a - b, residual_dist); diff --git a/src/utils/polygonUtils.cpp b/src/utils/polygonUtils.cpp index 42f9204a05..4855f34046 100644 --- a/src/utils/polygonUtils.cpp +++ b/src/utils/polygonUtils.cpp @@ -327,13 +327,13 @@ ClosestPolygonPoint PolygonUtils::_moveInside2(const ClosestPolygonPoint& closes /* * Implementation assumes moving inside, but moving outside should just as well be possible. */ -unsigned int PolygonUtils::moveInside(const Polygons& polygons, Point2LL& from, int distance, int64_t maxDist2) +size_t PolygonUtils::moveInside(const Polygons& polygons, Point2LL& from, int distance, int64_t maxDist2) { Point2LL ret = from; int64_t bestDist2 = std::numeric_limits::max(); - unsigned int bestPoly = NO_INDEX; + size_t bestPoly = NO_INDEX; bool is_already_on_correct_side_of_boundary = false; // whether [from] is already on the right side of the boundary - for (unsigned int poly_idx = 0; poly_idx < polygons.size(); poly_idx++) + for (size_t poly_idx = 0; poly_idx < polygons.size(); poly_idx++) { ConstPolygonRef poly = polygons[poly_idx]; if (poly.size() < 2)