diff --git a/include/sliceDataStorage.h b/include/sliceDataStorage.h index 0c36cfbc54..749fb8bbbc 100644 --- a/include/sliceDataStorage.h +++ b/include/sliceDataStorage.h @@ -399,10 +399,7 @@ class SliceDataStorage : public NoCopy */ SliceDataStorage(); - ~SliceDataStorage() - { - delete prime_tower_; - } + ~SliceDataStorage(); /*! * Get all outlines within a given layer. diff --git a/include/utils/LayerVector.h b/include/utils/LayerVector.h index ab00bbb363..bdf99cd9ca 100644 --- a/include/utils/LayerVector.h +++ b/include/utils/LayerVector.h @@ -155,24 +155,24 @@ class LayerVector return value_type{}; } - [[nodiscard]] LayerIndex getLayer(const const_iterator& iterator) const + [[nodiscard]] LayerIndex getLayer(const const_iterator& it) const { - return std::distance(begin(), iterator) - delta_; + return std::distance(begin(), it) - static_cast(delta_); } - [[nodiscard]] LayerIndex getLayer(const iterator& iterator) const + [[nodiscard]] LayerIndex getLayer(const iterator& it) const { - return std::distance(begin(), iterator) - delta_; + return std::distance(begin(), it) - static_cast(delta_); } - [[nodiscard]] LayerIndex getLayer(const const_reverse_iterator& iterator) const + [[nodiscard]] LayerIndex getLayer(const const_reverse_iterator& it) const { - return std::distance(iterator, rend()) - 1 - delta_; + return std::distance(it, rend()) - 1 - static_cast(delta_); } - [[nodiscard]] LayerIndex getLayer(const reverse_iterator& iterator) const + [[nodiscard]] LayerIndex getLayer(const reverse_iterator& it) const { - return std::distance(iterator, rend()) - 1 - delta_; + return std::distance(it, rend()) - 1 - static_cast(delta_); } void pop_back() diff --git a/src/PrimeTower/PrimeTower.cpp b/src/PrimeTower/PrimeTower.cpp index 056cf2d9d2..b58b9c7dd7 100644 --- a/src/PrimeTower/PrimeTower.cpp +++ b/src/PrimeTower/PrimeTower.cpp @@ -60,8 +60,8 @@ PrimeTower::PrimeTower() for (coord_t z = 0; z < base_height; z += layer_height) { - double brim_radius_factor = std::pow((1.0 - static_cast(z) / base_height), base_curve_magnitude); - coord_t extra_radius = base_extra_radius * brim_radius_factor; + double brim_radius_factor = std::pow((1.0 - static_cast(z) / static_cast(base_height)), base_curve_magnitude); + coord_t extra_radius = std::llrint(static_cast(base_extra_radius) * brim_radius_factor); base_occupied_outline_.push_back(outer_poly_.offset(extra_radius)); } } @@ -366,21 +366,24 @@ bool PrimeTower::extruderRequiresPrime(const std::vector& extruder_is_used void PrimeTower::gotoStartLocation(LayerPlan& gcode_layer, const size_t extruder_nr) const { - if (gcode_layer.getLayerNr() != 0) + // Layer number may be negative, make it positive (or null) to apply modulo operator + LayerIndex layer_nr = gcode_layer.getLayerNr(); + while (layer_nr < 0) { - size_t current_start_location_idx = ((((extruder_nr + 1) * gcode_layer.getLayerNr()) % number_of_prime_tower_start_locations_) + number_of_prime_tower_start_locations_) - % number_of_prime_tower_start_locations_; - - const ClosestPointPolygon wipe_location = prime_tower_start_locations_[current_start_location_idx]; - const ExtruderTrain& train = Application::getInstance().current_slice_->scene.extruders[extruder_nr]; - const coord_t inward_dist = train.settings_.get("machine_nozzle_size") * 3 / 2; - const coord_t start_dist = train.settings_.get("machine_nozzle_size") * 2; - const Point2LL prime_end = PolygonUtils::moveInsideDiagonally(wipe_location, inward_dist); - const Point2LL outward_dir = wipe_location.location_ - prime_end; - const Point2LL prime_start = wipe_location.location_ + normal(outward_dir, start_dist); - - gcode_layer.addTravel(prime_start); + layer_nr += number_of_prime_tower_start_locations_; } + + size_t current_start_location_idx = ((extruder_nr + 1) * static_cast(layer_nr)) % number_of_prime_tower_start_locations_; + + const ClosestPointPolygon wipe_location = prime_tower_start_locations_[current_start_location_idx]; + const ExtruderTrain& train = Application::getInstance().current_slice_->scene.extruders[extruder_nr]; + const coord_t inward_dist = train.settings_.get("machine_nozzle_size") * 3 / 2; + const coord_t start_dist = train.settings_.get("machine_nozzle_size") * 2; + const Point2LL prime_end = PolygonUtils::moveInsideDiagonally(wipe_location, inward_dist); + const Point2LL outward_dir = wipe_location.location_ - prime_end; + const Point2LL prime_start = wipe_location.location_ + normal(outward_dir, start_dist); + + gcode_layer.addTravel(prime_start); } } // namespace cura diff --git a/src/sliceDataStorage.cpp b/src/sliceDataStorage.cpp index b16b130794..c030fc403d 100644 --- a/src/sliceDataStorage.cpp +++ b/src/sliceDataStorage.cpp @@ -270,6 +270,11 @@ SliceDataStorage::SliceDataStorage() machine_size.include(machine_max); } +SliceDataStorage::~SliceDataStorage() +{ + delete prime_tower_; +} + Shape SliceDataStorage::getLayerOutlines( const LayerIndex layer_nr, const bool include_support,