mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-06-08 14:48:33 -04:00
Type handling is mainly done using templates. Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used. Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type). Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return. Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments). It is overloaded to be able to return type, type* and type&. Typechecking in ExtrusionEntityCollection updated to check all passed types.
78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
#include "ExPolygonCollection.hpp"
|
|
#include "Geometry.hpp"
|
|
#ifdef SLIC3RXS
|
|
#include "perlglue.hpp"
|
|
#endif
|
|
|
|
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)
|
|
{
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
(*it).scale(factor);
|
|
}
|
|
}
|
|
|
|
void
|
|
ExPolygonCollection::translate(double x, double y)
|
|
{
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
(*it).translate(x, y);
|
|
}
|
|
}
|
|
|
|
void
|
|
ExPolygonCollection::rotate(double angle, const Point ¢er)
|
|
{
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
(*it).rotate(angle, 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;
|
|
}
|
|
|
|
void
|
|
ExPolygonCollection::simplify(double tolerance)
|
|
{
|
|
ExPolygons expp;
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
it->simplify(tolerance, expp);
|
|
}
|
|
this->expolygons = expp;
|
|
}
|
|
|
|
void
|
|
ExPolygonCollection::convex_hull(Polygon* hull) const
|
|
{
|
|
Points pp;
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it)
|
|
pp.insert(pp.end(), it->contour.points.begin(), it->contour.points.end());
|
|
Slic3r::Geometry::convex_hull(pp, hull);
|
|
}
|
|
|
|
#ifdef SLIC3RXS
|
|
REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection");
|
|
#endif
|
|
|
|
}
|