polygon_45_set_traits.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP
  8. #define BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP
  9. namespace boost { namespace polygon{
  10. //default definition of polygon 45 set traits works for any model of polygon 45, polygon 45 with holes or any vector or list thereof
  11. template <typename T>
  12. struct polygon_45_set_traits {
  13. typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
  14. typedef typename get_iterator_type<T>::type iterator_type;
  15. typedef T operator_arg_type;
  16. static inline iterator_type begin(const T& polygon_set) {
  17. return get_iterator_type<T>::begin(polygon_set);
  18. }
  19. static inline iterator_type end(const T& polygon_set) {
  20. return get_iterator_type<T>::end(polygon_set);
  21. }
  22. static inline bool clean(const T& ) { return false; }
  23. static inline bool sorted(const T& ) { return false; }
  24. };
  25. template <typename T>
  26. struct is_45_polygonal_concept { typedef gtl_no type; };
  27. template <>
  28. struct is_45_polygonal_concept<polygon_45_concept> { typedef gtl_yes type; };
  29. template <>
  30. struct is_45_polygonal_concept<polygon_45_with_holes_concept> { typedef gtl_yes type; };
  31. template <>
  32. struct is_45_polygonal_concept<polygon_45_set_concept> { typedef gtl_yes type; };
  33. template <typename T>
  34. struct is_polygon_45_set_type {
  35. typedef typename is_45_polygonal_concept<typename geometry_concept<T>::type>::type type;
  36. };
  37. template <typename T>
  38. struct is_polygon_45_set_type<std::list<T> > {
  39. typedef typename gtl_or<
  40. typename is_45_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type,
  41. typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
  42. };
  43. template <typename T>
  44. struct is_polygon_45_set_type<std::vector<T> > {
  45. typedef typename gtl_or<
  46. typename is_45_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type,
  47. typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
  48. };
  49. template <typename T>
  50. struct is_mutable_polygon_45_set_type {
  51. typedef typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<T>::type>::type type;
  52. };
  53. template <typename T>
  54. struct is_mutable_polygon_45_set_type<std::list<T> > {
  55. typedef typename gtl_or<
  56. typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::list<T> >::type>::type,
  57. typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
  58. };
  59. template <typename T>
  60. struct is_mutable_polygon_45_set_type<std::vector<T> > {
  61. typedef typename gtl_or<
  62. typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::vector<T> >::type>::type,
  63. typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
  64. };
  65. template <typename T>
  66. bool fracture_holes_45_by_concept() { return false; }
  67. template <>
  68. inline bool fracture_holes_45_by_concept<polygon_45_concept>() { return true; }
  69. template <typename T, typename iT>
  70. void get_45_polygons_T(T& t, iT begin, iT end) {
  71. typedef typename polygon_45_set_traits<T>::coordinate_type Unit;
  72. typedef typename geometry_concept<typename T::value_type>::type CType;
  73. typename polygon_45_formation<Unit>::Polygon45Formation pf(fracture_holes_45_by_concept<CType>());
  74. //std::cout << "FORMING POLYGONS\n";
  75. pf.scan(t, begin, end);
  76. }
  77. template <typename T>
  78. struct polygon_45_set_mutable_traits {};
  79. template <typename T>
  80. struct polygon_45_set_mutable_traits<std::list<T> > {
  81. template <typename input_iterator_type>
  82. static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
  83. polygon_set.clear();
  84. polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps;
  85. ps.reserve(std::distance(input_begin, input_end));
  86. ps.insert(input_begin, input_end);
  87. ps.sort();
  88. ps.clean();
  89. get_45_polygons_T(polygon_set, ps.begin(), ps.end());
  90. }
  91. };
  92. template <typename T>
  93. struct polygon_45_set_mutable_traits<std::vector<T> > {
  94. template <typename input_iterator_type>
  95. static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
  96. polygon_set.clear();
  97. size_t num_ele = std::distance(input_begin, input_end);
  98. polygon_set.reserve(num_ele);
  99. polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps;
  100. ps.reserve(num_ele);
  101. ps.insert(input_begin, input_end);
  102. ps.sort();
  103. ps.clean();
  104. get_45_polygons_T(polygon_set, ps.begin(), ps.end());
  105. }
  106. };
  107. template <typename T>
  108. struct polygon_45_set_mutable_traits<polygon_45_set_data<T> > {
  109. template <typename input_iterator_type>
  110. static inline void set(polygon_45_set_data<T>& polygon_set,
  111. input_iterator_type input_begin, input_iterator_type input_end) {
  112. polygon_set.set(input_begin, input_end);
  113. }
  114. };
  115. template <typename T>
  116. struct polygon_45_set_traits<polygon_45_set_data<T> > {
  117. typedef typename polygon_45_set_data<T>::coordinate_type coordinate_type;
  118. typedef typename polygon_45_set_data<T>::iterator_type iterator_type;
  119. typedef typename polygon_45_set_data<T>::operator_arg_type operator_arg_type;
  120. static inline iterator_type begin(const polygon_45_set_data<T>& polygon_set) {
  121. return polygon_set.begin();
  122. }
  123. static inline iterator_type end(const polygon_45_set_data<T>& polygon_set) {
  124. return polygon_set.end();
  125. }
  126. static inline bool clean(const polygon_45_set_data<T>& polygon_set) { polygon_set.clean(); return true; }
  127. static inline bool sorted(const polygon_45_set_data<T>& polygon_set) { polygon_set.sort(); return true; }
  128. };
  129. }
  130. }
  131. #endif