Skip to content

Commit

Permalink
Make line-overlap detection more conservative.
Browse files Browse the repository at this point in the history
(Tried a lot of other things as well, which makes it less predictable.) Clean up experiments, bring it back to basics, be quite conservative as this is only a patch and solving the whole 'scan-segments can be too close to the connector paths' probably requires properly rewriting the zig-zag algorithm -- which is way more like a feature.

part of CURA-11597
  • Loading branch information
rburema committed Apr 11, 2024
1 parent 7206bc9 commit f05f538
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/infill/ZigzagConnectorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class ZigzagConnectorProcessor
*/
void addZagConnector(std::vector<Point2LL>& points, bool is_endpiece);

bool handleConnectorToCloseToSegment(const coord_t scanline_x, const coord_t min_distance_to_scanline);

protected:
const PointMatrix& rotation_matrix_; //!< The rotation matrix used to enforce the infill angle
Polygons& result_; //!< The result of the computation
Expand Down
2 changes: 1 addition & 1 deletion src/infill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void Infill::generateLinearBasedInfill(
assert(scanline_idx - scanline_min_idx >= 0 && scanline_idx - scanline_min_idx < int(cut_list.size()) && "reading infill cutlist index out of bounds!");
cut_list[scanline_idx - scanline_min_idx].push_back(y);
Point2LL scanline_linesegment_intersection(x, y);
zigzag_connector_processor.registerScanlineSegmentIntersection(scanline_linesegment_intersection, scanline_idx, line_distance / 2);
zigzag_connector_processor.registerScanlineSegmentIntersection(scanline_linesegment_intersection, scanline_idx, line_distance / 4);
crossings_per_scanline[scanline_idx - min_scanline_index].emplace_back(scanline_linesegment_intersection, poly_idx, point_idx);
}
zigzag_connector_processor.registerVertex(p1);
Expand Down
24 changes: 12 additions & 12 deletions src/infill/ZigzagConnectorProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ bool ZigzagConnectorProcessor::shouldAddCurrentConnector(int start_scanline_idx,
return should_add;
}

bool ZigzagConnectorProcessor::handleConnectorToCloseToSegment(const coord_t scanline_x, const coord_t min_distance_to_scanline)
{
bool all_within_min_dist = ! current_connector_.empty();
for (const auto& point : current_connector_)
{
all_within_min_dist &= std::abs(point.X - scanline_x) < min_distance_to_scanline;
}
return all_within_min_dist;
}

void ZigzagConnectorProcessor::registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index, coord_t min_distance_to_scanline)
{
Expand All @@ -97,20 +106,11 @@ void ZigzagConnectorProcessor::registerScanlineSegmentIntersection(const Point2L
else
{
// add the current connector if needed
if (shouldAddCurrentConnector(last_connector_index_, scanline_index))
if (shouldAddCurrentConnector(last_connector_index_, scanline_index) && ! handleConnectorToCloseToSegment(intersection.X, min_distance_to_scanline))
{
const bool is_this_endpiece = scanline_index == last_connector_index_;
bool close_to_line_except_intersect = true;
const coord_t min_dist2 = min_distance_to_scanline * min_distance_to_scanline;
for (const auto& point : current_connector_)
{
close_to_line_except_intersect &= std::abs(point.X - intersection.X) < min_distance_to_scanline;
}
if (current_connector_.empty() || ! close_to_line_except_intersect)
{
current_connector_.push_back(intersection);
addZagConnector(current_connector_, is_this_endpiece);
}
current_connector_.push_back(intersection);
addZagConnector(current_connector_, is_this_endpiece);
}
}

Expand Down

0 comments on commit f05f538

Please sign in to comment.