]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | Copyright 2008 Intel Corporation | |
3 | ||
4 | Use, modification and distribution are subject to the Boost Software License, | |
5 | Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
6 | http://www.boost.org/LICENSE_1_0.txt). | |
7 | */ | |
8 | #ifndef BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP | |
9 | #define BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP | |
10 | namespace boost { namespace polygon{ | |
11 | ||
12 | //default definition of polygon 45 set traits works for any model of polygon 45, polygon 45 with holes or any vector or list thereof | |
13 | template <typename T> | |
14 | struct polygon_45_set_traits { | |
15 | typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type; | |
16 | typedef typename get_iterator_type<T>::type iterator_type; | |
17 | typedef T operator_arg_type; | |
18 | ||
19 | static inline iterator_type begin(const T& polygon_set) { | |
20 | return get_iterator_type<T>::begin(polygon_set); | |
21 | } | |
22 | ||
23 | static inline iterator_type end(const T& polygon_set) { | |
24 | return get_iterator_type<T>::end(polygon_set); | |
25 | } | |
26 | ||
27 | static inline bool clean(const T& ) { return false; } | |
28 | ||
29 | static inline bool sorted(const T& ) { return false; } | |
30 | }; | |
31 | ||
32 | template <typename T> | |
33 | struct is_45_polygonal_concept { typedef gtl_no type; }; | |
34 | template <> | |
35 | struct is_45_polygonal_concept<polygon_45_concept> { typedef gtl_yes type; }; | |
36 | template <> | |
37 | struct is_45_polygonal_concept<polygon_45_with_holes_concept> { typedef gtl_yes type; }; | |
38 | template <> | |
39 | struct is_45_polygonal_concept<polygon_45_set_concept> { typedef gtl_yes type; }; | |
40 | ||
41 | template <typename T> | |
42 | struct is_polygon_45_set_type { | |
43 | typedef typename is_45_polygonal_concept<typename geometry_concept<T>::type>::type type; | |
44 | }; | |
45 | template <typename T> | |
46 | struct is_polygon_45_set_type<std::list<T> > { | |
47 | typedef typename gtl_or< | |
48 | typename is_45_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type, | |
49 | typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type; | |
50 | }; | |
51 | template <typename T> | |
52 | struct is_polygon_45_set_type<std::vector<T> > { | |
53 | typedef typename gtl_or< | |
54 | typename is_45_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type, | |
55 | typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type; | |
56 | }; | |
57 | ||
58 | template <typename T> | |
59 | struct is_mutable_polygon_45_set_type { | |
60 | typedef typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<T>::type>::type type; | |
61 | }; | |
62 | template <typename T> | |
63 | struct is_mutable_polygon_45_set_type<std::list<T> > { | |
64 | typedef typename gtl_or< | |
65 | typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::list<T> >::type>::type, | |
66 | typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type; | |
67 | }; | |
68 | template <typename T> | |
69 | struct is_mutable_polygon_45_set_type<std::vector<T> > { | |
70 | typedef typename gtl_or< | |
71 | typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::vector<T> >::type>::type, | |
72 | typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type; | |
73 | }; | |
74 | ||
75 | template <typename T> | |
76 | bool fracture_holes_45_by_concept() { return false; } | |
77 | template <> | |
78 | inline bool fracture_holes_45_by_concept<polygon_45_concept>() { return true; } | |
79 | ||
80 | template <typename T, typename iT> | |
81 | void get_45_polygons_T(T& t, iT begin, iT end) { | |
82 | typedef typename polygon_45_set_traits<T>::coordinate_type Unit; | |
83 | typedef typename geometry_concept<typename T::value_type>::type CType; | |
84 | typename polygon_45_formation<Unit>::Polygon45Formation pf(fracture_holes_45_by_concept<CType>()); | |
85 | //std::cout << "FORMING POLYGONS\n"; | |
86 | pf.scan(t, begin, end); | |
87 | } | |
88 | ||
89 | template <typename T> | |
90 | struct polygon_45_set_mutable_traits {}; | |
91 | template <typename T> | |
92 | struct polygon_45_set_mutable_traits<std::list<T> > { | |
93 | template <typename input_iterator_type> | |
94 | static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) { | |
95 | polygon_set.clear(); | |
96 | polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps; | |
97 | ps.reserve(std::distance(input_begin, input_end)); | |
98 | ps.insert(input_begin, input_end); | |
99 | ps.sort(); | |
100 | ps.clean(); | |
101 | get_45_polygons_T(polygon_set, ps.begin(), ps.end()); | |
102 | } | |
103 | }; | |
104 | template <typename T> | |
105 | struct polygon_45_set_mutable_traits<std::vector<T> > { | |
106 | template <typename input_iterator_type> | |
107 | static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) { | |
108 | polygon_set.clear(); | |
109 | size_t num_ele = std::distance(input_begin, input_end); | |
110 | polygon_set.reserve(num_ele); | |
111 | polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps; | |
112 | ps.reserve(num_ele); | |
113 | ps.insert(input_begin, input_end); | |
114 | ps.sort(); | |
115 | ps.clean(); | |
116 | get_45_polygons_T(polygon_set, ps.begin(), ps.end()); | |
117 | } | |
118 | }; | |
119 | ||
120 | template <typename T> | |
121 | struct polygon_45_set_mutable_traits<polygon_45_set_data<T> > { | |
122 | template <typename input_iterator_type> | |
123 | static inline void set(polygon_45_set_data<T>& polygon_set, | |
124 | input_iterator_type input_begin, input_iterator_type input_end) { | |
125 | polygon_set.set(input_begin, input_end); | |
126 | } | |
127 | }; | |
128 | template <typename T> | |
129 | struct polygon_45_set_traits<polygon_45_set_data<T> > { | |
130 | typedef typename polygon_45_set_data<T>::coordinate_type coordinate_type; | |
131 | typedef typename polygon_45_set_data<T>::iterator_type iterator_type; | |
132 | typedef typename polygon_45_set_data<T>::operator_arg_type operator_arg_type; | |
133 | ||
134 | static inline iterator_type begin(const polygon_45_set_data<T>& polygon_set) { | |
135 | return polygon_set.begin(); | |
136 | } | |
137 | ||
138 | static inline iterator_type end(const polygon_45_set_data<T>& polygon_set) { | |
139 | return polygon_set.end(); | |
140 | } | |
141 | ||
142 | static inline bool clean(const polygon_45_set_data<T>& polygon_set) { polygon_set.clean(); return true; } | |
143 | ||
144 | static inline bool sorted(const polygon_45_set_data<T>& polygon_set) { polygon_set.sort(); return true; } | |
145 | ||
146 | }; | |
147 | } | |
148 | } | |
149 | #endif |