Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/CuraEngine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemco Burema <r.burema@ultimaker.com>2022-10-26 13:49:55 +0300
committerRemco Burema <r.burema@ultimaker.com>2022-10-26 13:49:55 +0300
commit39569fcaad94a3c6200897c86ba113af7b3b7bf2 (patch)
treedd438c9010084892d1a40c697c47008ffba7f386
parent4b454ffc1cfcc8f4376f590052c7c3ab010d32e3 (diff)
Use closure instead of function-struct (+ code style).
Also make formula more clear. (And slightly better -- if we ever had a ridiculus amount of extruders, it would become incorrect.) part of CURA-9066
-rw-r--r--include/SkirtBrim.h36
-rw-r--r--src/SkirtBrim.cpp4
2 files changed, 25 insertions, 15 deletions
diff --git a/include/SkirtBrim.h b/include/SkirtBrim.h
index 743dc3f28..a9f362517 100644
--- a/include/SkirtBrim.h
+++ b/include/SkirtBrim.h
@@ -22,15 +22,25 @@ private:
*/
struct Offset
{
- Offset(const Polygons* reference_outline, const size_t reference_idx, bool external_only, const coord_t offset_value, const coord_t total_offset, size_t inset_idx, const int extruder_nr, bool is_last)
- : reference_outline(reference_outline)
- , reference_idx(reference_idx)
- , external_only(external_only)
- , offset_value(offset_value)
- , total_offset(total_offset)
- , inset_idx(inset_idx)
- , extruder_nr(extruder_nr)
- , is_last(is_last)
+ Offset
+ (
+ const Polygons* reference_outline,
+ const size_t reference_idx,
+ bool external_only,
+ const coord_t offset_value,
+ const coord_t total_offset,
+ size_t inset_idx,
+ const int extruder_nr,
+ bool is_last
+ ) :
+ reference_outline(reference_outline),
+ reference_idx(reference_idx),
+ external_only(external_only),
+ offset_value(offset_value),
+ total_offset(total_offset),
+ inset_idx(inset_idx),
+ extruder_nr(extruder_nr),
+ is_last(is_last)
{}
const Polygons* reference_outline; //!< Optional reference polygons from which to offset
int reference_idx; //!< Optional reference index into storage.skirt_brim from which to offset
@@ -45,12 +55,12 @@ private:
/*!
* Defines an order on offsets (potentially from different extruders) based on how far the offset is from the original outline.
*/
- struct OffsetSorter
+ static inline const auto OffsetSorter
{
- bool operator()(const Offset& a, const Offset& b)
+ [](const Offset& a, const Offset& b)
{
- return a.total_offset + a.extruder_nr
- < b.total_offset + b.extruder_nr; // add extruder_nr so that it's more stable when both extruders have the same offset settings
+ // Use extruder_nr in case both extruders have the same offset settings.
+ return a.total_offset != b.total_offset ? a.total_offset < b.total_offset : a.extruder_nr < b.extruder_nr;
}
};
diff --git a/src/SkirtBrim.cpp b/src/SkirtBrim.cpp
index 34b141ab5..8f27db436 100644
--- a/src/SkirtBrim.cpp
+++ b/src/SkirtBrim.cpp
@@ -123,7 +123,7 @@ std::vector<SkirtBrim::Offset> SkirtBrim::generateBrimOffsetPlan(std::vector<Pol
}
}
- std::sort(all_brim_offsets.begin(), all_brim_offsets.end(), OffsetSorter{});
+ std::sort(all_brim_offsets.begin(), all_brim_offsets.end(), OffsetSorter);
return all_brim_offsets;
}
@@ -217,7 +217,7 @@ std::vector<coord_t> SkirtBrim::generatePrimaryBrim(std::vector<Offset>& all_bri
constexpr bool is_last = true;
constexpr Polygons* reference_outline = nullptr; // not used
all_brim_offsets.emplace_back(reference_outline, offset.inset_idx, external_polys_only[offset.extruder_nr], line_widths[offset.extruder_nr], offset.total_offset + line_widths[offset.extruder_nr], offset.inset_idx + 1, offset.extruder_nr, is_last);
- std::sort(all_brim_offsets.begin() + offset_idx + 1, all_brim_offsets.end(), OffsetSorter{}); // reorder remaining offsets
+ std::sort(all_brim_offsets.begin() + offset_idx + 1, all_brim_offsets.end(), OffsetSorter); // reorder remaining offsets
}
}
return total_length;