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 {
|
|
|
|
|
2015-01-06 19:52:36 +00:00
|
|
|
ExPolygonCollection::ExPolygonCollection(const ExPolygon &expolygon)
|
|
|
|
{
|
|
|
|
this->expolygons.push_back(expolygon);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-23 19:14:13 +00:00
|
|
|
template <class T>
|
2013-11-21 16:53:50 +00:00
|
|
|
bool
|
2014-11-23 19:14:13 +00:00
|
|
|
ExPolygonCollection::contains(const T &item) const
|
2013-11-21 16:53:50 +00:00
|
|
|
{
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
2014-11-23 19:14:13 +00:00
|
|
|
if (it->contains(item)) return true;
|
2014-11-23 19:03:16 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-23 19:14:13 +00:00
|
|
|
template bool ExPolygonCollection::contains<Point>(const Point &item) const;
|
|
|
|
template bool ExPolygonCollection::contains<Line>(const Line &item) const;
|
|
|
|
template bool ExPolygonCollection::contains<Polyline>(const Polyline &item) const;
|
2014-11-23 19:03:16 +00:00
|
|
|
|
2015-01-06 19:52:36 +00:00
|
|
|
bool
|
|
|
|
ExPolygonCollection::contains_b(const Point &point) const
|
|
|
|
{
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
if (it->contains_b(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) {
|
2015-12-21 13:46:35 +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
|
|
|
}
|
|
|
|
|
2015-01-19 17:53:04 +00:00
|
|
|
Polygon
|
|
|
|
ExPolygonCollection::convex_hull() const
|
2013-12-12 19:19:33 +00:00
|
|
|
{
|
|
|
|
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());
|
2015-01-19 17:53:04 +00:00
|
|
|
return Slic3r::Geometry::convex_hull(pp);
|
2013-12-12 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:52:36 +00:00
|
|
|
Lines
|
|
|
|
ExPolygonCollection::lines() const
|
|
|
|
{
|
|
|
|
Lines lines;
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
Lines ex_lines = it->lines();
|
|
|
|
lines.insert(lines.end(), ex_lines.begin(), ex_lines.end());
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2015-02-27 20:55:02 +00:00
|
|
|
Polygons
|
|
|
|
ExPolygonCollection::contours() const
|
|
|
|
{
|
|
|
|
Polygons contours;
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
contours.push_back(it->contour);
|
|
|
|
}
|
|
|
|
return contours;
|
|
|
|
}
|
|
|
|
|
2015-10-26 22:23:03 +00:00
|
|
|
void
|
|
|
|
ExPolygonCollection::append(const ExPolygons &expp)
|
|
|
|
{
|
|
|
|
this->expolygons.insert(this->expolygons.end(), expp.begin(), expp.end());
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
BoundingBox get_extents(const ExPolygonCollection &expolygon)
|
|
|
|
{
|
|
|
|
return get_extents(expolygon.expolygons);
|
|
|
|
}
|
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|