summaryrefslogtreecommitdiff
path: root/boost/polygon/polygon_90_set_traits.hpp
blob: c1312e8856f9bac5dc2801ca34a1085ca822b439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
  Copyright 2008 Intel Corporation

  Use, modification and distribution are subject to the Boost Software License,
  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  http://www.boost.org/LICENSE_1_0.txt).
*/
#ifndef BOOST_POLYGON_POLYGON_90_SET_TRAITS_HPP
#define BOOST_POLYGON_POLYGON_90_SET_TRAITS_HPP
namespace boost { namespace polygon{

  struct polygon_90_set_concept {};

  template <typename T, typename T2>
  struct traits_by_concept {};
  template <typename T>
  struct traits_by_concept<T, coordinate_concept> { typedef coordinate_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, interval_concept> { typedef interval_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, point_concept> { typedef point_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, rectangle_concept> { typedef rectangle_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, segment_concept> { typedef segment_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_90_concept> { typedef polygon_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_90_with_holes_concept> { typedef polygon_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_45_concept> { typedef polygon_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_45_with_holes_concept> { typedef polygon_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_concept> { typedef polygon_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_with_holes_concept> { typedef polygon_traits<T> type; };

  struct polygon_45_set_concept;
  struct polygon_set_concept;
  template <typename T>
  struct polygon_90_set_traits;
  template <typename T>
  struct polygon_45_set_traits;
  template <typename T>
  struct polygon_set_traits;
  template <typename T>
  struct traits_by_concept<T, polygon_90_set_concept> { typedef polygon_90_set_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_45_set_concept> { typedef polygon_45_set_traits<T> type; };
  template <typename T>
  struct traits_by_concept<T, polygon_set_concept> { typedef polygon_set_traits<T> type; };

  template <typename T, typename T2>
  struct get_coordinate_type {
    typedef typename traits_by_concept<T, T2>::type traits_type;
    typedef typename traits_type::coordinate_type type;
  };
  //want to prevent recursive template definition syntax errors, so duplicate get_coordinate_type
  template <typename T, typename T2>
  struct get_coordinate_type_2 {
    typedef typename traits_by_concept<T, T2>::type traits_type;
    typedef typename traits_type::coordinate_type type;
  };
  template <typename T>
  struct get_coordinate_type<T, undefined_concept> {
    typedef typename get_coordinate_type_2<typename std::iterator_traits
                                           <typename T::iterator>::value_type,
                                           typename geometry_concept<typename std::iterator_traits
                                                                     <typename T::iterator>::value_type>::type>::type type; };

  template <typename T, typename T2>
  struct get_iterator_type_2 {
    typedef const T* type;
    static type begin(const T& t) { return &t; }
    static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
  };
  template <typename T>
  struct get_iterator_type {
    typedef get_iterator_type_2<T, typename geometry_concept<T>::type> indirect_type;
    typedef typename indirect_type::type type;
    static type begin(const T& t) { return indirect_type::begin(t); }
    static type end(const T& t) { return indirect_type::end(t); }
  };
  template <typename T>
  struct get_iterator_type_2<T, undefined_concept> {
    typedef typename T::const_iterator type;
    static type begin(const T& t) { return t.begin(); }
    static type end(const T& t) { return t.end(); }
  };

//   //helpers for allowing polygon 45 and containers of polygon 45 to behave interchangably in polygon_45_set_traits
//   template <typename T, typename T2>
//   struct get_coordinate_type_45 {};
//   template <typename T, typename T2>
//   struct get_coordinate_type_2_45 {};
//   template <typename T>
//   struct get_coordinate_type_45<T, void> {
//     typedef typename get_coordinate_type_2_45< typename T::value_type, typename geometry_concept<typename T::value_type>::type >::type type; };
//   template <typename T>
//   struct get_coordinate_type_45<T, polygon_45_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
//   template <typename T>
//   struct get_coordinate_type_45<T, polygon_45_with_holes_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
//   template <typename T>
//   struct get_coordinate_type_2_45<T, polygon_45_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
//   template <typename T>
//   struct get_coordinate_type_2_45<T, polygon_45_with_holes_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
//   template <typename T, typename T2>
//   struct get_iterator_type_45 {};
//   template <typename T>
//   struct get_iterator_type_45<T, void> {
//     typedef typename T::const_iterator type;
//     static type begin(const T& t) { return t.begin(); }
//     static type end(const T& t) { return t.end(); }
//   };
//   template <typename T>
//   struct get_iterator_type_45<T, polygon_45_concept> {
//     typedef const T* type;
//     static type begin(const T& t) { return &t; }
//     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
//   };
//   template <typename T>
//   struct get_iterator_type_45<T, polygon_45_with_holes_concept> {
//     typedef const T* type;
//     static type begin(const T& t) { return &t; }
//     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
//   };
//   template <typename T>
//   struct get_iterator_type_45<T, polygon_90_set_concept> {
//     typedef const T* type;
//     static type begin(const T& t) { return &t; }
//     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
//   };

