Some refactoring and const correctness fixes.
This commit is contained in:
parent
70bc392003
commit
81187e7e0e
3 changed files with 21 additions and 21 deletions
|
@ -289,13 +289,13 @@ public:
|
|||
throw std::runtime_error("ConfigOptionVector::set_at(): Assigning an incompatible type");
|
||||
}
|
||||
|
||||
T& get_at(size_t i)
|
||||
const T& get_at(size_t i) const
|
||||
{
|
||||
assert(! this->values.empty());
|
||||
return (i < this->values.size()) ? this->values[i] : this->values.front();
|
||||
}
|
||||
|
||||
const T& get_at(size_t i) const { return const_cast<ConfigOptionVector<T>*>(this)->get_at(i); }
|
||||
T& get_at(size_t i) { return const_cast<T&>(std::as_const(*this).get_at(i)); }
|
||||
|
||||
// Resize this vector by duplicating the /*last*/first value.
|
||||
// If the current vector is empty, the default value is used instead.
|
||||
|
|
|
@ -394,7 +394,21 @@ void ToolOrdering::collect_extruder_statistics(bool prime_multi_material)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const LayerTools& ToolOrdering::tools_for_layer(coordf_t print_z) const
|
||||
{
|
||||
auto it_layer_tools = std::lower_bound(m_layer_tools.begin(), m_layer_tools.end(), LayerTools(print_z - EPSILON));
|
||||
assert(it_layer_tools != m_layer_tools.end());
|
||||
coordf_t dist_min = std::abs(it_layer_tools->print_z - print_z);
|
||||
for (++ it_layer_tools; it_layer_tools != m_layer_tools.end(); ++ it_layer_tools) {
|
||||
coordf_t d = std::abs(it_layer_tools->print_z - print_z);
|
||||
if (d >= dist_min)
|
||||
break;
|
||||
dist_min = d;
|
||||
}
|
||||
-- it_layer_tools;
|
||||
assert(dist_min < EPSILON);
|
||||
return *it_layer_tools;
|
||||
}
|
||||
|
||||
// This function is called from Print::mark_wiping_extrusions and sets extruder this entity should be printed with (-1 .. as usual)
|
||||
void WipingExtrusions::set_extruder_override(const ExtrusionEntity* entity, unsigned int copy_id, int extruder, unsigned int num_of_copies)
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "../libslic3r.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Print;
|
||||
|
@ -123,25 +125,9 @@ public:
|
|||
// For a multi-material print, the printing extruders are ordered in the order they shall be primed.
|
||||
const std::vector<unsigned int>& all_extruders() const { return m_all_printing_extruders; }
|
||||
|
||||
template<class Self> static auto tools_for_layer(Self& self, coordf_t print_z) -> decltype (*self.m_layer_tools.begin())
|
||||
{
|
||||
auto it_layer_tools = std::lower_bound(self.m_layer_tools.begin(), self.m_layer_tools.end(), LayerTools(print_z - EPSILON));
|
||||
assert(it_layer_tools != self.m_layer_tools.end());
|
||||
coordf_t dist_min = std::abs(it_layer_tools->print_z - print_z);
|
||||
for (++ it_layer_tools; it_layer_tools != self.m_layer_tools.end(); ++it_layer_tools) {
|
||||
coordf_t d = std::abs(it_layer_tools->print_z - print_z);
|
||||
if (d >= dist_min)
|
||||
break;
|
||||
dist_min = d;
|
||||
}
|
||||
-- it_layer_tools;
|
||||
assert(dist_min < EPSILON);
|
||||
return *it_layer_tools;
|
||||
}
|
||||
|
||||
// Find LayerTools with the closest print_z.
|
||||
LayerTools& tools_for_layer(coordf_t print_z) { return tools_for_layer(*this, print_z); }
|
||||
const LayerTools& tools_for_layer(coordf_t print_z) const { return tools_for_layer(*this, print_z); }
|
||||
const LayerTools& tools_for_layer(coordf_t print_z) const;
|
||||
LayerTools& tools_for_layer(coordf_t print_z) { return const_cast<LayerTools&>(std::as_const(*this).tools_for_layer(print_z)); }
|
||||
|
||||
const LayerTools& front() const { return m_layer_tools.front(); }
|
||||
const LayerTools& back() const { return m_layer_tools.back(); }
|
||||
|
|
Loading…
Reference in a new issue