Skip to content

Commit

Permalink
Move IndexRange.hpp to LayerRegion.hpp and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SachCZ authored and lukasmatena committed Mar 5, 2024
1 parent 555424f commit 78cd2f9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/libslic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ set(SLIC3R_SOURCES
JumpPointSearch.cpp
JumpPointSearch.hpp
KDTreeIndirect.hpp
IndexRange.hpp
Layer.cpp
Layer.hpp
LayerRegion.hpp
Expand Down
44 changes: 0 additions & 44 deletions src/libslic3r/IndexRange.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/libslic3r/Layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "Flow.hpp"
#include "SurfaceCollection.hpp"
#include "ExtrusionEntityCollection.hpp"
#include "IndexRange.hpp"
#include "LayerRegion.hpp"

#include <boost/container/small_vector.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/LayerRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void detect_bridge_directions(
unsigned end_index{};
for (const ExpansionZone& expansion_zone: expansion_zones) {
end_index += expansion_zone.expolygons.size();
if (last_anchor_id < end_index) {
if (last_anchor_id < static_cast<int64_t>(end_index)) {
append(anchor_areas, to_polygons(expansion_zone.expolygons[last_anchor_id - start_index]));
break;
}
Expand Down
36 changes: 35 additions & 1 deletion src/libslic3r/LayerRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "BoundingBox.hpp"
#include "ExtrusionEntityCollection.hpp"
#include "SurfaceCollection.hpp"
#include "IndexRange.hpp"
#include "libslic3r/Algorithm/RegionExpansion.hpp"


Expand All @@ -14,6 +13,41 @@ class Layer;
using LayerPtrs = std::vector<Layer*>;
class PrintRegion;

// Range of indices, providing support for range based loops.
template<typename T>
class IndexRange
{
public:
IndexRange(T ibegin, T iend) : m_begin(ibegin), m_end(iend) {}
IndexRange() = default;

// Just a bare minimum functionality iterator required by range-for loop.
class Iterator {
public:
T operator*() const { return m_idx; }
bool operator!=(const Iterator &rhs) const { return m_idx != rhs.m_idx; }
void operator++() { ++ m_idx; }
private:
friend class IndexRange<T>;
Iterator(T idx) : m_idx(idx) {}
T m_idx;
};

Iterator begin() const { assert(m_begin <= m_end); return Iterator(m_begin); };
Iterator end() const { assert(m_begin <= m_end); return Iterator(m_end); };

bool empty() const { assert(m_begin <= m_end); return m_begin >= m_end; }
T size() const { assert(m_begin <= m_end); return m_end - m_begin; }

private:
// Index of the first extrusion in LayerRegion.
T m_begin { 0 };
// Index of the last extrusion in LayerRegion.
T m_end { 0 };
};

template class IndexRange<uint32_t>;

using ExtrusionRange = IndexRange<uint32_t>;
using ExPolygonRange = IndexRange<uint32_t>;

Expand Down
4 changes: 2 additions & 2 deletions tests/libslic3r/test_layer_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ struct LayerRegionFixture {
};

TEST_CASE_METHOD(LayerRegionFixture, "test the surface expansion", "[LayerRegion]") {
float custom_angle = 1.234;
const double custom_angle{1.234f};

Surfaces result{expand_merge_surfaces(
const Surfaces result{expand_merge_surfaces(
surfaces, stBottomBridge,
expansion_zones,
closing_radius,
Expand Down

0 comments on commit 78cd2f9

Please sign in to comment.