ring.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is 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. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP
  7. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP
  8. // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
  9. // boost::polygon::polygon_data -> boost::geometry::ring
  10. #include <cstddef>
  11. #include <boost/polygon/polygon.hpp>
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/cs.hpp>
  14. #include <boost/geometry/core/coordinate_dimension.hpp>
  15. #include <boost/geometry/core/coordinate_type.hpp>
  16. #include <boost/geometry/core/mutable_range.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  19. namespace boost { namespace geometry
  20. {
  21. namespace traits
  22. {
  23. template <typename CoordinateType>
  24. struct tag<boost::polygon::polygon_data<CoordinateType> >
  25. {
  26. typedef ring_tag type;
  27. };
  28. template <typename CoordinateType>
  29. struct clear<boost::polygon::polygon_data<CoordinateType> >
  30. {
  31. static inline void apply(boost::polygon::polygon_data<CoordinateType>& data)
  32. {
  33. // There is no "clear" function but we can assign
  34. // a newly (and therefore empty) constructed polygon
  35. boost::polygon::assign(data, boost::polygon::polygon_data<CoordinateType>());
  36. }
  37. };
  38. template <typename CoordinateType>
  39. struct push_back<boost::polygon::polygon_data<CoordinateType> >
  40. {
  41. typedef boost::polygon::point_data<CoordinateType> point_type;
  42. static inline void apply(boost::polygon::polygon_data<CoordinateType>& data,
  43. point_type const& point)
  44. {
  45. // Boost.Polygon's polygons are not appendable. So create a temporary vector,
  46. // add a record and set it to the original. Of course: this is not efficient.
  47. // But there seems no other way (without using a wrapper)
  48. std::vector<point_type> temporary_vector
  49. (
  50. boost::polygon::begin_points(data),
  51. boost::polygon::end_points(data)
  52. );
  53. temporary_vector.push_back(point);
  54. data.set(temporary_vector.begin(), temporary_vector.end());
  55. }
  56. };
  57. } // namespace traits
  58. }} // namespace boost::geometry
  59. // Adapt Boost.Polygon's polygon_data to Boost.Range
  60. // This just translates to
  61. // polygon_data.begin() and polygon_data.end()
  62. namespace boost
  63. {
  64. template<typename CoordinateType>
  65. struct range_mutable_iterator<boost::polygon::polygon_data<CoordinateType> >
  66. {
  67. typedef typename boost::polygon::polygon_traits
  68. <
  69. boost::polygon::polygon_data<CoordinateType>
  70. >::iterator_type type;
  71. };
  72. template<typename CoordinateType>
  73. struct range_const_iterator<boost::polygon::polygon_data<CoordinateType> >
  74. {
  75. typedef typename boost::polygon::polygon_traits
  76. <
  77. boost::polygon::polygon_data<CoordinateType>
  78. >::iterator_type type;
  79. };
  80. template<typename CoordinateType>
  81. struct range_size<boost::polygon::polygon_data<CoordinateType> >
  82. {
  83. typedef std::size_t type;
  84. };
  85. } // namespace boost
  86. // Support Boost.Polygon's polygon_data for Boost.Range ADP
  87. namespace boost { namespace polygon
  88. {
  89. template<typename CoordinateType>
  90. inline typename polygon_traits
  91. <
  92. polygon_data<CoordinateType>
  93. >::iterator_type range_begin(polygon_data<CoordinateType>& polygon)
  94. {
  95. return polygon.begin();
  96. }
  97. template<typename CoordinateType>
  98. inline typename polygon_traits
  99. <
  100. polygon_data<CoordinateType>
  101. >::iterator_type range_begin(polygon_data<CoordinateType> const& polygon)
  102. {
  103. return polygon.begin();
  104. }
  105. template<typename CoordinateType>
  106. inline typename polygon_traits
  107. <
  108. polygon_data<CoordinateType>
  109. >::iterator_type range_end(polygon_data<CoordinateType>& polygon)
  110. {
  111. return polygon.end();
  112. }
  113. template<typename CoordinateType>
  114. inline typename polygon_traits
  115. <
  116. polygon_data<CoordinateType>
  117. >::iterator_type range_end(polygon_data<CoordinateType> const& polygon)
  118. {
  119. return polygon.end();
  120. }
  121. template<typename CoordinateType>
  122. inline std::size_t range_calculate_size(polygon_data<CoordinateType> const& polygon)
  123. {
  124. return polygon.size();
  125. }
  126. }}
  127. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  128. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP