2013-07-16 18:09:53 +00:00
|
|
|
#ifndef slic3r_ClipperUtils_hpp_
|
|
|
|
#define slic3r_ClipperUtils_hpp_
|
|
|
|
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-16 18:09:53 +00:00
|
|
|
#include "clipper.hpp"
|
2013-07-16 19:04:14 +00:00
|
|
|
#include "ExPolygon.hpp"
|
|
|
|
#include "Polygon.hpp"
|
2013-11-23 17:29:25 +00:00
|
|
|
#include "Surface.hpp"
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-08-26 23:26:44 +00:00
|
|
|
// import these wherever we're included
|
2021-04-21 18:15:49 +00:00
|
|
|
using Slic3r::ClipperLib::jtMiter;
|
|
|
|
using Slic3r::ClipperLib::jtRound;
|
|
|
|
using Slic3r::ClipperLib::jtSquare;
|
2013-08-26 23:26:44 +00:00
|
|
|
|
2021-04-30 09:49:57 +00:00
|
|
|
static constexpr const float ClipperSafetyOffset = 10.f;
|
2021-05-05 10:16:40 +00:00
|
|
|
enum class ApplySafetyOffset {
|
|
|
|
No,
|
|
|
|
Yes
|
|
|
|
};
|
2021-04-13 11:28:21 +00:00
|
|
|
|
2021-04-30 09:49:57 +00:00
|
|
|
#define CLIPPERUTILS_UNSAFE_OFFSET
|
2017-03-24 08:32:30 +00:00
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
2021-04-30 09:49:57 +00:00
|
|
|
namespace ClipperUtils {
|
|
|
|
class PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
using value_type = Points;
|
|
|
|
using difference_type = std::ptrdiff_t;
|
|
|
|
using pointer = const Points*;
|
|
|
|
using reference = const Points&;
|
|
|
|
using iterator_category = std::input_iterator_tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EmptyPathsProvider {
|
|
|
|
public:
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
2021-05-03 13:28:03 +00:00
|
|
|
const Points& operator*() { assert(false); return s_empty_points; }
|
2021-04-30 09:49:57 +00:00
|
|
|
// all iterators point to end.
|
|
|
|
constexpr bool operator==(const iterator &rhs) const { return true; }
|
|
|
|
constexpr bool operator!=(const iterator &rhs) const { return false; }
|
2021-05-03 13:28:03 +00:00
|
|
|
const Points& operator++(int) { assert(false); return s_empty_points; }
|
2021-05-04 14:13:40 +00:00
|
|
|
const iterator& operator++() { assert(false); return *this; }
|
2021-04-30 09:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constexpr EmptyPathsProvider() {}
|
|
|
|
static constexpr iterator cend() throw() { return iterator{}; }
|
|
|
|
static constexpr iterator end() throw() { return cend(); }
|
|
|
|
static constexpr iterator cbegin() throw() { return cend(); }
|
|
|
|
static constexpr iterator begin() throw() { return cend(); }
|
|
|
|
static constexpr size_t size() throw() { return 0; }
|
2021-05-03 13:00:23 +00:00
|
|
|
|
2021-05-03 13:30:10 +00:00
|
|
|
static Points s_empty_points;
|
2021-04-30 09:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SinglePathProvider {
|
|
|
|
public:
|
|
|
|
SinglePathProvider(const Points &points) : m_points(points) {}
|
|
|
|
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
explicit iterator(const Points &points) : m_ptr(&points) {}
|
|
|
|
const Points& operator*() const { return *m_ptr; }
|
|
|
|
bool operator==(const iterator &rhs) const { return m_ptr == rhs.m_ptr; }
|
|
|
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
|
|
|
const Points& operator++(int) { auto out = m_ptr; m_ptr = &s_end; return *out; }
|
|
|
|
iterator& operator++() { m_ptr = &s_end; return *this; }
|
|
|
|
private:
|
|
|
|
const Points *m_ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
iterator cbegin() const { return iterator(m_points); }
|
|
|
|
iterator begin() const { return this->cbegin(); }
|
|
|
|
iterator cend() const { return iterator(s_end); }
|
|
|
|
iterator end() const { return this->cend(); }
|
|
|
|
size_t size() const { return 1; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Points &m_points;
|
|
|
|
static Points s_end;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename MultiPointType>
|
|
|
|
class MultiPointsProvider {
|
|
|
|
public:
|
|
|
|
MultiPointsProvider(const std::vector<MultiPointType> &multipoints) : m_multipoints(multipoints) {}
|
|
|
|
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
explicit iterator(typename std::vector<MultiPointType>::const_iterator it) : m_it(it) {}
|
|
|
|
const Points& operator*() const { return m_it->points; }
|
|
|
|
bool operator==(const iterator &rhs) const { return m_it == rhs.m_it; }
|
|
|
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
|
|
|
const Points& operator++(int) { return (m_it ++)->points; }
|
|
|
|
iterator& operator++() { ++ m_it; return *this; }
|
|
|
|
private:
|
|
|
|
typename std::vector<MultiPointType>::const_iterator m_it;
|
|
|
|
};
|
|
|
|
|
|
|
|
iterator cbegin() const { return iterator(m_multipoints.begin()); }
|
|
|
|
iterator begin() const { return this->cbegin(); }
|
|
|
|
iterator cend() const { return iterator(m_multipoints.end()); }
|
|
|
|
iterator end() const { return this->cend(); }
|
|
|
|
size_t size() const { return m_multipoints.size(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::vector<MultiPointType> &m_multipoints;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PolygonsProvider = MultiPointsProvider<Polygon>;
|
|
|
|
using PolylinesProvider = MultiPointsProvider<Polyline>;
|
|
|
|
|
|
|
|
struct ExPolygonProvider {
|
|
|
|
ExPolygonProvider(const ExPolygon &expoly) : m_expoly(expoly) {}
|
|
|
|
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
explicit iterator(const ExPolygon &expoly, int idx) : m_expoly(expoly), m_idx(idx) {}
|
|
|
|
const Points& operator*() const { return (m_idx == 0) ? m_expoly.contour.points : m_expoly.holes[m_idx - 1].points; }
|
|
|
|
bool operator==(const iterator &rhs) const { assert(m_expoly == rhs.m_expoly); return m_idx == rhs.m_idx; }
|
|
|
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
|
|
|
const Points& operator++(int) { const Points &out = **this; ++ m_idx; return out; }
|
|
|
|
iterator& operator++() { ++ m_idx; return *this; }
|
|
|
|
private:
|
|
|
|
const ExPolygon &m_expoly;
|
|
|
|
int m_idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
iterator cbegin() const { return iterator(m_expoly, 0); }
|
|
|
|
iterator begin() const { return this->cbegin(); }
|
|
|
|
iterator cend() const { return iterator(m_expoly, m_expoly.holes.size() + 1); }
|
|
|
|
iterator end() const { return this->cend(); }
|
|
|
|
size_t size() const { return m_expoly.holes.size() + 1; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ExPolygon &m_expoly;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ExPolygonsProvider {
|
|
|
|
ExPolygonsProvider(const ExPolygons &expolygons) : m_expolygons(expolygons) {
|
|
|
|
m_size = 0;
|
|
|
|
for (const ExPolygon &expoly : expolygons)
|
|
|
|
m_size += expoly.holes.size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
explicit iterator(ExPolygons::const_iterator it) : m_it_expolygon(it), m_idx_contour(0) {}
|
|
|
|
const Points& operator*() const { return (m_idx_contour == 0) ? m_it_expolygon->contour.points : m_it_expolygon->holes[m_idx_contour - 1].points; }
|
|
|
|
bool operator==(const iterator &rhs) const { return m_it_expolygon == rhs.m_it_expolygon && m_idx_contour == rhs.m_idx_contour; }
|
|
|
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
|
|
|
iterator& operator++() {
|
|
|
|
if (++ m_idx_contour == m_it_expolygon->holes.size() + 1) {
|
|
|
|
++ m_it_expolygon;
|
|
|
|
m_idx_contour = 0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
const Points& operator++(int) {
|
|
|
|
const Points &out = **this;
|
|
|
|
++ (*this);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
ExPolygons::const_iterator m_it_expolygon;
|
2021-05-03 13:00:23 +00:00
|
|
|
size_t m_idx_contour;
|
2021-04-30 09:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
iterator cbegin() const { return iterator(m_expolygons.cbegin()); }
|
|
|
|
iterator begin() const { return this->cbegin(); }
|
|
|
|
iterator cend() const { return iterator(m_expolygons.cend()); }
|
|
|
|
iterator end() const { return this->cend(); }
|
|
|
|
size_t size() const { return m_size; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ExPolygons &m_expolygons;
|
|
|
|
size_t m_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SurfacesProvider {
|
|
|
|
SurfacesProvider(const Surfaces &surfaces) : m_surfaces(surfaces) {
|
|
|
|
m_size = 0;
|
|
|
|
for (const Surface &surface : surfaces)
|
|
|
|
m_size += surface.expolygon.holes.size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
explicit iterator(Surfaces::const_iterator it) : m_it_surface(it), m_idx_contour(0) {}
|
|
|
|
const Points& operator*() const { return (m_idx_contour == 0) ? m_it_surface->expolygon.contour.points : m_it_surface->expolygon.holes[m_idx_contour - 1].points; }
|
|
|
|
bool operator==(const iterator &rhs) const { return m_it_surface == rhs.m_it_surface && m_idx_contour == rhs.m_idx_contour; }
|
|
|
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
|
|
|
iterator& operator++() {
|
|
|
|
if (++ m_idx_contour == m_it_surface->expolygon.holes.size() + 1) {
|
|
|
|
++ m_it_surface;
|
|
|
|
m_idx_contour = 0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
const Points& operator++(int) {
|
|
|
|
const Points &out = **this;
|
|
|
|
++ (*this);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Surfaces::const_iterator m_it_surface;
|
2021-05-03 13:00:23 +00:00
|
|
|
size_t m_idx_contour;
|
2021-04-30 09:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
iterator cbegin() const { return iterator(m_surfaces.cbegin()); }
|
|
|
|
iterator begin() const { return this->cbegin(); }
|
|
|
|
iterator cend() const { return iterator(m_surfaces.cend()); }
|
|
|
|
iterator end() const { return this->cend(); }
|
|
|
|
size_t size() const { return m_size; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Surfaces &m_surfaces;
|
|
|
|
size_t m_size;
|
|
|
|
};
|
2021-05-03 09:39:53 +00:00
|
|
|
|
|
|
|
struct SurfacesPtrProvider {
|
|
|
|
SurfacesPtrProvider(const SurfacesPtr &surfaces) : m_surfaces(surfaces) {
|
|
|
|
m_size = 0;
|
|
|
|
for (const Surface *surface : surfaces)
|
|
|
|
m_size += surface->expolygon.holes.size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iterator : public PathsProviderIteratorBase {
|
|
|
|
public:
|
|
|
|
explicit iterator(SurfacesPtr::const_iterator it) : m_it_surface(it), m_idx_contour(0) {}
|
|
|
|
const Points& operator*() const { return (m_idx_contour == 0) ? (*m_it_surface)->expolygon.contour.points : (*m_it_surface)->expolygon.holes[m_idx_contour - 1].points; }
|
|
|
|
bool operator==(const iterator &rhs) const { return m_it_surface == rhs.m_it_surface && m_idx_contour == rhs.m_idx_contour; }
|
|
|
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
|
|
|
iterator& operator++() {
|
|
|
|
if (++ m_idx_contour == (*m_it_surface)->expolygon.holes.size() + 1) {
|
|
|
|
++ m_it_surface;
|
|
|
|
m_idx_contour = 0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
const Points& operator++(int) {
|
|
|
|
const Points &out = **this;
|
|
|
|
++ (*this);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SurfacesPtr::const_iterator m_it_surface;
|
2021-05-03 13:00:23 +00:00
|
|
|
size_t m_idx_contour;
|
2021-05-03 09:39:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
iterator cbegin() const { return iterator(m_surfaces.cbegin()); }
|
|
|
|
iterator begin() const { return this->cbegin(); }
|
|
|
|
iterator cend() const { return iterator(m_surfaces.cend()); }
|
|
|
|
iterator end() const { return this->cend(); }
|
|
|
|
size_t size() const { return m_size; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const SurfacesPtr &m_surfaces;
|
|
|
|
size_t m_size;
|
|
|
|
};
|
2021-04-30 09:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input);
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-11-20 10:35:58 +00:00
|
|
|
// offset Polygons
|
2021-04-30 09:49:57 +00:00
|
|
|
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
2021-04-13 11:28:21 +00:00
|
|
|
|
2013-11-20 10:35:58 +00:00
|
|
|
// offset Polylines
|
2021-05-03 09:39:53 +00:00
|
|
|
Slic3r::Polygons offset(const Slic3r::Polyline &polyline, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3);
|
|
|
|
Slic3r::Polygons offset(const Slic3r::Polylines &polylines, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3);
|
|
|
|
Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::Polygons offset(const Slic3r::Surfaces &surfaces, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::Polygons offset(const Slic3r::SurfacesPtr &surfaces, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::Surfaces &surfaces, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
2021-05-05 10:16:40 +00:00
|
|
|
Slic3r::Polygons union_safety_offset(const Slic3r::ExPolygons &expolygons);
|
|
|
|
Slic3r::ExPolygons union_safety_offset_ex(const Slic3r::ExPolygons &expolygons);
|
2021-05-03 09:39:53 +00:00
|
|
|
|
|
|
|
Slic3r::Polygons offset2(const Slic3r::ExPolygons &expolygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset2_ex(const Slic3r::ExPolygons &expolygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
2021-04-13 11:28:21 +00:00
|
|
|
|
|
|
|
#ifdef CLIPPERUTILS_UNSAFE_OFFSET
|
2021-05-05 10:16:40 +00:00
|
|
|
Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
2021-04-30 09:49:57 +00:00
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
2021-05-03 09:39:53 +00:00
|
|
|
ClipperLib::Paths _offset2(const Slic3r::Polygons &polygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::Polygons offset2(const Slic3r::Polygons &polygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3);
|
2021-05-05 10:16:40 +00:00
|
|
|
Slic3r::Polygons union_safety_offset(const Slic3r::Polygons &expolygons);
|
|
|
|
Slic3r::ExPolygons union_safety_offset_ex(const Slic3r::Polygons &polygons);
|
2021-04-13 11:28:21 +00:00
|
|
|
#endif // CLIPPERUTILS_UNSAFE_OFFSET
|
|
|
|
|
2021-05-05 10:16:40 +00:00
|
|
|
Slic3r::Lines _clipper_ln(ClipperLib::ClipType clipType, const Slic3r::Lines &subject, const Slic3r::Polygons &clip);
|
|
|
|
|
|
|
|
// Safety offset is applied to the clipping polygons only.
|
|
|
|
Slic3r::Polygons diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
2021-05-27 12:29:51 +00:00
|
|
|
Slic3r::Polygons diff(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
2021-05-05 10:16:40 +00:00
|
|
|
Slic3r::Polygons diff(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polygons diff(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Surfaces &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Polygon &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygon &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Surfaces &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons diff_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip);
|
|
|
|
Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygon &clip);
|
|
|
|
Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygons &clip);
|
|
|
|
Slic3r::Polylines diff_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip);
|
|
|
|
|
|
|
|
inline Slic3r::Lines diff_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip)
|
2016-12-13 18:22:23 +00:00
|
|
|
{
|
2021-05-05 10:16:40 +00:00
|
|
|
return _clipper_ln(ClipperLib::ctDifference, subject, clip);
|
2016-12-13 18:22:23 +00:00
|
|
|
}
|
2015-12-21 13:46:35 +00:00
|
|
|
|
2021-05-05 10:16:40 +00:00
|
|
|
// Safety offset is applied to the clipping polygons only.
|
|
|
|
Slic3r::Polygons intersection(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polygons intersection(const Slic3r::ExPolygon &subject, const Slic3r::ExPolygon &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polygons intersection(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polygons intersection(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polygons intersection(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polygons intersection(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygon &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::ExPolygons intersection_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::ExPolygons &clip, ApplySafetyOffset do_safety_offset = ApplySafetyOffset::No);
|
|
|
|
Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip);
|
|
|
|
Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygons &clip);
|
|
|
|
Slic3r::Polylines intersection_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip);
|
|
|
|
|
|
|
|
inline Slic3r::Lines intersection_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip)
|
2016-12-13 18:22:23 +00:00
|
|
|
{
|
2021-05-05 10:16:40 +00:00
|
|
|
return _clipper_ln(ClipperLib::ctIntersection, subject, clip);
|
2016-12-08 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 10:16:40 +00:00
|
|
|
inline Slic3r::Lines intersection_ln(const Slic3r::Line &subject, const Slic3r::Polygons &clip)
|
2017-06-02 11:33:19 +00:00
|
|
|
{
|
|
|
|
Slic3r::Lines lines;
|
|
|
|
lines.emplace_back(subject);
|
2021-05-05 10:16:40 +00:00
|
|
|
return _clipper_ln(ClipperLib::ctIntersection, lines, clip);
|
2016-12-13 18:22:23 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 10:16:40 +00:00
|
|
|
Slic3r::Polygons union_(const Slic3r::Polygons &subject);
|
|
|
|
Slic3r::Polygons union_(const Slic3r::ExPolygons &subject);
|
|
|
|
Slic3r::Polygons union_(const Slic3r::Polygons &subject, const Slic3r::Polygons &subject2);
|
2021-06-01 09:10:12 +00:00
|
|
|
// May be used to "heal" unusual models (3DLabPrints etc.) by providing fill_type (pftEvenOdd, pftNonZero, pftPositive, pftNegative).
|
2021-06-01 10:33:14 +00:00
|
|
|
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, ClipperLib::PolyFillType fill_type = ClipperLib::pftNonZero);
|
2021-04-30 09:49:57 +00:00
|
|
|
Slic3r::ExPolygons union_ex(const Slic3r::ExPolygons &subject);
|
|
|
|
Slic3r::ExPolygons union_ex(const Slic3r::Surfaces &subject);
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2021-04-30 09:49:57 +00:00
|
|
|
ClipperLib::PolyTree union_pt(const Slic3r::Polygons &subject);
|
|
|
|
ClipperLib::PolyTree union_pt(const Slic3r::ExPolygons &subject);
|
2019-09-24 12:54:33 +00:00
|
|
|
|
2021-04-30 09:49:57 +00:00
|
|
|
Slic3r::Polygons union_pt_chained_outside_in(const Slic3r::Polygons &subject);
|
2019-09-24 12:54:33 +00:00
|
|
|
|
2019-12-19 10:27:01 +00:00
|
|
|
ClipperLib::PolyNodes order_nodes(const ClipperLib::PolyNodes &nodes);
|
|
|
|
|
|
|
|
// Implementing generalized loop (foreach) over a list of nodes which can be
|
|
|
|
// ordered or unordered (performance gain) based on template parameter
|
|
|
|
enum class e_ordering {
|
|
|
|
ON,
|
|
|
|
OFF
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a template struct, template functions can not be partially specialized
|
|
|
|
template<e_ordering o, class Fn> struct _foreach_node {
|
|
|
|
void operator()(const ClipperLib::PolyNodes &nodes, Fn &&fn);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Specialization with NO ordering
|
|
|
|
template<class Fn> struct _foreach_node<e_ordering::OFF, Fn> {
|
|
|
|
void operator()(const ClipperLib::PolyNodes &nodes, Fn &&fn)
|
|
|
|
{
|
|
|
|
for (auto &n : nodes) fn(n);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Specialization with ordering
|
|
|
|
template<class Fn> struct _foreach_node<e_ordering::ON, Fn> {
|
|
|
|
void operator()(const ClipperLib::PolyNodes &nodes, Fn &&fn)
|
|
|
|
{
|
|
|
|
auto ordered_nodes = order_nodes(nodes);
|
|
|
|
for (auto &n : nodes) fn(n);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Wrapper function for the foreach_node which can deduce arguments automatically
|
|
|
|
template<e_ordering o, class Fn>
|
|
|
|
void foreach_node(const ClipperLib::PolyNodes &nodes, Fn &&fn)
|
|
|
|
{
|
|
|
|
_foreach_node<o, Fn>()(nodes, std::forward<Fn>(fn));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collecting polygons of the tree into a list of Polygons, holes have clockwise
|
|
|
|
// orientation.
|
|
|
|
template<e_ordering ordering = e_ordering::OFF>
|
|
|
|
void traverse_pt(const ClipperLib::PolyNode *tree, Polygons *out)
|
|
|
|
{
|
|
|
|
if (!tree) return; // terminates recursion
|
|
|
|
|
|
|
|
// Push the contour of the current level
|
2021-04-30 09:49:57 +00:00
|
|
|
out->emplace_back(tree->Contour);
|
2019-12-19 10:27:01 +00:00
|
|
|
|
|
|
|
// Do the recursion for all the children.
|
|
|
|
traverse_pt<ordering>(tree->Childs, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collecting polygons of the tree into a list of ExPolygons.
|
|
|
|
template<e_ordering ordering = e_ordering::OFF>
|
|
|
|
void traverse_pt(const ClipperLib::PolyNode *tree, ExPolygons *out)
|
|
|
|
{
|
|
|
|
if (!tree) return;
|
|
|
|
else if(tree->IsHole()) {
|
|
|
|
// Levels of holes are skipped and handled together with the
|
|
|
|
// contour levels.
|
|
|
|
traverse_pt<ordering>(tree->Childs, out);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExPolygon level;
|
2021-04-30 09:49:57 +00:00
|
|
|
level.contour.points = tree->Contour;
|
2019-12-19 10:27:01 +00:00
|
|
|
|
|
|
|
foreach_node<ordering>(tree->Childs,
|
|
|
|
[out, &level] (const ClipperLib::PolyNode *node) {
|
|
|
|
|
|
|
|
// Holes are collected here.
|
2021-04-30 09:49:57 +00:00
|
|
|
level.holes.emplace_back(node->Contour);
|
2019-12-19 10:27:01 +00:00
|
|
|
|
|
|
|
// By doing a recursion, a new level expoly is created with the contour
|
|
|
|
// and holes of the lower level. Doing this for all the childs.
|
|
|
|
traverse_pt<ordering>(node->Childs, out);
|
|
|
|
});
|
|
|
|
|
|
|
|
out->emplace_back(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<e_ordering o = e_ordering::OFF, class ExOrJustPolygons>
|
|
|
|
void traverse_pt(const ClipperLib::PolyNodes &nodes, ExOrJustPolygons *retval)
|
|
|
|
{
|
|
|
|
foreach_node<o>(nodes, [&retval](const ClipperLib::PolyNode *node) {
|
|
|
|
traverse_pt<o>(node, retval);
|
|
|
|
});
|
|
|
|
}
|
2019-09-24 12:54:33 +00:00
|
|
|
|
2013-08-26 16:37:19 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
/* OTHER */
|
|
|
|
Slic3r::Polygons simplify_polygons(const Slic3r::Polygons &subject, bool preserve_collinear = false);
|
|
|
|
Slic3r::ExPolygons simplify_polygons_ex(const Slic3r::Polygons &subject, bool preserve_collinear = false);
|
2013-08-08 00:10:34 +00:00
|
|
|
|
2016-11-23 14:51:47 +00:00
|
|
|
Polygons top_level_islands(const Slic3r::Polygons &polygons);
|
|
|
|
|
2021-04-13 11:28:21 +00:00
|
|
|
ClipperLib::Path mittered_offset_path_scaled(const Points &contour, const std::vector<float> &deltas, double miter_limit);
|
2019-10-25 11:34:37 +00:00
|
|
|
Polygons variable_offset_inner(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
|
|
|
|
Polygons variable_offset_outer(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
|
|
|
|
ExPolygons variable_offset_outer_ex(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
|
|
|
|
ExPolygons variable_offset_inner_ex(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
|
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 14:05:57 +00:00
|
|
|
#endif
|