Back to home page

EIC code displayed by LXR

 
 

    


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

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_45_SET_TRAITS_HPP
0009 #define BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP
0010 namespace boost { namespace polygon{
0011 
0012   //default definition of polygon 45 set traits works for any model of polygon 45, polygon 45 with holes or any vector or list thereof
0013   template <typename T>
0014   struct polygon_45_set_traits {
0015     typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
0016     typedef typename get_iterator_type<T>::type iterator_type;
0017     typedef T operator_arg_type;
0018 
0019     static inline iterator_type begin(const T& polygon_set) {
0020       return get_iterator_type<T>::begin(polygon_set);
0021     }
0022 
0023     static inline iterator_type end(const T& polygon_set) {
0024       return get_iterator_type<T>::end(polygon_set);
0025     }
0026 
0027     static inline bool clean(const T& ) { return false; }
0028 
0029     static inline bool sorted(const T& ) { return false; }
0030   };
0031 
0032   template <typename T>
0033   struct is_45_polygonal_concept { typedef gtl_no type; };
0034   template <>
0035   struct is_45_polygonal_concept<polygon_45_concept> { typedef gtl_yes type; };
0036   template <>
0037   struct is_45_polygonal_concept<polygon_45_with_holes_concept> { typedef gtl_yes type; };
0038   template <>
0039   struct is_45_polygonal_concept<polygon_45_set_concept> { typedef gtl_yes type; };
0040 
0041   template <typename T>
0042   struct is_polygon_45_set_type {
0043     typedef typename is_45_polygonal_concept<typename geometry_concept<T>::type>::type type;
0044   };
0045   template <typename T>
0046   struct is_polygon_45_set_type<std::list<T> > {
0047     typedef typename gtl_or<
0048       typename is_45_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type,
0049       typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
0050   };
0051   template <typename T>
0052   struct is_polygon_45_set_type<std::vector<T> > {
0053     typedef typename gtl_or<
0054       typename is_45_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type,
0055       typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
0056   };
0057 
0058   template <typename T>
0059   struct is_mutable_polygon_45_set_type {
0060     typedef typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<T>::type>::type type;
0061   };
0062   template <typename T>
0063   struct is_mutable_polygon_45_set_type<std::list<T> > {
0064     typedef typename gtl_or<
0065       typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::list<T> >::type>::type,
0066       typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
0067   };
0068   template <typename T>
0069   struct is_mutable_polygon_45_set_type<std::vector<T> > {
0070     typedef typename gtl_or<
0071       typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::vector<T> >::type>::type,
0072       typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
0073   };
0074 
0075   template <typename T>
0076   bool fracture_holes_45_by_concept() { return false; }
0077   template <>
0078   inline bool fracture_holes_45_by_concept<polygon_45_concept>() { return true; }
0079 
0080   template <typename T, typename iT>
0081   void get_45_polygons_T(T& t, iT begin, iT end) {
0082     typedef typename polygon_45_set_traits<T>::coordinate_type Unit;
0083     typedef typename geometry_concept<typename T::value_type>::type CType;
0084     typename polygon_45_formation<Unit>::Polygon45Formation pf(fracture_holes_45_by_concept<CType>());
0085     //std::cout << "FORMING POLYGONS\n";
0086     pf.scan(t, begin, end);
0087   }
0088 
0089   template <typename T>
0090   struct polygon_45_set_mutable_traits {};
0091   template <typename T>
0092   struct polygon_45_set_mutable_traits<std::list<T> > {
0093     template <typename input_iterator_type>
0094     static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
0095       polygon_set.clear();
0096       polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps;
0097       ps.reserve(std::distance(input_begin, input_end));
0098       ps.insert(input_begin, input_end);
0099       ps.sort();
0100       ps.clean();
0101       get_45_polygons_T(polygon_set, ps.begin(), ps.end());
0102     }
0103   };
0104   template <typename T>
0105   struct polygon_45_set_mutable_traits<std::vector<T> > {
0106     template <typename input_iterator_type>
0107     static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
0108       polygon_set.clear();
0109       size_t num_ele = std::distance(input_begin, input_end);
0110       polygon_set.reserve(num_ele);
0111       polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps;
0112       ps.reserve(num_ele);
0113       ps.insert(input_begin, input_end);
0114       ps.sort();
0115       ps.clean();
0116       get_45_polygons_T(polygon_set, ps.begin(), ps.end());
0117     }
0118   };
0119 
0120   template <typename T>
0121   struct polygon_45_set_mutable_traits<polygon_45_set_data<T> > {
0122     template <typename input_iterator_type>
0123     static inline void set(polygon_45_set_data<T>& polygon_set,
0124                            input_iterator_type input_begin, input_iterator_type input_end) {
0125       polygon_set.set(input_begin, input_end);
0126     }
0127   };
0128   template <typename T>
0129   struct polygon_45_set_traits<polygon_45_set_data<T> > {
0130     typedef typename polygon_45_set_data<T>::coordinate_type coordinate_type;
0131     typedef typename polygon_45_set_data<T>::iterator_type iterator_type;
0132     typedef typename polygon_45_set_data<T>::operator_arg_type operator_arg_type;
0133 
0134     static inline iterator_type begin(const polygon_45_set_data<T>& polygon_set) {
0135       return polygon_set.begin();
0136     }
0137 
0138     static inline iterator_type end(const polygon_45_set_data<T>& polygon_set) {
0139       return polygon_set.end();
0140     }
0141 
0142     static inline bool clean(const polygon_45_set_data<T>& polygon_set) { polygon_set.clean(); return true; }
0143 
0144     static inline bool sorted(const polygon_45_set_data<T>& polygon_set) { polygon_set.sort(); return true; }
0145 
0146   };
0147 }
0148 }
0149 #endif