areal.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Boost.Geometry
  2. // Copyright (c) 2018-2021 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_AREAL_HPP
  9. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_AREAL_HPP
  10. #include <boost/geometry/core/cs.hpp>
  11. #include <boost/geometry/core/tags.hpp>
  12. #include <boost/geometry/iterators/segment_iterator.hpp>
  13. #include <boost/geometry/algorithms/detail/envelope/range.hpp>
  14. #include <boost/geometry/algorithms/detail/envelope/linear.hpp>
  15. #include <boost/geometry/algorithms/dispatch/envelope.hpp>
  16. #include <boost/geometry/views/reversible_view.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail { namespace envelope
  21. {
  22. struct envelope_hole
  23. {
  24. template <typename Range, typename Box, typename Strategies>
  25. static inline void apply(Range const& range, Box& mbr, Strategies const& strategies)
  26. {
  27. // Reverse holes to avoid calculating the envelope for the outside
  28. // in spherical and geographic coordinate systems
  29. detail::clockwise_view
  30. <
  31. Range const,
  32. geometry::point_order<Range>::value == counterclockwise
  33. ? clockwise : counterclockwise
  34. > view(range);
  35. strategies.envelope(range, mbr).apply(view, mbr);
  36. }
  37. };
  38. struct envelope_polygon
  39. {
  40. template <typename Polygon, typename Box, typename Strategy>
  41. static inline void apply(Polygon const& polygon, Box& mbr, Strategy const& strategy)
  42. {
  43. typename ring_return_type<Polygon const>::type ext_ring
  44. = exterior_ring(polygon);
  45. if (geometry::is_empty(ext_ring))
  46. {
  47. // use dummy multi polygon to get the strategy because there is no multi ring concept
  48. using strategy_t = decltype(strategy.envelope(detail::dummy_multi_polygon(),
  49. detail::dummy_box()));
  50. // if the exterior ring is empty, consider the interior rings
  51. envelope_multi_range
  52. <
  53. envelope_hole
  54. >::template apply<strategy_t>(interior_rings(polygon), mbr, strategy);
  55. }
  56. else
  57. {
  58. // otherwise, consider only the exterior ring
  59. envelope_range::apply(ext_ring, mbr, strategy);
  60. }
  61. }
  62. };
  63. }} // namespace detail::envelope
  64. #endif // DOXYGEN_NO_DETAIL
  65. #ifndef DOXYGEN_NO_DISPATCH
  66. namespace dispatch
  67. {
  68. template <typename Ring>
  69. struct envelope<Ring, ring_tag>
  70. : detail::envelope::envelope_range
  71. {};
  72. template <typename Polygon>
  73. struct envelope<Polygon, polygon_tag>
  74. : detail::envelope::envelope_polygon
  75. {};
  76. template <typename MultiPolygon>
  77. struct envelope<MultiPolygon, multi_polygon_tag>
  78. : detail::envelope::envelope_multi_range
  79. <
  80. detail::envelope::envelope_polygon
  81. >
  82. {};
  83. } // namespace dispatch
  84. #endif // DOXYGEN_NO_DISPATCH
  85. }} // namespace boost::geometry
  86. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_AREAL_HPP