diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index d19a71968..019c91c06 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -670,9 +670,8 @@ void SLAPrint::process() } // Just get the first record that is form the model: - auto slindex_it = po.closest_slice_record( - po.m_slice_index, float(bb3d.min(Z)), - std::numeric_limits::infinity()); + auto slindex_it = + po.closest_slice_record(po.m_slice_index, float(bb3d.min(Z))); if(slindex_it == po.m_slice_index.end()) throw std::runtime_error(L("Slicing had to be stopped " @@ -1272,7 +1271,7 @@ void SLAPrint::fill_statistics() int sliced_layer_cnt = 0; for (const SliceRecord& layer : highest_obj_slice_index) { - const double l_height = (layer.print_level() == highest_obj_slice_index.begin()->print_level()) ? init_layer_height : layer_height; + const auto l_height = double(layer.layer_height()); // Calculation of the consumed material @@ -1283,9 +1282,8 @@ void SLAPrint::fill_statistics() { const SliceRecord *record = nullptr; { - const SliceRecord& slr = po->closest_slice_to_slice_level(layer.slice_level(), float(EPSILON)); - if (!slr.is_valid()) - continue; + const SliceRecord& slr = po->closest_slice_to_slice_level(layer.slice_level()); + if (!slr.is_valid()) continue; record = &slr; } diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 626c5ead7..88152830f 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -124,7 +124,7 @@ public: // Returns the current layer height float layer_height() const { return m_height; } - bool is_valid() const { return std::isnan(m_slice_z); } + bool is_valid() const { return ! std::isnan(m_slice_z); } const SLAPrintObject* print_obj() const { return m_po; } @@ -158,7 +158,10 @@ private: // // This method can be used in const or non-const contexts as well. template - static auto closest_slice_record(Container& cont, T lvl, T eps) -> decltype (cont.begin()) + static auto closest_slice_record( + Container& cont, + T lvl, + T eps = std::numeric_limits::max()) -> decltype (cont.begin()) { if(cont.empty()) return cont.end(); if(cont.size() == 1 && std::abs(level(cont.front()) - lvl) > eps) @@ -207,22 +210,22 @@ public: // max_epsilon gives the allowable deviation of the returned slice record's // level. const SliceRecord& closest_slice_to_print_level( - coord_t print_level, coord_t max_epsilon = coord_t(SCALED_EPSILON)) const + coord_t print_level, + coord_t max_epsilon = std::numeric_limits::max()) const { auto it = closest_slice_record(m_slice_index, print_level, max_epsilon); - if (it == m_slice_index.end()) return SliceRecord::EMPTY; - return *it; + return it == m_slice_index.end() ? SliceRecord::EMPTY : *it; } // Search slice index for the closest slice to given slice_level. // max_epsilon gives the allowable deviation of the returned slice record's - // level. + // level. Use SliceRecord::is_valid() to check the result. const SliceRecord& closest_slice_to_slice_level( - float slice_level, float max_epsilon = float(EPSILON)) const + float slice_level, + float max_epsilon = std::numeric_limits::max()) const { auto it = closest_slice_record(m_slice_index, slice_level, max_epsilon); - if (it == m_slice_index.end()) return SliceRecord::EMPTY; - return *it; + return it == m_slice_index.end() ? SliceRecord::EMPTY : *it; } protected: diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 78d1085e8..da62ddab0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5027,7 +5027,7 @@ void GLCanvas3D::_render_sla_slices() const // Offset to avoid OpenGL Z fighting between the object's horizontal surfaces and the triangluated surfaces of the cuts. double plane_shift_z = 0.002; - if (! slice_low.is_valid()) { + if (slice_low.is_valid()) { const ExPolygons& obj_bottom = slice_low.get_slice(soModel); const ExPolygons& sup_bottom = slice_low.get_slice(soSupport); // calculate model bottom cap @@ -5038,7 +5038,7 @@ void GLCanvas3D::_render_sla_slices() const bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, true); } - if (! slice_high.is_valid()) { + if (slice_high.is_valid()) { const ExPolygons& obj_top = slice_high.get_slice(soModel); const ExPolygons& sup_top = slice_high.get_slice(soSupport); // calculate model top cap