Skip to content

Commit

Permalink
Merge branch 'main' into CURA-10831
Browse files Browse the repository at this point in the history
  • Loading branch information
jellespijker committed Dec 5, 2023
2 parents effddef + 5c2ebd8 commit a7275c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/utils/polygonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>::max());
static size_t moveInside(const Polygons& polygons, Point2LL& from, int distance = 0, int64_t max_dist2 = std::numeric_limits<int64_t>::max());

/**
* \brief Moves the point \p from onto the nearest polygon or leaves the
Expand Down
17 changes: 9 additions & 8 deletions src/LayerPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t> 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++)
Expand All @@ -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
}
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/polygonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>::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)
Expand Down

0 comments on commit a7275c1

Please sign in to comment.