123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- /*
- 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
|