From cf6f7723790391cb00d077bc2f640c2b69eb9f12 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Tue, 9 Jan 2024 09:23:09 +0100 Subject: [PATCH] Use lambda to avoid code duplication CURA 11395 --- src/raft.cpp | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/raft.cpp b/src/raft.cpp index 233f93a40b..a8a23cf21e 100644 --- a/src/raft.cpp +++ b/src/raft.cpp @@ -51,35 +51,19 @@ void Raft::generate(SliceDataStorage& storage) storage.raftInterfaceOutline = storage.raftInterfaceOutline.unionPolygons(ooze_shield_raft); } - if (settings.get("raft_base_remove_inside_corners")) - { - storage.raftBaseOutline.makeConvex(); - } - else - { - const coord_t smoothing = settings.get("raft_base_smoothing"); - storage.raftBaseOutline = storage.raftBaseOutline.offset(smoothing, ClipperLib::jtRound).offset(-smoothing, ClipperLib::jtRound); - } - - if (settings.get("raft_interface_remove_inside_corners")) - { - storage.raftInterfaceOutline.makeConvex(); - } - else - { - const coord_t smoothing = settings.get("raft_interface_smoothing"); - storage.raftInterfaceOutline = storage.raftInterfaceOutline.offset(smoothing, ClipperLib::jtRound).offset(-smoothing, ClipperLib::jtRound); - } - - if (settings.get("raft_surface_remove_inside_corners")) - { - storage.raftSurfaceOutline.makeConvex(); - } - else - { - const coord_t smoothing = settings.get("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("raft_base_remove_inside_corners"), settings.get("raft_base_smoothing")); + remove_inside_corners(storage.raftInterfaceOutline, settings.get("raft_interface_remove_inside_corners"), settings.get("raft_interface_smoothing")); + remove_inside_corners(storage.raftSurfaceOutline, settings.get("raft_surface_remove_inside_corners"), settings.get("raft_surface_smoothing")); if (storage.primeTower.enabled_ && ! storage.primeTower.would_have_actual_tower_) {