1
#ifndef slic3r_Polygon_hpp_
2
#define slic3r_Polygon_hpp_
7
#include "MultiPoint.hpp"
8
#include "Polyline.hpp"
13
typedef std::vector<Polygon> Polygons;
15
class Polygon : public MultiPoint {
17
operator Polygons() const;
18
operator Polyline() const;
19
Point& operator[](Points::size_type idx);
20
const Point& operator[](Points::size_type idx) const;
21
Point last_point() const;
23
void lines(Lines* lines) const;
24
void split_at_vertex(const Point &point, Polyline* polyline) const;
25
void split_at_index(int index, Polyline* polyline) const;
26
void split_at_first_point(Polyline* polyline) const;
27
void equally_spaced_points(double distance, Points* points) const;
29
bool is_counter_clockwise() const;
30
bool is_clockwise() const;
31
bool make_counter_clockwise();
32
bool make_clockwise();
33
bool is_valid() const;
34
bool contains_point(const Point &point) const;
35
Polygons simplify(double tolerance) const;
36
void simplify(double tolerance, Polygons &polygons) const;
37
void triangulate_convex(Polygons* polygons) const;
38
Point centroid() const;
41
void from_SV_check(SV* poly_sv);
48
#include <boost/polygon/polygon.hpp>
49
namespace boost { namespace polygon {
51
struct geometry_concept<Polygon>{ typedef polygon_concept type; };
54
struct polygon_traits<Polygon> {
55
typedef coord_t coordinate_type;
56
typedef Points::const_iterator iterator_type;
57
typedef Point point_type;
59
// Get the begin iterator
60
static inline iterator_type begin_points(const Polygon& t) {
61
return t.points.begin();
64
// Get the end iterator
65
static inline iterator_type end_points(const Polygon& t) {
66
return t.points.end();
69
// Get the number of sides of the polygon
70
static inline std::size_t size(const Polygon& t) {
71
return t.points.size();
74
// Get the winding direction of the polygon
75
static inline winding_direction winding(const Polygon& t) {
76
return unknown_winding;
81
struct polygon_mutable_traits<Polygon> {
82
// expects stl style iterators
83
template <typename iT>
84
static inline Polygon& set_points(Polygon& polygon, iT input_begin, iT input_end) {
85
polygon.points.clear();
86
while (input_begin != input_end) {
87
polygon.points.push_back(Point());
88
boost::polygon::assign(polygon.points.back(), *input_begin);
91
// skip last point since Boost will set last point = first point
92
polygon.points.pop_back();
98
struct geometry_concept<Polygons> { typedef polygon_set_concept type; };
100
//next we map to the concept through traits
102
struct polygon_set_traits<Polygons> {
103
typedef coord_t coordinate_type;
104
typedef Polygons::const_iterator iterator_type;
105
typedef Polygons operator_arg_type;
107
static inline iterator_type begin(const Polygons& polygon_set) {
108
return polygon_set.begin();
111
static inline iterator_type end(const Polygons& polygon_set) {
112
return polygon_set.end();
115
//don't worry about these, just return false from them
116
static inline bool clean(const Polygons& polygon_set) { return false; }
117
static inline bool sorted(const Polygons& polygon_set) { return false; }
121
struct polygon_set_mutable_traits<Polygons> {
122
template <typename input_iterator_type>
123
static inline void set(Polygons& polygons, input_iterator_type input_begin, input_iterator_type input_end) {
124
polygons.assign(input_begin, input_end);