~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/src/ExPolygonCollection.cpp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "ExPolygonCollection.hpp"
 
2
#include "Geometry.hpp"
 
3
 
 
4
namespace Slic3r {
 
5
 
 
6
ExPolygonCollection::operator Polygons() const
 
7
{
 
8
    Polygons polygons;
 
9
    for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
 
10
        polygons.push_back(it->contour);
 
11
        for (Polygons::const_iterator ith = it->holes.begin(); ith != it->holes.end(); ++ith) {
 
12
            polygons.push_back(*ith);
 
13
        }
 
14
    }
 
15
    return polygons;
 
16
}
 
17
 
 
18
void
 
19
ExPolygonCollection::scale(double factor)
 
20
{
 
21
    for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
 
22
        (*it).scale(factor);
 
23
    }
 
24
}
 
25
 
 
26
void
 
27
ExPolygonCollection::translate(double x, double y)
 
28
{
 
29
   for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
 
30
        (*it).translate(x, y);
 
31
    }
 
32
}
 
33
 
 
34
void
 
35
ExPolygonCollection::rotate(double angle, const Point &center)
 
36
{
 
37
    for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
 
38
        (*it).rotate(angle, center);
 
39
    }
 
40
}
 
41
 
 
42
bool
 
43
ExPolygonCollection::contains_point(const Point &point) const
 
44
{
 
45
    for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
 
46
        if (it->contains_point(point)) return true;
 
47
    }
 
48
    return false;
 
49
}
 
50
 
 
51
void
 
52
ExPolygonCollection::simplify(double tolerance)
 
53
{
 
54
    ExPolygons expp;
 
55
    for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
 
56
        it->simplify(tolerance, expp);
 
57
    }
 
58
    this->expolygons = expp;
 
59
}
 
60
 
 
61
void
 
62
ExPolygonCollection::convex_hull(Polygon* hull) const
 
63
{
 
64
    Points pp;
 
65
    for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it)
 
66
        pp.insert(pp.end(), it->contour.points.begin(), it->contour.points.end());
 
67
    Slic3r::Geometry::convex_hull(pp, hull);
 
68
}
 
69
 
 
70
#ifdef SLIC3RXS
 
71
REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection");
 
72
#endif
 
73
 
 
74
}