interface.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2015-2021.
  6. // Modifications copyright (c) 2015-2021, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Distributed under the Boost Software License, Version 1.0.
  13. // (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP
  17. #include <boost/geometry/algorithms/dispatch/envelope.hpp>
  18. #include <boost/geometry/core/coordinate_system.hpp>
  19. #include <boost/geometry/core/tag.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. #include <boost/geometry/core/visit.hpp>
  22. #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
  23. #include <boost/geometry/geometries/concepts/check.hpp>
  24. #include <boost/geometry/strategies/default_strategy.hpp>
  25. #include <boost/geometry/strategies/detail.hpp>
  26. #include <boost/geometry/strategies/envelope/services.hpp>
  27. #include <boost/geometry/util/select_most_precise.hpp>
  28. #include <boost/geometry/util/type_traits_std.hpp>
  29. namespace boost { namespace geometry
  30. {
  31. namespace resolve_strategy
  32. {
  33. template
  34. <
  35. typename Strategy,
  36. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  37. >
  38. struct envelope
  39. {
  40. template <typename Geometry, typename Box>
  41. static inline void apply(Geometry const& geometry,
  42. Box& box,
  43. Strategy const& strategy)
  44. {
  45. dispatch::envelope<Geometry>::apply(geometry, box, strategy);
  46. }
  47. };
  48. template <typename Strategy>
  49. struct envelope<Strategy, false>
  50. {
  51. template <typename Geometry, typename Box>
  52. static inline void apply(Geometry const& geometry,
  53. Box& box,
  54. Strategy const& strategy)
  55. {
  56. using strategies::envelope::services::strategy_converter;
  57. return dispatch::envelope
  58. <
  59. Geometry
  60. >::apply(geometry, box, strategy_converter<Strategy>::get(strategy));
  61. }
  62. };
  63. template <>
  64. struct envelope<default_strategy, false>
  65. {
  66. template <typename Geometry, typename Box>
  67. static inline void apply(Geometry const& geometry,
  68. Box& box,
  69. default_strategy)
  70. {
  71. typedef typename strategies::envelope::services::default_strategy
  72. <
  73. Geometry, Box
  74. >::type strategy_type;
  75. dispatch::envelope<Geometry>::apply(geometry, box, strategy_type());
  76. }
  77. };
  78. } // namespace resolve_strategy
  79. namespace resolve_dynamic
  80. {
  81. template <typename Geometry, typename Tag = typename tag<Geometry>::type>
  82. struct envelope
  83. {
  84. template <typename Box, typename Strategy>
  85. static inline void apply(Geometry const& geometry,
  86. Box& box,
  87. Strategy const& strategy)
  88. {
  89. concepts::check<Geometry const>();
  90. concepts::check<Box>();
  91. resolve_strategy::envelope<Strategy>::apply(geometry, box, strategy);
  92. }
  93. };
  94. template <typename Geometry>
  95. struct envelope<Geometry, dynamic_geometry_tag>
  96. {
  97. template <typename Box, typename Strategy>
  98. static inline void apply(Geometry const& geometry,
  99. Box& box,
  100. Strategy const& strategy)
  101. {
  102. traits::visit<Geometry>::apply([&](auto const& g)
  103. {
  104. envelope<util::remove_cref_t<decltype(g)>>::apply(g, box, strategy);
  105. }, geometry);
  106. }
  107. };
  108. } // namespace resolve_dynamic
  109. /*!
  110. \brief \brief_calc{envelope (with strategy)}
  111. \ingroup envelope
  112. \details \details_calc{envelope,\det_envelope}.
  113. \tparam Geometry \tparam_geometry
  114. \tparam Box \tparam_box
  115. \tparam Strategy \tparam_strategy{Envelope}
  116. \param geometry \param_geometry
  117. \param mbr \param_box \param_set{envelope}
  118. \param strategy \param_strategy{envelope}
  119. \qbk{distinguish,with strategy}
  120. \qbk{[include reference/algorithms/envelope.qbk]}
  121. \qbk{
  122. [heading Example]
  123. [envelope] [envelope_output]
  124. }
  125. */
  126. template<typename Geometry, typename Box, typename Strategy>
  127. inline void envelope(Geometry const& geometry, Box& mbr, Strategy const& strategy)
  128. {
  129. resolve_dynamic::envelope<Geometry>::apply(geometry, mbr, strategy);
  130. }
  131. /*!
  132. \brief \brief_calc{envelope}
  133. \ingroup envelope
  134. \details \details_calc{envelope,\det_envelope}.
  135. \tparam Geometry \tparam_geometry
  136. \tparam Box \tparam_box
  137. \param geometry \param_geometry
  138. \param mbr \param_box \param_set{envelope}
  139. \qbk{[include reference/algorithms/envelope.qbk]}
  140. \qbk{
  141. [heading Example]
  142. [envelope] [envelope_output]
  143. }
  144. */
  145. template<typename Geometry, typename Box>
  146. inline void envelope(Geometry const& geometry, Box& mbr)
  147. {
  148. resolve_dynamic::envelope<Geometry>::apply(geometry, mbr, default_strategy());
  149. }
  150. /*!
  151. \brief \brief_calc{envelope}
  152. \ingroup envelope
  153. \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
  154. \tparam Box \tparam_box
  155. \tparam Geometry \tparam_geometry
  156. \tparam Strategy \tparam_strategy{Envelope}
  157. \param geometry \param_geometry
  158. \param strategy \param_strategy{envelope}
  159. \return \return_calc{envelope}
  160. \qbk{distinguish,with strategy}
  161. \qbk{[include reference/algorithms/envelope.qbk]}
  162. \qbk{
  163. [heading Example]
  164. [return_envelope] [return_envelope_output]
  165. }
  166. */
  167. template<typename Box, typename Geometry, typename Strategy>
  168. inline Box return_envelope(Geometry const& geometry, Strategy const& strategy)
  169. {
  170. Box mbr;
  171. resolve_dynamic::envelope<Geometry>::apply(geometry, mbr, strategy);
  172. return mbr;
  173. }
  174. /*!
  175. \brief \brief_calc{envelope}
  176. \ingroup envelope
  177. \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
  178. \tparam Box \tparam_box
  179. \tparam Geometry \tparam_geometry
  180. \param geometry \param_geometry
  181. \return \return_calc{envelope}
  182. \qbk{[include reference/algorithms/envelope.qbk]}
  183. \qbk{
  184. [heading Example]
  185. [return_envelope] [return_envelope_output]
  186. }
  187. */
  188. template<typename Box, typename Geometry>
  189. inline Box return_envelope(Geometry const& geometry)
  190. {
  191. Box mbr;
  192. resolve_dynamic::envelope<Geometry>::apply(geometry, mbr, default_strategy());
  193. return mbr;
  194. }
  195. }} // namespace boost::geometry
  196. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP