convert_ring.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2018.
  4. // Modifications copyright (c) 2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CONVERT_RING_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CONVERT_RING_HPP
  11. #include <boost/mpl/assert.hpp>
  12. #include <boost/range/algorithm/reverse.hpp>
  13. #include <boost/geometry/algorithms/convert.hpp>
  14. #include <boost/geometry/algorithms/detail/ring_identifier.hpp>
  15. #include <boost/geometry/algorithms/num_points.hpp>
  16. #include <boost/geometry/core/tags.hpp>
  17. #include <boost/geometry/core/exterior_ring.hpp>
  18. #include <boost/geometry/core/interior_rings.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_DETAIL
  22. namespace detail { namespace overlay
  23. {
  24. template<typename Tag>
  25. struct convert_ring
  26. {
  27. BOOST_MPL_ASSERT_MSG
  28. (
  29. false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TAG
  30. , (types<Tag>)
  31. );
  32. };
  33. template<>
  34. struct convert_ring<ring_tag>
  35. {
  36. template<typename Destination, typename Source>
  37. static inline void apply(Destination& destination, Source const& source,
  38. bool append, bool reverse)
  39. {
  40. if (! append)
  41. {
  42. geometry::convert(source, destination);
  43. if (reverse)
  44. {
  45. boost::reverse(destination);
  46. }
  47. }
  48. }
  49. };
  50. template<>
  51. struct convert_ring<polygon_tag>
  52. {
  53. template<typename Destination, typename Source>
  54. static inline void apply(Destination& destination, Source const& source,
  55. bool append, bool reverse)
  56. {
  57. if (! append)
  58. {
  59. geometry::convert(source, exterior_ring(destination));
  60. if (reverse)
  61. {
  62. boost::reverse(exterior_ring(destination));
  63. }
  64. }
  65. else
  66. {
  67. // Avoid adding interior rings which are invalid
  68. // because of its number of points:
  69. std::size_t const min_num_points
  70. = core_detail::closure::minimum_ring_size
  71. <
  72. geometry::closure<Destination>::value
  73. >::value;
  74. if (geometry::num_points(source) >= min_num_points)
  75. {
  76. interior_rings(destination).resize(
  77. interior_rings(destination).size() + 1);
  78. geometry::convert(source, interior_rings(destination).back());
  79. if (reverse)
  80. {
  81. boost::reverse(interior_rings(destination).back());
  82. }
  83. }
  84. }
  85. }
  86. };
  87. }} // namespace detail::overlay
  88. #endif // DOXYGEN_NO_DETAIL
  89. }} // namespace boost::geometry
  90. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CONVERT_RING_HPP