  template <typename T>
  struct polygon_90_set_traits {
    typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
    typedef get_iterator_type<T> indirection_type;
    typedef typename get_iterator_type<T>::type iterator_type;
    typedef T operator_arg_type;

    static inline iterator_type begin(const T& polygon_set) {
      return indirection_type::begin(polygon_set);
    }

    static inline iterator_type end(const T& polygon_set) {
      return indirection_type::end(polygon_set);
    }

    static inline orientation_2d orient(const T&) { return HORIZONTAL; }

    static inline bool clean(const T&) { return false; }

    static inline bool sorted(const T&) { return false; }
  };

  template <typename T>
  struct is_manhattan_polygonal_concept { typedef gtl_no type; };
  template <>
  struct is_manhattan_polygonal_concept<rectangle_concept> { typedef gtl_yes type; };
  template <>
  struct is_manhattan_polygonal_concept<polygon_90_concept> { typedef gtl_yes type; };
  template <>
  struct is_manhattan_polygonal_concept<polygon_90_with_holes_concept> { typedef gtl_yes type; };
  template <>
  struct is_manhattan_polygonal_concept<polygon_90_set_concept> { typedef gtl_yes type; };

  template <typename T>
  struct is_polygon_90_set_type {
    typedef typename is_manhattan_polygonal_concept<typename geometry_concept<T>::type>::type type;
  };
  template <typename T>
  struct is_polygon_90_set_type<std::list<T> > {
    typedef typename gtl_or<
      typename is_manhattan_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type,
      typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
  };
  template <typename T>
  struct is_polygon_90_set_type<std::vector<T> > {
    typedef typename gtl_or<
      typename is_manhattan_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type,
      typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
  };

  template <typename T>
  struct is_mutable_polygon_90_set_type {
    typedef typename gtl_same_type<polygon_90_set_concept, typename geometry_concept<T>::type>::type type;
  };
  template <typename T>
  struct is_mutable_polygon_90_set_type<std::list<T> > {
    typedef typename gtl_or<
      typename gtl_same_type<polygon_90_set_concept, typename geometry_concept<std::list<T> >::type>::type,
      typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
  };
  template <typename T>
  struct is_mutable_polygon_90_set_type<std::vector<T> > {
    typedef typename gtl_or<
      typename gtl_same_type<polygon_90_set_concept, typename geometry_concept<std::vector<T> >::type>::type,
      typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
  };

//   //specialization for rectangle, polygon_90 and polygon_90_with_holes types
//   template <typename T>
//   struct polygon_90_set_traits
//     typedef typename geometry_concept<T>::type concept_type;
//     typedef typename get_coordinate_type<T, concept_type>::type coordinate_type;
//     typedef iterator_geometry_to_set<concept_type, T> iterator_type;
//     typedef T operator_arg_type;

//     static inline iterator_type begin(const T& polygon_set) {
//       return iterator_geometry_to_set<concept_type, T>(polygon_set, LOW, HORIZONTAL);
//     }

//     static inline iterator_type end(const T& polygon_set) {
//       return iterator_geometry_to_set<concept_type, T>(polygon_set, HIGH, HORIZONTAL);
//     }

//     static inline orientation_2d orient(const T& polygon_set) { return HORIZONTAL; }

//     static inline bool clean(const T& polygon_set) { return false; }

//     static inline bool sorted(const T& polygon_set) { return false; }

//   };

//   //specialization for containers of recangle, polygon_90, polygon_90_with_holes
//   template <typename T>
//   struct polygon_90_set_traits<T, typename is_manhattan_polygonal_concept<typename std::iterator_traits<typename T::iterator>::value_type>::type> {
//     typedef typename std::iterator_traits<typename T::iterator>::value_type geometry_type;
//     typedef typename geometry_concept<geometry_type>::type concept_type;
//     typedef typename get_coordinate_type<geometry_type, concept_type>::type coordinate_type;
//     typedef iterator_geometry_range_to_set<concept_type, typename T::const_iterator> iterator_type;
//     typedef T operator_arg_type;

//     static inline iterator_type begin(const T& polygon_set) {
//       return iterator_type(polygon_set.begin(), HORIZONTAL);
//     }

//     static inline iterator_type end(const T& polygon_set) {
//       return iterator_type(polygon_set.end(), HORIZONTAL);
//     }

//     static inline orientation_2d orient(const T& polygon_set) { return HORIZONTAL; }

//     static inline bool clean(const T& polygon_set) { return false; }

//     static inline bool sorted(const T& polygon_set) { return false; }

//   };

