Implemented utility functions to operate over lines, polylines, polygons,

surfaces.
This commit is contained in:
bubnikv 2016-11-07 22:49:11 +01:00
parent aac968162b
commit 5a81731577
13 changed files with 495 additions and 66 deletions

View file

@ -26,24 +26,12 @@ ExPolygon::operator Points() const
ExPolygon::operator Polygons() const
{
Polygons polygons;
polygons.reserve(this->holes.size() + 1);
polygons.push_back(this->contour);
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
polygons.push_back(*it);
}
return polygons;
return to_polygons(*this);
}
ExPolygon::operator Polylines() const
{
Polylines polylines;
polylines.reserve(this->holes.size() + 1);
polylines.push_back((Polyline)this->contour);
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
polylines.push_back((Polyline)*it);
}
return polylines;
return to_polylines(*this);
}
void
@ -583,6 +571,22 @@ BoundingBox get_extents(const ExPolygons &expolygons)
return bbox;
}
BoundingBox get_extents_rotated(const ExPolygon &expolygon, double angle)
{
return get_extents_rotated(expolygon.contour, angle);
}
BoundingBox get_extents_rotated(const ExPolygons &expolygons, double angle)
{
BoundingBox bbox;
if (! expolygons.empty()) {
bbox = get_extents_rotated(expolygons.front().contour, angle);
for (size_t i = 1; i < expolygons.size(); ++ i)
bbox.merge(get_extents_rotated(expolygons[i].contour, angle));
}
return bbox;
}
bool remove_sticks(ExPolygon &poly)
{
return remove_sticks(poly.contour) || remove_sticks(poly.holes);