1 #ifndef SLA_BOOSTADAPTER_HPP
2 #define SLA_BOOSTADAPTER_HPP
3 
4 #include <libslic3r/Point.hpp>
5 #include <libslic3r/BoundingBox.hpp>
6 
7 #include <boost/geometry.hpp>
8 
9 namespace boost {
10 namespace geometry {
11 namespace traits {
12 
13 /* ************************************************************************** */
14 /* Point concept adaptation ************************************************* */
15 /* ************************************************************************** */
16 
17 template<> struct tag<Slic3r::Point> {
18     using type = point_tag;
19 };
20 
21 template<> struct coordinate_type<Slic3r::Point> {
22     using type = coord_t;
23 };
24 
25 template<> struct coordinate_system<Slic3r::Point> {
26     using type = cs::cartesian;
27 };
28 
29 template<> struct dimension<Slic3r::Point>: boost::mpl::int_<2> {};
30 
31 template<std::size_t d> struct access<Slic3r::Point, d > {
getboost::geometry::traits::access32     static inline coord_t get(Slic3r::Point const& a) {
33         return a(d);
34     }
35 
setboost::geometry::traits::access36     static inline void set(Slic3r::Point& a, coord_t const& value) {
37         a(d) = value;
38     }
39 };
40 
41 // For Vec2d ///////////////////////////////////////////////////////////////////
42 
43 template<> struct tag<Slic3r::Vec2d> {
44     using type = point_tag;
45 };
46 
47 template<> struct coordinate_type<Slic3r::Vec2d> {
48     using type = double;
49 };
50 
51 template<> struct coordinate_system<Slic3r::Vec2d> {
52     using type = cs::cartesian;
53 };
54 
55 template<> struct dimension<Slic3r::Vec2d>: boost::mpl::int_<2> {};
56 
57 template<std::size_t d> struct access<Slic3r::Vec2d, d > {
getboost::geometry::traits::access58     static inline double get(Slic3r::Vec2d const& a) {
59         return a(d);
60     }
61 
setboost::geometry::traits::access62     static inline void set(Slic3r::Vec2d& a, double const& value) {
63         a(d) = value;
64     }
65 };
66 
67 // For Vec3d ///////////////////////////////////////////////////////////////////
68 
69 template<> struct tag<Slic3r::Vec3d> {
70     using type = point_tag;
71 };
72 
73 template<> struct coordinate_type<Slic3r::Vec3d> {
74     using type = double;
75 };
76 
77 template<> struct coordinate_system<Slic3r::Vec3d> {
78     using type = cs::cartesian;
79 };
80 
81 template<> struct dimension<Slic3r::Vec3d>: boost::mpl::int_<3> {};
82 
83 template<std::size_t d> struct access<Slic3r::Vec3d, d > {
getboost::geometry::traits::access84     static inline double get(Slic3r::Vec3d const& a) {
85         return a(d);
86     }
87 
setboost::geometry::traits::access88     static inline void set(Slic3r::Vec3d& a, double const& value) {
89         a(d) = value;
90     }
91 };
92 
93 /* ************************************************************************** */
94 /* Box concept adaptation *************************************************** */
95 /* ************************************************************************** */
96 
97 template<> struct tag<Slic3r::BoundingBox> {
98     using type = box_tag;
99 };
100 
101 template<> struct point_type<Slic3r::BoundingBox> {
102     using type = Slic3r::Point;
103 };
104 
105 template<std::size_t d>
106 struct indexed_access<Slic3r::BoundingBox, 0, d> {
getboost::geometry::traits::indexed_access107     static inline coord_t get(Slic3r::BoundingBox const& box) {
108         return box.min(d);
109     }
setboost::geometry::traits::indexed_access110     static inline void set(Slic3r::BoundingBox &box, coord_t const& coord) {
111         box.min(d) = coord;
112     }
113 };
114 
115 template<std::size_t d>
116 struct indexed_access<Slic3r::BoundingBox, 1, d> {
getboost::geometry::traits::indexed_access117     static inline coord_t get(Slic3r::BoundingBox const& box) {
118         return box.max(d);
119     }
setboost::geometry::traits::indexed_access120     static inline void set(Slic3r::BoundingBox &box, coord_t const& coord) {
121         box.max(d) = coord;
122     }
123 };
124 
125 }
126 }
127 
128 template<> struct range_value<std::vector<Slic3r::Vec2d>> {
129     using type = Slic3r::Vec2d;
130 };
131 
132 }
133 
134 #endif // SLABOOSTADAPTER_HPP
135