convert_ring.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/num_points.hpp>
  15. #include <boost/geometry/core/tags.hpp>
  16. #include <boost/geometry/core/exterior_ring.hpp>
  17. #include <boost/geometry/core/interior_rings.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace overlay
  22. {
  23. template<typename Tag>
  24. struct convert_ring
  25. {
  26. BOOST_MPL_ASSERT_MSG
  27. (
  28. false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TAG
  29. , (types<Tag>)
  30. );
  31. };
  32. template<>
  33. struct convert_ring<ring_tag>
  34. {
  35. template<typename Destination, typename Source>
  36. static inline void apply(Destination& destination, Source const& source,
  37. bool append, bool reverse)
  38. {
  39. if (! append)
  40. {
  41. geometry::convert(source, destination);
  42. if (reverse)
  43. {
  44. boost::reverse(destination);
  45. }
  46. }
  47. }
  48. };
  49. template<>
  50. struct convert_ring<polygon_tag>
  51. {
  52. template<typename Destination, typename Source>
  53. static inline void apply(Destination& destination, Source const& source,
  54. bool append, bool reverse)
  55. {
  56. if (! append)
  57. {
  58. geometry::convert(source, exterior_ring(destination));
  59. if (reverse)
  60. {
  61. boost::reverse(exterior_ring(destination));
  62. }
  63. }
  64. else
  65. {
  66. // Avoid adding interior rings which are invalid
  67. // because of its number of points:
  68. std::size_t const min_num_points
  69. = core_detail::closure::minimum_ring_size
  70. <
  71. geometry::closure<Destination>::value
  72. >::value;
  73. if (geometry::num_points(source) >= min_num_points)
  74. {
  75. interior_rings(destination).resize(
  76. interior_rings(destination).size() + 1);
  77. geometry::convert(source, interior_rings(destination).back());
  78. if (reverse)
  79. {
  80. boost::reverse(interior_rings(destination).back());
  81. }
  82. }
  83. }
  84. }
  85. };
  86. }} // namespace detail::overlay
  87. #endif // DOXYGEN_NO_DETAIL
  88. }} // namespace boost::geometry
  89. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CONVERT_RING_HPP