mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 07:41:09 -06:00
Ported intersect_expolygons() and subtract_expolygons() to XS
This commit is contained in:
parent
5f81292f3f
commit
761f261a68
11 changed files with 95 additions and 29 deletions
|
@ -2,6 +2,18 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
ExPolygonCollection::operator Polygons() const
|
||||
{
|
||||
Polygons polygons;
|
||||
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
||||
polygons.push_back(it->contour);
|
||||
for (Polygons::const_iterator ith = it->holes.begin(); ith != it->holes.end(); ++ith) {
|
||||
polygons.push_back(*ith);
|
||||
}
|
||||
}
|
||||
return polygons;
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygonCollection::scale(double factor)
|
||||
{
|
||||
|
@ -26,4 +38,13 @@ ExPolygonCollection::rotate(double angle, Point* center)
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ExPolygonCollection::contains_point(const Point* point) const
|
||||
{
|
||||
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
||||
if (it->contains_point(point)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ class ExPolygonCollection
|
|||
{
|
||||
public:
|
||||
ExPolygons expolygons;
|
||||
operator Polygons() const;
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void rotate(double angle, Point* center);
|
||||
bool contains_point(const Point* point) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#include "ExtrusionEntity.hpp"
|
||||
#include "ExtrusionEntityCollection.hpp"
|
||||
#include "ExPolygonCollection.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -26,6 +29,36 @@ ExtrusionPath::last_point() const
|
|||
return new Point(this->polyline.points.back());
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection) const
|
||||
{
|
||||
// perform clipping
|
||||
Polylines clipped;
|
||||
intersection(this->polyline, *collection, clipped);
|
||||
return this->_inflate_collection(clipped);
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionPath::subtract_expolygons(ExPolygonCollection* collection) const
|
||||
{
|
||||
// perform clipping
|
||||
Polylines clipped;
|
||||
diff(this->polyline, *collection, clipped);
|
||||
return this->_inflate_collection(clipped);
|
||||
}
|
||||
|
||||
ExtrusionEntityCollection*
|
||||
ExtrusionPath::_inflate_collection(const Polylines &polylines) const
|
||||
{
|
||||
ExtrusionEntityCollection* retval = new ExtrusionEntityCollection();
|
||||
for (Polylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it) {
|
||||
ExtrusionPath* path = this->clone();
|
||||
path->polyline = *it;
|
||||
retval->entities.push_back(path);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
ExtrusionLoop*
|
||||
ExtrusionLoop::clone() const
|
||||
{
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
class ExPolygonCollection;
|
||||
class ExtrusionEntityCollection;
|
||||
|
||||
enum ExtrusionRole {
|
||||
erPerimeter,
|
||||
erExternalPerimeter,
|
||||
|
@ -45,6 +48,10 @@ class ExtrusionPath : public ExtrusionEntity
|
|||
void reverse();
|
||||
Point* first_point() const;
|
||||
Point* last_point() const;
|
||||
ExtrusionEntityCollection* intersect_expolygons(ExPolygonCollection* collection) const;
|
||||
ExtrusionEntityCollection* subtract_expolygons(ExPolygonCollection* collection) const;
|
||||
private:
|
||||
ExtrusionEntityCollection* _inflate_collection(const Polylines &polylines) const;
|
||||
};
|
||||
|
||||
class ExtrusionLoop : public ExtrusionEntity
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
#include "Polyline.hpp"
|
||||
#include "Polygon.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
Polyline::operator Polylines() const
|
||||
{
|
||||
Polylines polylines(1);
|
||||
polylines.push_back(*this);
|
||||
return polylines;
|
||||
}
|
||||
|
||||
Point*
|
||||
Polyline::last_point() const
|
||||
{
|
||||
|
|
|
@ -6,8 +6,12 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
class Polyline;
|
||||
typedef std::vector<Polyline> Polylines;
|
||||
|
||||
class Polyline : public MultiPoint {
|
||||
public:
|
||||
operator Polylines() const;
|
||||
Point* last_point() const;
|
||||
Lines lines() const;
|
||||
void clip_end(double distance);
|
||||
|
@ -20,8 +24,6 @@ class Polyline : public MultiPoint {
|
|||
#endif
|
||||
};
|
||||
|
||||
typedef std::vector<Polyline> Polylines;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
void rotate(double angle, Point* center);
|
||||
int count()
|
||||
%code{% RETVAL = THIS->expolygons.size(); %};
|
||||
bool contains_point(Point* point);
|
||||
%{
|
||||
|
||||
ExPolygonCollection*
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
|
||||
Point* last_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
|
||||
ExtrusionEntityCollection* intersect_expolygons(ExPolygonCollection* collection)
|
||||
%code{% const char* CLASS = "Slic3r::ExtrusionPath::Collection"; RETVAL = THIS->intersect_expolygons(collection); %};
|
||||
ExtrusionEntityCollection* subtract_expolygons(ExPolygonCollection* collection)
|
||||
%code{% const char* CLASS = "Slic3r::ExtrusionPath::Collection"; RETVAL = THIS->subtract_expolygons(collection); %};
|
||||
%{
|
||||
|
||||
ExtrusionPath*
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
%typemap{AV*};
|
||||
%typemap{Point*};
|
||||
%typemap{ExPolygon*};
|
||||
%typemap{ExPolygonCollection*};
|
||||
%typemap{Line*};
|
||||
%typemap{Polyline*};
|
||||
%typemap{Polygon*};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue