Skip to content

Commit

Permalink
Minor code cleaning and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Apr 17, 2024
1 parent eeec963 commit 5139274
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/infill/ZigzagConnectorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ 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);
bool handleConnectorTooCloseToSegment(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
Expand Down
21 changes: 15 additions & 6 deletions src/infill/ZigzagConnectorProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,23 @@ 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 ZigzagConnectorProcessor::handleConnectorTooCloseToSegment(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_)
if (current_connector_.empty())
{
all_within_min_dist &= std::abs(point.X - scanline_x) < min_distance_to_scanline;
return false;
}
else
{
return std::find_if(
current_connector_.begin(),
current_connector_.end(),
[scanline_x, min_distance_to_scanline](const Point2LL& point)
{
return std::abs(point.X - scanline_x) >= min_distance_to_scanline;
})
== current_connector_.end();
}
return all_within_min_dist;
}

void ZigzagConnectorProcessor::registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index, coord_t min_distance_to_scanline)
Expand All @@ -106,7 +115,7 @@ void ZigzagConnectorProcessor::registerScanlineSegmentIntersection(const Point2L
else
{
// add the current connector if needed
if (shouldAddCurrentConnector(last_connector_index_, scanline_index) && ! handleConnectorToCloseToSegment(intersection.X, min_distance_to_scanline))
if (shouldAddCurrentConnector(last_connector_index_, scanline_index) && ! handleConnectorTooCloseToSegment(intersection.X, min_distance_to_scanline))
{
const bool is_this_endpiece = scanline_index == last_connector_index_;
current_connector_.push_back(intersection);
Expand Down

0 comments on commit 5139274

Please sign in to comment.