Skip to content

Commit

Permalink
Use lambda to avoid code duplication
Browse files Browse the repository at this point in the history
CURA 11395
  • Loading branch information
casperlamboo committed Jan 9, 2024
1 parent 68d0de9 commit cf6f772
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,19 @@ void Raft::generate(SliceDataStorage& storage)
storage.raftInterfaceOutline = storage.raftInterfaceOutline.unionPolygons(ooze_shield_raft);
}

if (settings.get<bool>("raft_base_remove_inside_corners"))
{
storage.raftBaseOutline.makeConvex();
}
else
{
const coord_t smoothing = settings.get<coord_t>("raft_base_smoothing");
storage.raftBaseOutline = storage.raftBaseOutline.offset(smoothing, ClipperLib::jtRound).offset(-smoothing, ClipperLib::jtRound);
}

if (settings.get<bool>("raft_interface_remove_inside_corners"))
{
storage.raftInterfaceOutline.makeConvex();
}
else
{
const coord_t smoothing = settings.get<coord_t>("raft_interface_smoothing");
storage.raftInterfaceOutline = storage.raftInterfaceOutline.offset(smoothing, ClipperLib::jtRound).offset(-smoothing, ClipperLib::jtRound);
}

if (settings.get<bool>("raft_surface_remove_inside_corners"))
{
storage.raftSurfaceOutline.makeConvex();
}
else
{
const coord_t smoothing = settings.get<coord_t>("raft_surface_smoothing");
storage.raftSurfaceOutline = storage.raftSurfaceOutline.offset(smoothing, ClipperLib::jtRound).offset(-smoothing, ClipperLib::jtRound);
}
const auto remove_inside_corners = [&settings, &storage](Polygons& outline, bool remove_inside_corners, coord_t smoothing) {
if (remove_inside_corners)
{
outline.makeConvex();
}
else
{
outline = outline.offset(smoothing, ClipperLib::jtRound).offset(-smoothing, ClipperLib::jtRound);
}
};
remove_inside_corners(storage.raftBaseOutline, settings.get<bool>("raft_base_remove_inside_corners"), settings.get<coord_t>("raft_base_smoothing"));
remove_inside_corners(storage.raftInterfaceOutline, settings.get<bool>("raft_interface_remove_inside_corners"), settings.get<coord_t>("raft_interface_smoothing"));
remove_inside_corners(storage.raftSurfaceOutline, settings.get<bool>("raft_surface_remove_inside_corners"), settings.get<coord_t>("raft_surface_smoothing"));

if (storage.primeTower.enabled_ && ! storage.primeTower.would_have_actual_tower_)
{
Expand Down

0 comments on commit cf6f772

Please sign in to comment.