mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 14:20:58 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
89 lines
3.3 KiB
C++
89 lines
3.3 KiB
C++
#include "ExPolygonsIndex.hpp"
|
|
#include "ExPolygon.hpp"
|
|
#include <cstdint>
|
|
#include <cassert>
|
|
#include <vector>
|
|
#include <utility>
|
|
#include <algorithm>
|
|
using namespace Slic3r;
|
|
|
|
// IMPROVE: use one dimensional vector for polygons offset with searching by std::lower_bound
|
|
ExPolygonsIndices::ExPolygonsIndices(const ExPolygons &shapes)
|
|
{
|
|
// prepare offsets
|
|
m_offsets.reserve(shapes.size());
|
|
uint32_t offset = 0;
|
|
for (const ExPolygon &shape : shapes) {
|
|
assert(!shape.contour.points.empty());
|
|
std::vector<uint32_t> shape_offsets;
|
|
shape_offsets.reserve(shape.holes.size() + 1);
|
|
shape_offsets.push_back(offset);
|
|
offset += shape.contour.points.size();
|
|
for (const Polygon &hole: shape.holes) {
|
|
shape_offsets.push_back(offset);
|
|
offset += hole.points.size();
|
|
}
|
|
m_offsets.push_back(std::move(shape_offsets));
|
|
}
|
|
m_count = offset;
|
|
}
|
|
|
|
uint32_t ExPolygonsIndices::cvt(const ExPolygonsIndex &id) const
|
|
{
|
|
assert(id.expolygons_index < m_offsets.size());
|
|
const std::vector<uint32_t> &shape_offset = m_offsets[id.expolygons_index];
|
|
assert(id.polygon_index < shape_offset.size());
|
|
uint32_t res = shape_offset[id.polygon_index] + id.point_index;
|
|
assert(res < m_count);
|
|
return res;
|
|
}
|
|
|
|
ExPolygonsIndex ExPolygonsIndices::cvt(uint32_t index) const
|
|
{
|
|
assert(index < m_count);
|
|
ExPolygonsIndex result{0, 0, 0};
|
|
// find expolygon index
|
|
auto fn = [](const std::vector<uint32_t> &offsets, uint32_t index) { return offsets[0] < index; };
|
|
auto it = std::lower_bound(m_offsets.begin() + 1, m_offsets.end(), index, fn);
|
|
result.expolygons_index = it - m_offsets.begin();
|
|
if (it == m_offsets.end() || it->at(0) != index) --result.expolygons_index;
|
|
|
|
// find polygon index
|
|
const std::vector<uint32_t> &shape_offset = m_offsets[result.expolygons_index];
|
|
auto it2 = std::lower_bound(shape_offset.begin() + 1, shape_offset.end(), index);
|
|
result.polygon_index = it2 - shape_offset.begin();
|
|
if (it2 == shape_offset.end() || *it2 != index) --result.polygon_index;
|
|
|
|
// calculate point index
|
|
uint32_t polygon_offset = shape_offset[result.polygon_index];
|
|
assert(index >= polygon_offset);
|
|
result.point_index = index - polygon_offset;
|
|
return result;
|
|
}
|
|
|
|
bool ExPolygonsIndices::is_last_point(const ExPolygonsIndex &id) const {
|
|
assert(id.expolygons_index < m_offsets.size());
|
|
const std::vector<uint32_t> &shape_offset = m_offsets[id.expolygons_index];
|
|
assert(id.polygon_index < shape_offset.size());
|
|
uint32_t index = shape_offset[id.polygon_index] + id.point_index;
|
|
assert(index < m_count);
|
|
// next index
|
|
uint32_t next_point_index = index + 1;
|
|
uint32_t next_poly_index = id.polygon_index + 1;
|
|
uint32_t next_expoly_index = id.expolygons_index + 1;
|
|
// is last expoly?
|
|
if (next_expoly_index == m_offsets.size()) {
|
|
// is last expoly last poly?
|
|
if (next_poly_index == shape_offset.size())
|
|
return next_point_index == m_count;
|
|
} else {
|
|
// (not last expoly) is expoly last poly?
|
|
if (next_poly_index == shape_offset.size())
|
|
return next_point_index == m_offsets[next_expoly_index][0];
|
|
}
|
|
// Not last polygon in expolygon
|
|
return next_point_index == shape_offset[next_poly_index];
|
|
}
|
|
|
|
uint32_t ExPolygonsIndices::get_count() const { return m_count; }
|