From 9939da998e70221875e69ae913371e049b203c76 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 12 Jun 2024 16:27:36 +0200 Subject: [PATCH] Clean code and add documentation --- include/utils/LayerVector.h | 18 +++++++++++------- include/utils/polygonUtils.h | 9 --------- src/FffGcodeWriter.cpp | 2 +- src/sliceDataStorage.cpp | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/utils/LayerVector.h b/include/utils/LayerVector.h index bdf99cd9ca..40afd423b8 100644 --- a/include/utils/LayerVector.h +++ b/include/utils/LayerVector.h @@ -15,8 +15,9 @@ namespace cura /*! * \brief The LayerVector class mimics a std::vector but with the index being a LayerIndex, thus it can have negative * values (for raft layers). - * \note At instantiation, LayerVector will call Raft::getTotalExtraLayers() so it requires the settings to be setup. - * After that, it is assumed that this value will not change while the vector is used. + * \note When calling the init() method, LayerVector will call Raft::getTotalExtraLayers() so it requires the settings + * to be setup. This is the reason why this is not done in the constructor, and has to be called manually. + * After that, it is assumed that this value will not change as long as the vector is used. * \warning It is assumed that items are inserted in layer order, and without missing items, like a std::vector would do */ template @@ -33,15 +34,13 @@ class LayerVector using difference_type = typename std::vector::difference_type; public: - LayerVector() - { - } + LayerVector() = default; /*! * \brief Initializes the vector for use * \param contains_raft_layers Indicates whether this vector will contain raft layers - * \param total_print_layers The number of print layers (not including raft layers). This is only for pre-reserving - * stored data and can be safely omitted. + * \param print_layers The number of print layers (not including raft layers). This is only for pre-reserving + * stored data and can be safely omitted. * \note It is not mandatory to call this method if you do not intend to store raft layers, but still good practice */ void init(bool contains_raft_layers, size_t print_layers = 0) @@ -145,6 +144,11 @@ class LayerVector return end(); } + /*! + * \brief Safe method to retrieve an element from the list + * \param pos The position of the element to be retrieved + * \return The element at the given position, or if there is none, a default-constructed value. + */ value_type get(const LayerIndex& pos) const noexcept { LayerIndex::value_type index = pos + delta_; diff --git a/include/utils/polygonUtils.h b/include/utils/polygonUtils.h index cefc8e2fe6..80e8fc5801 100644 --- a/include/utils/polygonUtils.h +++ b/include/utils/polygonUtils.h @@ -715,15 +715,6 @@ class PolygonUtils namespace std { -/*template -struct hash> -{ - size_t operator()(const std::pair& pair) const - { - return 31 * std::hash()(pair.first) + 59 * std::hash()(pair.second); - } -};*/ - template<> struct hash { diff --git a/src/FffGcodeWriter.cpp b/src/FffGcodeWriter.cpp index c2f48297ce..413143f4e7 100644 --- a/src/FffGcodeWriter.cpp +++ b/src/FffGcodeWriter.cpp @@ -2463,7 +2463,7 @@ size_t FffGcodeWriter::findUsedExtruderIndex(const SliceDataStorage& storage, co } else { - // Asking for extruder on an empty layer, get the one from layer below + // Asking for extruder on an empty layer, get the last one from layer below return findUsedExtruderIndex(storage, layer_nr - 1, true); } } diff --git a/src/sliceDataStorage.cpp b/src/sliceDataStorage.cpp index 9e479c6c2b..a419f75680 100644 --- a/src/sliceDataStorage.cpp +++ b/src/sliceDataStorage.cpp @@ -639,7 +639,7 @@ Shape SliceDataStorage::getMachineBorder(int checking_extruder_nr) const Point2LL translation(extruder_settings.get("machine_nozzle_offset_x"), extruder_settings.get("machine_nozzle_offset_y")); prime_pos -= translation; Shape prime_polygons; - prime_polygons.emplace_back(PolygonUtils::makeCircle(prime_pos, prime_clearance, 32)); + prime_polygons.emplace_back(PolygonUtils::makeCircle(prime_pos, prime_clearance, 64)); disallowed_areas = disallowed_areas.unionPolygons(prime_polygons); }