areal.hpp 3.2 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. ring_return_type_t<Polygon const> ext_ring = exterior_ring(polygon);
  44. if (geometry::is_empty(ext_ring))
  45. {
  46. // use dummy multi polygon to get the strategy because there is no multi ring concept
  47. using strategy_t = decltype(strategy.envelope(detail::dummy_multi_polygon(),
  48. detail::dummy_box()));
  49. // if the exterior ring is empty, consider the interior rings
  50. envelope_multi_range
  51. <
  52. envelope_hole
  53. >::template apply<strategy_t>(interior_rings(polygon), mbr, strategy);
  54. }
  55. else
  56. {
  57. // otherwise, consider only the exterior ring
  58. envelope_range::apply(ext_ring, mbr, strategy);
  59. }
  60. }
  61. };
  62. }} // namespace detail::envelope
  63. #endif // DOXYGEN_NO_DETAIL
  64. #ifndef DOXYGEN_NO_DISPATCH
  65. namespace dispatch
  66. {
  67. template <typename Ring>
  68. struct envelope<Ring, ring_tag>
  69. : detail::envelope::envelope_range
  70. {};
  71. template <typename Polygon>
  72. struct envelope<Polygon, polygon_tag>
  73. : detail::envelope::envelope_polygon
  74. {};
  75. template <typename MultiPolygon>
  76. struct envelope<MultiPolygon, multi_polygon_tag>
  77. : detail::envelope::envelope_multi_range
  78. <
  79. detail::envelope::envelope_polygon
  80. >
  81. {};
  82. } // namespace dispatch
  83. #endif // DOXYGEN_NO_DISPATCH
  84. }} // namespace boost::geometry
  85. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_AREAL_HPP