2013-07-16 19:04:14 +00:00
|
|
|
#include "ExPolygonCollection.hpp"
|
2013-12-12 19:19:33 +00:00
|
|
|
#include "Geometry.hpp"
|
2013-07-16 19:04:14 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2014-05-13 18:06:01 +00:00
|
|
|
ExPolygonCollection::operator Points() const
|
|
|
|
{
|
|
|
|
Points points;
|
|
|
|
Polygons pp = *this;
|
|
|
|
for (Polygons::const_iterator poly = pp.begin(); poly != pp.end(); ++poly) {
|
|
|
|
for (Points::const_iterator point = poly->points.begin(); point != poly->points.end(); ++point)
|
|
|
|
points.push_back(*point);
|
|
|
|
}
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-13 18:06:01 +00:00
|
|
|
ExPolygonCollection::operator ExPolygons&()
|
|
|
|
{
|
|
|
|
return this->expolygons;
|
|
|
|
}
|
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
void
|
|
|
|
ExPolygonCollection::scale(double factor)
|
|
|
|
{
|
2013-08-08 00:10:34 +00:00
|
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
|
|
(*it).scale(factor);
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ExPolygonCollection::translate(double x, double y)
|
|
|
|
{
|
2013-08-08 00:10:34 +00:00
|
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
|
|
(*it).translate(x, y);
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-24 11:43:24 +00:00
|
|
|
ExPolygonCollection::rotate(double angle, const Point ¢er)
|
2013-07-16 19:04:14 +00:00
|
|
|
{
|
2013-08-08 00:10:34 +00:00
|
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
|
|
(*it).rotate(angle, center);
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
bool
|
2014-04-24 14:40:10 +00:00
|
|
|
ExPolygonCollection::contains_point(const Point &point) const
|
2013-11-21 16:53:50 +00:00
|
|
|
{
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
if (it->contains_point(point)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-21 19:25:24 +00:00
|
|
|
void
|
|
|
|
ExPolygonCollection::simplify(double tolerance)
|
|
|
|
{
|
2013-11-22 01:16:10 +00:00
|
|
|
ExPolygons expp;
|
2013-11-21 19:25:24 +00:00
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
2013-11-22 01:16:10 +00:00
|
|
|
it->simplify(tolerance, expp);
|
2013-11-21 19:25:24 +00:00
|
|
|
}
|
2013-11-22 01:16:10 +00:00
|
|
|
this->expolygons = expp;
|
2013-11-21 19:25:24 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 19:19:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-04-27 17:18:53 +00:00
|
|
|
#ifdef SLIC3RXS
|
|
|
|
REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection");
|
|
|
|
#endif
|
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|