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

« back to all changes in this revision

Viewing changes to xs/src/Polygon.hpp

  • 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
#ifndef slic3r_Polygon_hpp_
 
2
#define slic3r_Polygon_hpp_
 
3
 
 
4
#include <myinit.h>
 
5
#include <vector>
 
6
#include "Line.hpp"
 
7
#include "MultiPoint.hpp"
 
8
#include "Polyline.hpp"
 
9
 
 
10
namespace Slic3r {
 
11
 
 
12
class Polygon;
 
13
typedef std::vector<Polygon> Polygons;
 
14
 
 
15
class Polygon : public MultiPoint {
 
16
    public:
 
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;
 
22
    Lines lines() 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;
 
28
    double area() 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;
 
39
    
 
40
    #ifdef SLIC3RXS
 
41
    void from_SV_check(SV* poly_sv);
 
42
    #endif
 
43
};
 
44
 
 
45
}
 
46
 
 
47
// start Boost
 
48
#include <boost/polygon/polygon.hpp>
 
49
namespace boost { namespace polygon {
 
50
    template <>
 
51
    struct geometry_concept<Polygon>{ typedef polygon_concept type; };
 
52
 
 
53
    template <>
 
54
    struct polygon_traits<Polygon> {
 
55
        typedef coord_t coordinate_type;
 
56
        typedef Points::const_iterator iterator_type;
 
57
        typedef Point point_type;
 
58
 
 
59
        // Get the begin iterator
 
60
        static inline iterator_type begin_points(const Polygon& t) {
 
61
            return t.points.begin();
 
62
        }
 
63
 
 
64
        // Get the end iterator
 
65
        static inline iterator_type end_points(const Polygon& t) {
 
66
            return t.points.end();
 
67
        }
 
68
 
 
69
        // Get the number of sides of the polygon
 
70
        static inline std::size_t size(const Polygon& t) {
 
71
            return t.points.size();
 
72
        }
 
73
 
 
74
        // Get the winding direction of the polygon
 
75
        static inline winding_direction winding(const Polygon& t) {
 
76
            return unknown_winding;
 
77
        }
 
78
    };
 
79
 
 
80
    template <>
 
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);
 
89
                ++input_begin;
 
90
            }
 
91
            // skip last point since Boost will set last point = first point
 
92
            polygon.points.pop_back();
 
93
            return polygon;
 
94
        }
 
95
    };
 
96
    
 
97
    template <>
 
98
    struct geometry_concept<Polygons> { typedef polygon_set_concept type; };
 
99
 
 
100
    //next we map to the concept through traits
 
101
    template <>
 
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;
 
106
 
 
107
        static inline iterator_type begin(const Polygons& polygon_set) {
 
108
            return polygon_set.begin();
 
109
        }
 
110
 
 
111
        static inline iterator_type end(const Polygons& polygon_set) {
 
112
            return polygon_set.end();
 
113
        }
 
114
 
 
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; }
 
118
    };
 
119
 
 
120
    template <>
 
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);
 
125
        }
 
126
    };
 
127
} }
 
128
// end Boost
 
129
 
 
130
#endif