Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:48:01

0001 /*
0002   Copyright 2008 Intel Corporation
0003 
0004   Use, modification and distribution are subject to the Boost Software License,
0005   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006   http://www.boost.org/LICENSE_1_0.txt).
0007 */
0008 #ifndef BOOST_POLYGON_POLYGON_90_SET_TRAITS_HPP
0009 #define BOOST_POLYGON_POLYGON_90_SET_TRAITS_HPP
0010 namespace boost { namespace polygon{
0011 
0012   struct polygon_90_set_concept {};
0013 
0014   template <typename T, typename T2>
0015   struct traits_by_concept {};
0016   template <typename T>
0017   struct traits_by_concept<T, coordinate_concept> { typedef coordinate_traits<T> type; };
0018   template <typename T>
0019   struct traits_by_concept<T, interval_concept> { typedef interval_traits<T> type; };
0020   template <typename T>
0021   struct traits_by_concept<T, point_concept> { typedef point_traits<T> type; };
0022   template <typename T>
0023   struct traits_by_concept<T, rectangle_concept> { typedef rectangle_traits<T> type; };
0024   template <typename T>
0025   struct traits_by_concept<T, segment_concept> { typedef segment_traits<T> type; };
0026   template <typename T>
0027   struct traits_by_concept<T, polygon_90_concept> { typedef polygon_traits<T> type; };
0028   template <typename T>
0029   struct traits_by_concept<T, polygon_90_with_holes_concept> { typedef polygon_traits<T> type; };
0030   template <typename T>
0031   struct traits_by_concept<T, polygon_45_concept> { typedef polygon_traits<T> type; };
0032   template <typename T>
0033   struct traits_by_concept<T, polygon_45_with_holes_concept> { typedef polygon_traits<T> type; };
0034   template <typename T>
0035   struct traits_by_concept<T, polygon_concept> { typedef polygon_traits<T> type; };
0036   template <typename T>
0037   struct traits_by_concept<T, polygon_with_holes_concept> { typedef polygon_traits<T> type; };
0038 
0039   struct polygon_45_set_concept;
0040   struct polygon_set_concept;
0041   template <typename T>
0042   struct polygon_90_set_traits;
0043   template <typename T>
0044   struct polygon_45_set_traits;
0045   template <typename T>
0046   struct polygon_set_traits;
0047   template <typename T>
0048   struct traits_by_concept<T, polygon_90_set_concept> { typedef polygon_90_set_traits<T> type; };
0049   template <typename T>
0050   struct traits_by_concept<T, polygon_45_set_concept> { typedef polygon_45_set_traits<T> type; };
0051   template <typename T>
0052   struct traits_by_concept<T, polygon_set_concept> { typedef polygon_set_traits<T> type; };
0053 
0054   template <typename T, typename T2>
0055   struct get_coordinate_type {
0056     typedef typename traits_by_concept<T, T2>::type traits_type;
0057     typedef typename traits_type::coordinate_type type;
0058   };
0059   //want to prevent recursive template definition syntax errors, so duplicate get_coordinate_type
0060   template <typename T, typename T2>
0061   struct get_coordinate_type_2 {
0062     typedef typename traits_by_concept<T, T2>::type traits_type;
0063     typedef typename traits_type::coordinate_type type;
0064   };
0065   template <typename T>
0066   struct get_coordinate_type<T, undefined_concept> {
0067     typedef typename get_coordinate_type_2<typename std::iterator_traits
0068                                            <typename T::iterator>::value_type,
0069                                            typename geometry_concept<typename std::iterator_traits
0070                                                                      <typename T::iterator>::value_type>::type>::type type; };
0071 
0072   template <typename T, typename T2>
0073   struct get_iterator_type_2 {
0074     typedef const T* type;
0075     static type begin(const T& t) { return &t; }
0076     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
0077   };
0078   template <typename T>
0079   struct get_iterator_type {
0080     typedef get_iterator_type_2<T, typename geometry_concept<T>::type> indirect_type;
0081     typedef typename indirect_type::type type;
0082     static type begin(const T& t) { return indirect_type::begin(t); }
0083     static type end(const T& t) { return indirect_type::end(t); }
0084   };
0085   template <typename T>
0086   struct get_iterator_type_2<T, undefined_concept> {
0087     typedef typename T::const_iterator type;
0088     static type begin(const T& t) { return t.begin(); }
0089     static type end(const T& t) { return t.end(); }
0090   };
0091 
0092 //   //helpers for allowing polygon 45 and containers of polygon 45 to behave interchangably in polygon_45_set_traits
0093 //   template <typename T, typename T2>
0094 //   struct get_coordinate_type_45 {};
0095 //   template <typename T, typename T2>
0096 //   struct get_coordinate_type_2_45 {};
0097 //   template <typename T>
0098 //   struct get_coordinate_type_45<T, void> {
0099 //     typedef typename get_coordinate_type_2_45< typename T::value_type, typename geometry_concept<typename T::value_type>::type >::type type; };
0100 //   template <typename T>
0101 //   struct get_coordinate_type_45<T, polygon_45_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
0102 //   template <typename T>
0103 //   struct get_coordinate_type_45<T, polygon_45_with_holes_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
0104 //   template <typename T>
0105 //   struct get_coordinate_type_2_45<T, polygon_45_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
0106 //   template <typename T>
0107 //   struct get_coordinate_type_2_45<T, polygon_45_with_holes_concept> { typedef typename polygon_traits<T>::coordinate_type type; };
0108 //   template <typename T, typename T2>
0109 //   struct get_iterator_type_45 {};
0110 //   template <typename T>
0111 //   struct get_iterator_type_45<T, void> {
0112 //     typedef typename T::const_iterator type;
0113 //     static type begin(const T& t) { return t.begin(); }
0114 //     static type end(const T& t) { return t.end(); }
0115 //   };
0116 //   template <typename T>
0117 //   struct get_iterator_type_45<T, polygon_45_concept> {
0118 //     typedef const T* type;
0119 //     static type begin(const T& t) { return &t; }
0120 //     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
0121 //   };
0122 //   template <typename T>
0123 //   struct get_iterator_type_45<T, polygon_45_with_holes_concept> {
0124 //     typedef const T* type;
0125 //     static type begin(const T& t) { return &t; }
0126 //     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
0127 //   };
0128 //   template <typename T>
0129 //   struct get_iterator_type_45<T, polygon_90_set_concept> {
0130 //     typedef const T* type;
0131 //     static type begin(const T& t) { return &t; }
0132 //     static type end(const T& t) { const T* tp = &t; ++tp; return tp; }
0133 //   };
0134 
0135   template <typename T>
0136   struct polygon_90_set_traits {
0137     typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
0138     typedef get_iterator_type<T> indirection_type;
0139     typedef typename get_iterator_type<T>::type iterator_type;
0140     typedef T operator_arg_type;
0141 
0142     static inline iterator_type begin(const T& polygon_set) {
0143       return indirection_type::begin(polygon_set);
0144     }
0145 
0146     static inline iterator_type end(const T& polygon_set) {
0147       return indirection_type::end(polygon_set);
0148     }
0149 
0150     static inline orientation_2d orient(const T&) { return HORIZONTAL; }
0151 
0152     static inline bool clean(const T&) { return false; }
0153 
0154     static inline bool sorted(const T&) { return false; }
0155   };
0156 
0157   template <typename T>
0158   struct is_manhattan_polygonal_concept { typedef gtl_no type; };
0159   template <>
0160   struct is_manhattan_polygonal_concept<rectangle_concept> { typedef gtl_yes type; };
0161   template <>
0162   struct is_manhattan_polygonal_concept<polygon_90_concept> { typedef gtl_yes type; };
0163   template <>
0164   struct is_manhattan_polygonal_concept<polygon_90_with_holes_concept> { typedef gtl_yes type; };
0165   template <>
0166   struct is_manhattan_polygonal_concept<polygon_90_set_concept> { typedef gtl_yes type; };
0167 
0168   template <typename T>
0169   struct is_polygon_90_set_type {
0170     typedef typename is_manhattan_polygonal_concept<typename geometry_concept<T>::type>::type type;
0171   };
0172   template <typename T>
0173   struct is_polygon_90_set_type<std::list<T> > {
0174     typedef typename gtl_or<
0175       typename is_manhattan_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type,
0176       typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
0177   };
0178   template <typename T>
0179   struct is_polygon_90_set_type<std::vector<T> > {
0180     typedef typename gtl_or<
0181       typename is_manhattan_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type,
0182       typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
0183   };
0184 
0185   template <typename T>
0186   struct is_mutable_polygon_90_set_type {
0187     typedef typename gtl_same_type<polygon_90_set_concept, typename geometry_concept<T>::type>::type type;
0188   };
0189   template <typename T>
0190   struct is_mutable_polygon_90_set_type<std::list<T> > {
0191     typedef typename gtl_or<
0192       typename gtl_same_type<polygon_90_set_concept, typename geometry_concept<std::list<T> >::type>::type,
0193       typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
0194   };
0195   template <typename T>
0196   struct is_mutable_polygon_90_set_type<std::vector<T> > {
0197     typedef typename gtl_or<
0198       typename gtl_same_type<polygon_90_set_concept, typename geometry_concept<std::vector<T> >::type>::type,
0199       typename is_manhattan_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
0200   };
0201 
0202 //   //specialization for rectangle, polygon_90 and polygon_90_with_holes types
0203 //   template <typename T>
0204 //   struct polygon_90_set_traits
0205 //     typedef typename geometry_concept<T>::type concept_type;
0206 //     typedef typename get_coordinate_type<T, concept_type>::type coordinate_type;
0207 //     typedef iterator_geometry_to_set<concept_type, T> iterator_type;
0208 //     typedef T operator_arg_type;
0209 
0210 //     static inline iterator_type begin(const T& polygon_set) {
0211 //       return iterator_geometry_to_set<concept_type, T>(polygon_set, LOW, HORIZONTAL);
0212 //     }
0213 
0214 //     static inline iterator_type end(const T& polygon_set) {
0215 //       return iterator_geometry_to_set<concept_type, T>(polygon_set, HIGH, HORIZONTAL);
0216 //     }
0217 
0218 //     static inline orientation_2d orient(const T& polygon_set) { return HORIZONTAL; }
0219 
0220 //     static inline bool clean(const T& polygon_set) { return false; }
0221 
0222 //     static inline bool sorted(const T& polygon_set) { return false; }
0223 
0224 //   };
0225 
0226 //   //specialization for containers of recangle, polygon_90, polygon_90_with_holes
0227 //   template <typename T>
0228 //   struct polygon_90_set_traits<T, typename is_manhattan_polygonal_concept<typename std::iterator_traits<typename T::iterator>::value_type>::type> {
0229 //     typedef typename std::iterator_traits<typename T::iterator>::value_type geometry_type;
0230 //     typedef typename geometry_concept<geometry_type>::type concept_type;
0231 //     typedef typename get_coordinate_type<geometry_type, concept_type>::type coordinate_type;
0232 //     typedef iterator_geometry_range_to_set<concept_type, typename T::const_iterator> iterator_type;
0233 //     typedef T operator_arg_type;
0234 
0235 //     static inline iterator_type begin(const T& polygon_set) {
0236 //       return iterator_type(polygon_set.begin(), HORIZONTAL);
0237 //     }
0238 
0239 //     static inline iterator_type end(const T& polygon_set) {
0240 //       return iterator_type(polygon_set.end(), HORIZONTAL);
0241 //     }
0242 
0243 //     static inline orientation_2d orient(const T& polygon_set) { return HORIZONTAL; }
0244 
0245 //     static inline bool clean(const T& polygon_set) { return false; }
0246 
0247 //     static inline bool sorted(const T& polygon_set) { return false; }
0248 
0249 //   };
0250 
0251   //get dispatch functions
0252   template <typename output_container_type, typename pst>
0253   void get_90_dispatch(output_container_type& output, const pst& ps,
0254                        orientation_2d orient, rectangle_concept ) {
0255     form_rectangles(output, ps.begin(), ps.end(), orient, rectangle_concept());
0256   }
0257 
0258   template <typename output_container_type, typename pst>
0259   void get_90_dispatch(output_container_type& output, const pst& ps,
0260                        orientation_2d orient, polygon_90_concept tag) {
0261     get_polygons(output, ps.begin(), ps.end(), orient, true, tag);
0262   }
0263 
0264   template <typename output_container_type, typename pst>
0265   void get_90_dispatch(output_container_type& output, const pst& ps,
0266                        orientation_2d orient, polygon_90_with_holes_concept tag) {
0267     get_polygons(output, ps.begin(), ps.end(), orient, false, tag);
0268   }
0269 
0270   //by default works with containers of rectangle, polygon or polygon with holes
0271   //must be specialized to work with anything else
0272   template <typename T>
0273   struct polygon_90_set_mutable_traits {};
0274   template <typename T>
0275   struct polygon_90_set_mutable_traits<std::list<T> > {
0276     typedef typename geometry_concept<T>::type concept_type;
0277     template <typename input_iterator_type>
0278     static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end, orientation_2d orient) {
0279       polygon_set.clear();
0280       polygon_90_set_data<typename polygon_90_set_traits<std::list<T> >::coordinate_type> ps(orient);
0281       ps.reserve(std::distance(input_begin, input_end));
0282       ps.insert(input_begin, input_end, orient);
0283       ps.clean();
0284       get_90_dispatch(polygon_set, ps, orient, concept_type());
0285     }
0286   };
0287   template <typename T>
0288   struct polygon_90_set_mutable_traits<std::vector<T> > {
0289     typedef typename geometry_concept<T>::type concept_type;
0290     template <typename input_iterator_type>
0291     static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end, orientation_2d orient) {
0292       polygon_set.clear();
0293       size_t num_ele = std::distance(input_begin, input_end);
0294       polygon_set.reserve(num_ele);
0295       polygon_90_set_data<typename polygon_90_set_traits<std::list<T> >::coordinate_type> ps(orient);
0296       ps.reserve(num_ele);
0297       ps.insert(input_begin, input_end, orient);
0298       ps.clean();
0299       get_90_dispatch(polygon_set, ps, orient, concept_type());
0300     }
0301   };
0302 
0303   template <typename T>
0304   struct polygon_90_set_mutable_traits<polygon_90_set_data<T> > {
0305 
0306     template <typename input_iterator_type>
0307     static inline void set(polygon_90_set_data<T>& polygon_set,
0308                            input_iterator_type input_begin, input_iterator_type input_end,
0309                            orientation_2d orient) {
0310       polygon_set.clear();
0311       polygon_set.reserve(std::distance(input_begin, input_end));
0312       polygon_set.insert(input_begin, input_end, orient);
0313     }
0314 
0315   };
0316 
0317   template <typename T>
0318   struct polygon_90_set_traits<polygon_90_set_data<T> > {
0319     typedef typename polygon_90_set_data<T>::coordinate_type coordinate_type;
0320     typedef typename polygon_90_set_data<T>::iterator_type iterator_type;
0321     typedef typename polygon_90_set_data<T>::operator_arg_type operator_arg_type;
0322 
0323     static inline iterator_type begin(const polygon_90_set_data<T>& polygon_set) {
0324       return polygon_set.begin();
0325     }
0326 
0327     static inline iterator_type end(const polygon_90_set_data<T>& polygon_set) {
0328       return polygon_set.end();
0329     }
0330 
0331     static inline orientation_2d orient(const polygon_90_set_data<T>& polygon_set) { return polygon_set.orient(); }
0332 
0333     static inline bool clean(const polygon_90_set_data<T>& polygon_set) { polygon_set.clean(); return true; }
0334 
0335     static inline bool sorted(const polygon_90_set_data<T>& polygon_set) { polygon_set.sort(); return true; }
0336 
0337   };
0338 
0339   template <typename T>
0340   struct is_polygon_90_set_concept { };
0341   template <>
0342   struct is_polygon_90_set_concept<polygon_90_set_concept> { typedef gtl_yes type; };
0343   template <>
0344   struct is_polygon_90_set_concept<rectangle_concept> { typedef gtl_yes type; };
0345   template <>
0346   struct is_polygon_90_set_concept<polygon_90_concept> { typedef gtl_yes type; };
0347   template <>
0348   struct is_polygon_90_set_concept<polygon_90_with_holes_concept> { typedef gtl_yes type; };
0349 
0350   template <typename T>
0351   struct is_mutable_polygon_90_set_concept { typedef gtl_no type; };
0352   template <>
0353   struct is_mutable_polygon_90_set_concept<polygon_90_set_concept> { typedef gtl_yes type; };
0354 
0355   template <typename T>
0356   struct geometry_concept<polygon_90_set_data<T> > { typedef polygon_90_set_concept type; };
0357 
0358   //template <typename T>
0359   //typename enable_if<typename is_polygon_90_set_type<T>::type, void>::type
0360   //print_is_polygon_90_set_concept(const T& t) { std::cout << "is polygon 90 set concept\n"; }
0361   //template <typename T>
0362   //typename enable_if<typename is_mutable_polygon_90_set_type<T>::type, void>::type
0363   //print_is_mutable_polygon_90_set_concept(const T& t) { std::cout << "is mutable polygon 90 set concept\n"; }
0364 }
0365 }
0366 #endif