Skip to content

Commit

Permalink
Apply code cleaning suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Oct 31, 2024
1 parent 12491b4 commit 69c3e42
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
46 changes: 28 additions & 18 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ class LayerPlan : public NoCopy
* \param spiralize Whether to gradually increase the z height from the normal layer height to the height of the next layer over this polygon
* \param flow_ratio The ratio with which to multiply the extrusion amount
* \param always_retract Whether to force a retraction when moving to the start of the polygon (used for outer walls)
* \param scarf_seam Indicates whether we may use a scarf seam for the path
* \param smooth_speed Indicates whether we may use a speed gradient for the path
*/
void addPolygon(
const Polygon& polygon,
Expand All @@ -408,8 +410,7 @@ class LayerPlan : public NoCopy
const Ratio& flow_ratio = 1.0_r,
bool always_retract = false,
bool scarf_seam = false,
bool smooth_speed = false,
bool is_candidate_small_feature = false);
bool smooth_speed = false);

/*!
* Add polygons to the gcode with optimized order.
Expand Down Expand Up @@ -438,6 +439,8 @@ class LayerPlan : public NoCopy
* \param reverse_order Adds polygons in reverse order.
* \param start_near_location Start optimising the path near this location.
* If unset, this causes it to start near the last planned location.
* \param scarf_seam Indicates whether we may use a scarf seam for the path
* \param smooth_speed Indicates whether we may use a speed gradient for the path
*/
void addPolygonsByOptimizer(
const Shape& polygons,
Expand Down Expand Up @@ -535,6 +538,8 @@ class LayerPlan : public NoCopy
* polyline).
* \param is_reversed Whether to print this wall in reverse direction.
* \param is_linked_path Whether the path is a continuation off the previous path
* \param scarf_seam Indicates whether we may use a scarf seam for the path
* \param smooth_speed Indicates whether we may use a speed gradient for the path
*/
void addWall(
const ExtrusionLine& wall,
Expand Down Expand Up @@ -844,6 +849,23 @@ class LayerPlan : public NoCopy
PrintFeatureType feature,
bool update_extrusion_offset = false);

/*!
* \brief Alias for a function definition that adds an extrusion segment
* \param start The start position of the segment
* \param end The end position of the segment
* \param speed_factor The speed factor to be applied when extruding this specific segment (relative to nominal speed for the entire path)
* \param flow_ratio The flow ratio to be applied when extruding this specific segment (relative to nominal flow for the entire path)
* \param line_width_ratio The line width ratio to be applied when extruding this specific segment (relative to nominal line width for the entire path)
* \param distance_to_bridge_start The calculate distance to the next bridge start, which may be irrelevant in some cases
*/
using AddExtrusionSegmentFunction = std::function<void(
const Point3LL& start,
const Point3LL& end,
const Ratio& speed_factor,
const Ratio& flow_ratio,
const Ratio& line_width_ratio,
const coord_t distance_to_bridge_start)>;

/*!
* \brief Add a wall to the gcode with optimized order, but split into pieces in order to facilitate the scarf seam and/or speed gradient.
* \tparam PathType The type of path to be processed, either ExtrusionLine or some subclass of Polyline
Expand Down Expand Up @@ -902,13 +924,7 @@ class LayerPlan : public NoCopy
const coord_t decelerate_length,
const bool is_scarf_closure,
const bool compute_distance_to_bridge_start,
const std::function<void(
const Point3LL& start,
const Point3LL& end,
const Ratio& speed_factor,
const Ratio& flow_ratio,
const Ratio& line_width_ratio,
const coord_t distance_to_bridge_start)>& func_add_segment);
const AddExtrusionSegmentFunction& func_add_segment);

/*!
* \brief Add a wall to the gcode with optimized order, possibly adding a scarf seam / speed gradient according to settings
Expand All @@ -922,8 +938,8 @@ class LayerPlan : public NoCopy
* \param is_closed Indicates whether the path is closed (or open)
* \param is_reversed Indicates if the path is to be processed backwards
* \param is_candidate_small_feature Indicates whether the path should be tested for being treated as a smell feature
* \param scarf_seam Indicates whether we may set a scraf seam to the path
* \param smooth_speed Indicates whether we may set a speed gradient to the path
* \param scarf_seam Indicates whether we may use a scarf seam for the path
* \param smooth_speed Indicates whether we may use a speed gradient for the path
* \param func_add_segment The function to be called to actually add an extrusion segment with the given parameters
*/
template<class PathType>
Expand All @@ -939,13 +955,7 @@ class LayerPlan : public NoCopy
const bool is_candidate_small_feature,
const bool scarf_seam,
const bool smooth_speed,
const std::function<void(
const Point3LL& start,
const Point3LL& end,
const Ratio& speed_factor,
const Ratio& flow_ratio,
const Ratio& line_width_ratio,
const coord_t distance_to_bridge_start)>& func_add_segment);
const AddExtrusionSegmentFunction& func_add_segment);

