convert_ring.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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-2020.
  4. // Modifications copyright (c) 2018-2020, 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/range/algorithm/reverse.hpp>
  12. #include <boost/geometry/algorithms/convert.hpp>
  13. #include <boost/geometry/algorithms/num_points.hpp>
  14. #include <boost/geometry/core/exterior_ring.hpp>
  15. #include <boost/geometry/core/interior_rings.hpp>
  16. #include <boost/geometry/core/static_assert.hpp>
  17. #include <boost/geometry/core/tags.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_GEOMETRY_STATIC_ASSERT_FALSE(
  27. "Not or not yet implemented for this geometry Tag.",
  28. Tag);
  29. };
  30. template<>
  31. struct convert_ring<ring_tag>
  32. {
  33. template<typename Destination, typename Source>
  34. static inline void apply(Destination& destination, Source const& source,
  35. bool append, bool reverse)
  36. {
  37. if (! append)
  38. {
  39. geometry::convert(source, destination);
  40. if (reverse)
  41. {
  42. boost::reverse(destination);
  43. }
  44. }
  45. }
  46. };
  47. template<>
  48. struct convert_ring<polygon_tag>
  49. {
  50. template<typename Destination, typename Source>
  51. static inline void apply(Destination& destination, Source const& source,
  52. bool append, bool reverse)
  53. {
  54. if (! append)
  55. {
  56. geometry::convert(source, exterior_ring(destination));
  57. if (reverse)
  58. {
  59. boost::reverse(exterior_ring(destination));
  60. }
  61. }
  62. else
  63. {
  64. // Avoid adding interior rings which are invalid
  65. // because of its number of points:
  66. std::size_t const min_num_points
  67. = core_detail::closure::minimum_ring_size
  68. <
  69. geometry::closure<Destination>::value
  70. >::value;
  71. if (geometry::num_points(source) >= min_num_points)
  72. {
  73. // TODO: resize and .size() and .back() should not be called here
  74. interior_rings(destination).resize(
  75. interior_rings(destination).size() + 1);
  76. geometry::convert(source, interior_rings(destination).back());
  77. if (reverse)
  78. {
  79. boost::reverse(interior_rings(destination).back());
  80. }
  81. }
  82. }
  83. }
  84. };
  85. }} // namespace detail::overlay
  86. #endif // DOXYGEN_NO_DETAIL
  87. }} // namespace boost::geometry
  88. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_CONVERT_RING_HPP