  //get dispatch functions
  template <typename output_container_type, typename pst>
  void get_90_dispatch(output_container_type& output, const pst& ps,
                       orientation_2d orient, rectangle_concept ) {
    form_rectangles(output, ps.begin(), ps.end(), orient, rectangle_concept());
  }

  template <typename output_container_type, typename pst>
  void get_90_dispatch(output_container_type& output, const pst& ps,
                       orientation_2d orient, polygon_90_concept tag) {
    get_polygons(output, ps.begin(), ps.end(), orient, true, tag);
  }

  template <typename output_container_type, typename pst>
  void get_90_dispatch(output_container_type& output, const pst& ps,
                       orientation_2d orient, polygon_90_with_holes_concept tag) {
    get_polygons(output, ps.begin(), ps.end(), orient, false, tag);
  }

  //by default works with containers of rectangle, polygon or polygon with holes
  //must be specialized to work with anything else
  template <typename T>
  struct polygon_90_set_mutable_traits {};
  template <typename T>
  struct polygon_90_set_mutable_traits<std::list<T> > {
    typedef typename geometry_concept<T>::type concept_type;
    template <typename input_iterator_type>
    static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end, orientation_2d orient) {
      polygon_set.clear();
      polygon_90_set_data<typename polygon_90_set_traits<std::list<T> >::coordinate_type> ps(orient);
      ps.reserve(std::distance(input_begin, input_end));
      ps.insert(input_begin, input_end, orient);
      ps.clean();
      get_90_dispatch(polygon_set, ps, orient, concept_type());
    }
  };
  template <typename T>
  struct polygon_90_set_mutable_traits<std::vector<T> > {
    typedef typename geometry_concept<T>::type concept_type;
    template <typename input_iterator_type>
    static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end, orientation_2d orient) {
      polygon_set.clear();
      size_t num_ele = std::distance(input_begin, input_end);
      polygon_set.reserve(num_ele);
      polygon_90_set_data<typename polygon_90_set_traits<std::list<T> >::coordinate_type> ps(orient);
      ps.reserve(num_ele);
      ps.insert(input_begin, input_end, orient);
      ps.clean();
      get_90_dispatch(polygon_set, ps, orient, concept_type());
    }
  };

  template <typename T>
  struct polygon_90_set_mutable_traits<polygon_90_set_data<T> > {

    template <typename input_iterator_type>
    static inline void set(polygon_90_set_data<T>& polygon_set,
                           input_iterator_type input_begin, input_iterator_type input_end,
                           orientation_2d orient) {
      polygon_set.clear();
      polygon_set.reserve(std::distance(input_begin, input_end));
      polygon_set.insert(input_begin, input_end, orient);
    }

  };

  template <typename T>
  struct polygon_90_set_traits<polygon_90_set_data<T> > {
    typedef typename polygon_90_set_data<T>::coordinate_type coordinate_type;
    typedef typename polygon_90_set_data<T>::iterator_type iterator_type;
    typedef typename polygon_90_set_data<T>::operator_arg_type operator_arg_type;

    static inline iterator_type begin(const polygon_90_set_data<T>& polygon_set) {
      return polygon_set.begin();
    }

    static inline iterator_type end(const polygon_90_set_data<T>& polygon_set) {
      return polygon_set.end();
    }

    static inline orientation_2d orient(const polygon_90_set_data<T>& polygon_set) { return polygon_set.orient(); }

    static inline bool clean(const polygon_90_set_data<T>& polygon_set) { polygon_set.clean(); return true; }

    static inline bool sorted(const polygon_90_set_data<T>& polygon_set) { polygon_set.sort(); return true; }

  };

  template <typename T>
  struct is_polygon_90_set_concept { };
  template <>
  struct is_polygon_90_set_concept<polygon_90_set_concept> { typedef gtl_yes type; };
  template <>
  struct is_polygon_90_set_concept<rectangle_concept> { typedef gtl_yes type; };
  template <>
  struct is_polygon_90_set_concept<polygon_90_concept> { typedef gtl_yes type; };
  template <>
  struct is_polygon_90_set_concept<polygon_90_with_holes_concept> { typedef gtl_yes type; };

  template <typename T>
  struct is_mutable_polygon_90_set_concept { typedef gtl_no type; };
  template <>
  struct is_mutable_polygon_90_set_concept<polygon_90_set_concept> { typedef gtl_yes type; };

  template <typename T>
  struct geometry_concept<polygon_90_set_data<T> > { typedef polygon_90_set_concept type; };

  //template <typename T>
  //typename enable_if<typename is_polygon_90_set_type<T>::type, void>::type
  //print_is_polygon_90_set_concept(const T& t) { std::cout << "is polygon 90 set concept\n"; }
  //template <typename T>
  //typename enable_if<typename is_mutable_polygon_90_set_type<T>::type, void>::type
  //print_is_mutable_polygon_90_set_concept(const T& t) { std::cout << "is mutable polygon 90 set concept\n"; }
}
}
#endif