Chris@16: /* Chris@16: Copyright 2008 Intel Corporation Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: */ Chris@16: #ifndef BOOST_POLYGON_POLYGON_90_SET_TRAITS_HPP Chris@16: #define BOOST_POLYGON_POLYGON_90_SET_TRAITS_HPP Chris@16: namespace boost { namespace polygon{ Chris@16: Chris@16: struct polygon_90_set_concept {}; Chris@16: Chris@16: template Chris@16: struct traits_by_concept {}; Chris@16: template Chris@16: struct traits_by_concept { typedef coordinate_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef interval_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef point_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef rectangle_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef segment_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_traits type; }; Chris@16: Chris@16: struct polygon_45_set_concept; Chris@16: struct polygon_set_concept; Chris@16: template Chris@16: struct polygon_90_set_traits; Chris@16: template Chris@16: struct polygon_45_set_traits; Chris@16: template Chris@16: struct polygon_set_traits; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_90_set_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_45_set_traits type; }; Chris@16: template Chris@16: struct traits_by_concept { typedef polygon_set_traits type; }; Chris@16: Chris@16: template Chris@16: struct get_coordinate_type { Chris@16: typedef typename traits_by_concept::type traits_type; Chris@16: typedef typename traits_type::coordinate_type type; Chris@16: }; Chris@16: //want to prevent recursive template definition syntax errors, so duplicate get_coordinate_type Chris@16: template Chris@16: struct get_coordinate_type_2 { Chris@16: typedef typename traits_by_concept::type traits_type; Chris@16: typedef typename traits_type::coordinate_type type; Chris@16: }; Chris@16: template Chris@16: struct get_coordinate_type { Chris@16: typedef typename get_coordinate_type_2::value_type, Chris@16: typename geometry_concept::value_type>::type>::type type; }; Chris@16: Chris@16: template Chris@16: struct get_iterator_type_2 { Chris@16: typedef const T* type; Chris@16: static type begin(const T& t) { return &t; } Chris@16: static type end(const T& t) { const T* tp = &t; ++tp; return tp; } Chris@16: }; Chris@16: template Chris@16: struct get_iterator_type { Chris@16: typedef get_iterator_type_2::type> indirect_type; Chris@16: typedef typename indirect_type::type type; Chris@16: static type begin(const T& t) { return indirect_type::begin(t); } Chris@16: static type end(const T& t) { return indirect_type::end(t); } Chris@16: }; Chris@16: template Chris@16: struct get_iterator_type_2 { Chris@16: typedef typename T::const_iterator type; Chris@16: static type begin(const T& t) { return t.begin(); } Chris@16: static type end(const T& t) { return t.end(); } Chris@16: }; Chris@16: Chris@16: // //helpers for allowing polygon 45 and containers of polygon 45 to behave interchangably in polygon_45_set_traits Chris@16: // template Chris@16: // struct get_coordinate_type_45 {}; Chris@16: // template Chris@16: // struct get_coordinate_type_2_45 {}; Chris@16: // template Chris@16: // struct get_coordinate_type_45 { Chris@16: // typedef typename get_coordinate_type_2_45< typename T::value_type, typename geometry_concept::type >::type type; }; Chris@16: // template Chris@16: // struct get_coordinate_type_45 { typedef typename polygon_traits::coordinate_type type; }; Chris@16: // template Chris@16: // struct get_coordinate_type_45 { typedef typename polygon_traits::coordinate_type type; }; Chris@16: // template Chris@16: // struct get_coordinate_type_2_45 { typedef typename polygon_traits::coordinate_type type; }; Chris@16: // template Chris@16: // struct get_coordinate_type_2_45 { typedef typename polygon_traits::coordinate_type type; }; Chris@16: // template Chris@16: // struct get_iterator_type_45 {}; Chris@16: // template Chris@16: // struct get_iterator_type_45 { Chris@16: // typedef typename T::const_iterator type; Chris@16: // static type begin(const T& t) { return t.begin(); } Chris@16: // static type end(const T& t) { return t.end(); } Chris@16: // }; Chris@16: // template Chris@16: // struct get_iterator_type_45 { Chris@16: // typedef const T* type; Chris@16: // static type begin(const T& t) { return &t; } Chris@16: // static type end(const T& t) { const T* tp = &t; ++tp; return tp; } Chris@16: // }; Chris@16: // template Chris@16: // struct get_iterator_type_45 { Chris@16: // typedef const T* type; Chris@16: // static type begin(const T& t) { return &t; } Chris@16: // static type end(const T& t) { const T* tp = &t; ++tp; return tp; } Chris@16: // }; Chris@16: // template Chris@16: // struct get_iterator_type_45 { Chris@16: // typedef const T* type; Chris@16: // static type begin(const T& t) { return &t; } Chris@16: // static type end(const T& t) { const T* tp = &t; ++tp; return tp; } Chris@16: // }; Chris@16: Chris@16: template Chris@16: struct polygon_90_set_traits { Chris@16: typedef typename get_coordinate_type::type >::type coordinate_type; Chris@16: typedef get_iterator_type indirection_type; Chris@16: typedef typename get_iterator_type::type iterator_type; Chris@16: typedef T operator_arg_type; Chris@16: Chris@16: static inline iterator_type begin(const T& polygon_set) { Chris@16: return indirection_type::begin(polygon_set); Chris@16: } Chris@16: Chris@16: static inline iterator_type end(const T& polygon_set) { Chris@16: return indirection_type::end(polygon_set); Chris@16: } Chris@16: Chris@16: static inline orientation_2d orient(const T&) { return HORIZONTAL; } Chris@16: Chris@16: static inline bool clean(const T&) { return false; } Chris@16: Chris@16: static inline bool sorted(const T&) { return false; } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_manhattan_polygonal_concept { typedef gtl_no type; }; Chris@16: template <> Chris@16: struct is_manhattan_polygonal_concept { typedef gtl_yes type; }; Chris@16: template <> Chris@16: struct is_manhattan_polygonal_concept { typedef gtl_yes type; }; Chris@16: template <> Chris@16: struct is_manhattan_polygonal_concept { typedef gtl_yes type; }; Chris@16: template <> Chris@16: struct is_manhattan_polygonal_concept { typedef gtl_yes type; }; Chris@16: Chris@16: template Chris@16: struct is_polygon_90_set_type { Chris@16: typedef typename is_manhattan_polygonal_concept::type>::type type; Chris@16: }; Chris@16: template Chris@16: struct is_polygon_90_set_type > { Chris@16: typedef typename gtl_or< Chris@16: typename is_manhattan_polygonal_concept >::type>::type, Chris@16: typename is_manhattan_polygonal_concept::value_type>::type>::type>::type type; Chris@16: }; Chris@16: template Chris@16: struct is_polygon_90_set_type > { Chris@16: typedef typename gtl_or< Chris@16: typename is_manhattan_polygonal_concept >::type>::type, Chris@16: typename is_manhattan_polygonal_concept::value_type>::type>::type>::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_mutable_polygon_90_set_type { Chris@16: typedef typename gtl_same_type::type>::type type; Chris@16: }; Chris@16: template Chris@16: struct is_mutable_polygon_90_set_type > { Chris@16: typedef typename gtl_or< Chris@16: typename gtl_same_type >::type>::type, Chris@16: typename is_manhattan_polygonal_concept::value_type>::type>::type>::type type; Chris@16: }; Chris@16: template Chris@16: struct is_mutable_polygon_90_set_type > { Chris@16: typedef typename gtl_or< Chris@16: typename gtl_same_type >::type>::type, Chris@16: typename is_manhattan_polygonal_concept::value_type>::type>::type>::type type; Chris@16: }; Chris@16: Chris@16: // //specialization for rectangle, polygon_90 and polygon_90_with_holes types Chris@16: // template Chris@16: // struct polygon_90_set_traits Chris@16: // typedef typename geometry_concept::type concept_type; Chris@16: // typedef typename get_coordinate_type::type coordinate_type; Chris@16: // typedef iterator_geometry_to_set iterator_type; Chris@16: // typedef T operator_arg_type; Chris@16: Chris@16: // static inline iterator_type begin(const T& polygon_set) { Chris@16: // return iterator_geometry_to_set(polygon_set, LOW, HORIZONTAL); Chris@16: // } Chris@16: Chris@16: // static inline iterator_type end(const T& polygon_set) { Chris@16: // return iterator_geometry_to_set(polygon_set, HIGH, HORIZONTAL); Chris@16: // } Chris@16: Chris@16: // static inline orientation_2d orient(const T& polygon_set) { return HORIZONTAL; } Chris@16: Chris@16: // static inline bool clean(const T& polygon_set) { return false; } Chris@16: Chris@16: // static inline bool sorted(const T& polygon_set) { return false; } Chris@16: Chris@16: // }; Chris@16: Chris@16: // //specialization for containers of recangle, polygon_90, polygon_90_with_holes Chris@16: // template Chris@16: // struct polygon_90_set_traits::value_type>::type> { Chris@16: // typedef typename std::iterator_traits::value_type geometry_type; Chris@16: // typedef typename geometry_concept::type concept_type; Chris@16: // typedef typename get_coordinate_type::type coordinate_type; Chris@16: // typedef iterator_geometry_range_to_set iterator_type; Chris@16: // typedef T operator_arg_type; Chris@16: Chris@16: // static inline iterator_type begin(const T& polygon_set) { Chris@16: // return iterator_type(polygon_set.begin(), HORIZONTAL); Chris@16: // } Chris@16: Chris@16: // static inline iterator_type end(const T& polygon_set) { Chris@16: // return iterator_type(polygon_set.end(), HORIZONTAL); Chris@16: // } Chris@16: Chris@16: // static inline orientation_2d orient(const T& polygon_set) { return HORIZONTAL; } Chris@16: Chris@16: // static inline bool clean(const T& polygon_set) { return false; } Chris@16: Chris@16: // static inline bool sorted(const T& polygon_set) { return false; } Chris@16: Chris@16: // }; Chris@16: Chris@16: //get dispatch functions Chris@16: template Chris@16: void get_90_dispatch(output_container_type& output, const pst& ps, Chris@16: orientation_2d orient, rectangle_concept ) { Chris@16: form_rectangles(output, ps.begin(), ps.end(), orient, rectangle_concept()); Chris@16: } Chris@16: Chris@16: template Chris@16: void get_90_dispatch(output_container_type& output, const pst& ps, Chris@16: orientation_2d orient, polygon_90_concept tag) { Chris@16: get_polygons(output, ps.begin(), ps.end(), orient, true, tag); Chris@16: } Chris@16: Chris@16: template Chris@16: void get_90_dispatch(output_container_type& output, const pst& ps, Chris@16: orientation_2d orient, polygon_90_with_holes_concept tag) { Chris@16: get_polygons(output, ps.begin(), ps.end(), orient, false, tag); Chris@16: } Chris@16: Chris@16: //by default works with containers of rectangle, polygon or polygon with holes Chris@16: //must be specialized to work with anything else Chris@16: template Chris@16: struct polygon_90_set_mutable_traits {}; Chris@16: template Chris@16: struct polygon_90_set_mutable_traits > { Chris@16: typedef typename geometry_concept::type concept_type; Chris@16: template Chris@16: static inline void set(std::list& polygon_set, input_iterator_type input_begin, input_iterator_type input_end, orientation_2d orient) { Chris@16: polygon_set.clear(); Chris@16: polygon_90_set_data >::coordinate_type> ps(orient); Chris@16: ps.reserve(std::distance(input_begin, input_end)); Chris@16: ps.insert(input_begin, input_end, orient); Chris@16: ps.clean(); Chris@16: get_90_dispatch(polygon_set, ps, orient, concept_type()); Chris@16: } Chris@16: }; Chris@16: template Chris@16: struct polygon_90_set_mutable_traits > { Chris@16: typedef typename geometry_concept::type concept_type; Chris@16: template Chris@16: static inline void set(std::vector& polygon_set, input_iterator_type input_begin, input_iterator_type input_end, orientation_2d orient) { Chris@16: polygon_set.clear(); Chris@16: size_t num_ele = std::distance(input_begin, input_end); Chris@16: polygon_set.reserve(num_ele); Chris@16: polygon_90_set_data >::coordinate_type> ps(orient); Chris@16: ps.reserve(num_ele); Chris@16: ps.insert(input_begin, input_end, orient); Chris@16: ps.clean(); Chris@16: get_90_dispatch(polygon_set, ps, orient, concept_type()); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct polygon_90_set_mutable_traits > { Chris@16: Chris@16: template Chris@16: static inline void set(polygon_90_set_data& polygon_set, Chris@16: input_iterator_type input_begin, input_iterator_type input_end, Chris@16: orientation_2d orient) { Chris@16: polygon_set.clear(); Chris@16: polygon_set.reserve(std::distance(input_begin, input_end)); Chris@16: polygon_set.insert(input_begin, input_end, orient); Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: template Chris@16: struct polygon_90_set_traits > { Chris@16: typedef typename polygon_90_set_data::coordinate_type coordinate_type; Chris@16: typedef typename polygon_90_set_data::iterator_type iterator_type; Chris@16: typedef typename polygon_90_set_data::operator_arg_type operator_arg_type; Chris@16: Chris@16: static inline iterator_type begin(const polygon_90_set_data& polygon_set) { Chris@16: return polygon_set.begin(); Chris@16: } Chris@16: Chris@16: static inline iterator_type end(const polygon_90_set_data& polygon_set) { Chris@16: return polygon_set.end(); Chris@16: } Chris@16: Chris@16: static inline orientation_2d orient(const polygon_90_set_data& polygon_set) { return polygon_set.orient(); } Chris@16: Chris@16: static inline bool clean(const polygon_90_set_data& polygon_set) { polygon_set.clean(); return true; } Chris@16: Chris@16: static inline bool sorted(const polygon_90_set_data& polygon_set) { polygon_set.sort(); return true; } Chris@16: Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_polygon_90_set_concept { }; Chris@16: template <> Chris@16: struct is_polygon_90_set_concept { typedef gtl_yes type; }; Chris@16: template <> Chris@16: struct is_polygon_90_set_concept { typedef gtl_yes type; }; Chris@16: template <> Chris@16: struct is_polygon_90_set_concept { typedef gtl_yes type; }; Chris@16: template <> Chris@16: struct is_polygon_90_set_concept { typedef gtl_yes type; }; Chris@16: Chris@16: template Chris@16: struct is_mutable_polygon_90_set_concept { typedef gtl_no type; }; Chris@16: template <> Chris@16: struct is_mutable_polygon_90_set_concept { typedef gtl_yes type; }; Chris@16: Chris@16: template Chris@16: struct geometry_concept > { typedef polygon_90_set_concept type; }; Chris@16: Chris@16: //template Chris@16: //typename enable_if::type, void>::type Chris@16: //print_is_polygon_90_set_concept(const T& t) { std::cout << "is polygon 90 set concept\n"; } Chris@16: //template Chris@16: //typename enable_if::type, void>::type Chris@16: //print_is_mutable_polygon_90_set_concept(const T& t) { std::cout << "is mutable polygon 90 set concept\n"; } Chris@16: } Chris@16: } Chris@16: #endif