/*!
* \brief Helper function to calculate the distance from the start of the current wall line to the first bridge segment
Expand Down
30 changes: 10 additions & 20 deletions src/LayerPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ void LayerPlan::addPolygon(
const Ratio& flow_ratio,
bool always_retract,
bool scarf_seam,
bool smooth_speed,
bool is_candidate_small_feature)
bool smooth_speed)
{
constexpr bool is_closed = true;
constexpr bool is_candidate_small_feature = false;

Point2LL p0 = polygon[start_idx];
addTravel(p0, always_retract, config.z_offset);
Expand Down Expand Up @@ -659,7 +659,7 @@ void LayerPlan::addPolygonsByOptimizer(
}
orderOptimizer.optimize();

auto add_polygons
const auto add_polygons
= [this, &config, &settings, &wall_0_wipe_dist, &spiralize, &flow_ratio, &always_retract, &scarf_seam, &smooth_speed](const auto& iterator_begin, const auto& iterator_end)
{
for (auto iterator = iterator_begin; iterator != iterator_end; ++iterator)
Expand Down Expand Up @@ -1065,13 +1065,7 @@ void LayerPlan::addSplitWall(
const coord_t decelerate_length,
const bool is_scarf_closure,
const bool compute_distance_to_bridge_start,
const std::function<void(
const Point3LL& start,
const Point3LL& end,
const Ratio& speed_factor,
const Ratio& flow_ratio,
const Ratio& line_width_ratio,
const coord_t distance_to_bridge_start)>& func_add_segment)
const AddExtrusionSegmentFunction& func_add_segment)
{
coord_t distance_to_bridge_start = 0; // will be updated before each line is processed
Point2LL p0 = wall.pointAt(start_idx);
Expand All @@ -1098,6 +1092,9 @@ void LayerPlan::addSplitWall(

if constexpr (std::is_same_v<PathType, ExtrusionLine>)
{
// The bridging functionality has not been designed to work with anything else than ExtrusionLine objects,
// and there is no need to do it otherwise yet. So the compute_distance_to_bridge_start argument will
// just be ignored if using an other PathType (e.g. Polygon)
if (compute_distance_to_bridge_start && ! bridge_wall_mask_.empty())
{
distance_to_bridge_start = computeDistanceToBridgeStart(wall.getPath(), (wall.size() + start_idx + point_idx * direction - 1) % wall.size(), min_bridge_line_len);
Expand Down Expand Up @@ -1368,13 +1365,7 @@ void LayerPlan::addWallWithScarfSeam(
const bool is_candidate_small_feature,
const bool scarf_seam,
const bool smooth_speed,
const std::function<void(
const Point3LL& start,
const Point3LL& end,
const Ratio& speed_factor,
const Ratio& flow_ratio,
const Ratio& line_width_ratio,
const coord_t distance_to_bridge_start)>& func_add_segment)
const AddExtrusionSegmentFunction& func_add_segment)
{
if (wall.empty())
{
Expand Down Expand Up @@ -1494,8 +1485,7 @@ void LayerPlan::addWall(
wall.inset_idx_ == 0,
scarf_seam,
smooth_speed,
[this, &settings, &default_config, &roofing_config, &bridge_config, &non_bridge_line_volume](
const Point3LL& start,
[&](const Point3LL& start,
const Point3LL& end,
const Ratio& speed_factor,
const Ratio& actual_flow_ratio,
Expand Down Expand Up @@ -2492,7 +2482,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode)

for (const auto& reversed_chunk : paths | ranges::views::enumerate | ranges::views::reverse
| ranges::views::chunk_by(
[](const auto&path_a, const auto&path_b)
[](const auto& path_a, const auto& path_b)
{
return (! std::get<1>(path_a).isTravelPath()) || std::get<1>(path_b).isTravelPath();
}))
Expand Down

0 comments on commit 69c3e42

Please sign in to comment.