Skip to content

Commit

Permalink
Gradual overhang speed: Make sure to avoid microsegments.
Browse files Browse the repository at this point in the history
Since the speed regions can 'too' small as well, we need to make sure we don't create microsegments -- While there was already a mitigation earlier, Ihad to partially undo that to fix a bug, and now it's done in a more guaranteed, explicit way.

part of CURA-12352
  • Loading branch information
rburema committed Jan 16, 2025
1 parent 93907a5 commit 2cb9722
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/LayerPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,40 @@ void LayerPlan::addExtrusionMoveWithGradualOverhang(
// Pre-calculate the intersections of the segment with all regions (except last one, you cannot intersect an infinite plane)
const Point2LL end = p.toPoint2LL();
const Point2LL vector = end - start;
const coord_t segment_length = vSize(vector);
std::vector<std::vector<float>> speed_regions_intersections;
speed_regions_intersections.reserve(overhang_masks_.size() - 1);
for (const OverhangMask& overhang_region : overhang_masks_ | ranges::views::drop_last(1))
{
std::vector<float> intersections = overhang_region.supported_region.intersectionsWithSegment(start, end);
ranges::sort(intersections);

// Avoid microsegments: Move intersections that are too close to the start or end of the segment slightly more to the center of the segment.
for (float& intersection : intersections)
{
if (intersection * segment_length < MINIMUM_LINE_LENGTH)
{
intersection = MINIMUM_LINE_LENGTH / static_cast<float>(segment_length);
}
else if (intersection * segment_length > segment_length - MINIMUM_LINE_LENGTH)
{
intersection = (segment_length - MINIMUM_LINE_LENGTH) / static_cast<float>(segment_length);
}
}

// (Also) Avoid microsegments: Filter out pairs of intersections that are too close to each other.
// This should be possible because the intersections happen in the same region.
constexpr std::array<float, 1> dummy = { 2.0f };
std::vector<float> temp_intersections;
for (const auto& tup : ranges::views::concat(dummy, intersections, dummy) | ranges::views::sliding(3))
{
if ((tup[1] - tup[0]) * segment_length >= MINIMUM_LINE_LENGTH && (tup[2] - tup[1]) * segment_length >= MINIMUM_LINE_LENGTH)
{
temp_intersections.push_back(tup[1]);
}
}
intersections = temp_intersections;

speed_regions_intersections.push_back(intersections);
}

Expand Down

0 comments on commit 2cb9722

Please sign in to comment.