interface.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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, 2016, 2017, 2018.
  6. // Modifications copyright (c) 2015-2018, 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/variant/apply_visitor.hpp>
  18. #include <boost/variant/static_visitor.hpp>
  19. #include <boost/variant/variant_fwd.hpp>
  20. #include <boost/geometry/algorithms/dispatch/envelope.hpp>
  21. #include <boost/geometry/core/coordinate_system.hpp>
  22. #include <boost/geometry/core/tag.hpp>
  23. #include <boost/geometry/core/tags.hpp>
  24. #include <boost/geometry/geometries/concepts/check.hpp>
  25. #include <boost/geometry/strategies/default_strategy.hpp>
  26. #include <boost/geometry/strategies/envelope.hpp>
  27. #include <boost/geometry/util/select_most_precise.hpp>
  28. namespace boost { namespace geometry
  29. {
  30. namespace resolve_strategy
  31. {
  32. template <typename Geometry>
  33. struct envelope
  34. {
  35. template <typename Box, typename Strategy>
  36. static inline void apply(Geometry const& geometry,
  37. Box& box,
  38. Strategy const& strategy)
  39. {
  40. dispatch::envelope<Geometry>::apply(geometry, box, strategy);
  41. }
  42. template <typename Box>
  43. static inline void apply(Geometry const& geometry,
  44. Box& box,
  45. default_strategy)
  46. {
  47. typedef typename strategy::envelope::services::default_strategy
  48. <
  49. typename tag<Geometry>::type,
  50. typename cs_tag<Geometry>::type,
  51. typename select_most_precise
  52. <
  53. typename coordinate_type<Geometry>::type,
  54. typename coordinate_type<Box>::type
  55. >::type
  56. >::type strategy_type;
  57. dispatch::envelope<Geometry>::apply(geometry, box, strategy_type());
  58. }
  59. };
  60. } // namespace resolve_strategy
  61. namespace resolve_variant
  62. {
  63. template <typename Geometry>
  64. struct envelope
  65. {
  66. template <typename Box, typename Strategy>
  67. static inline void apply(Geometry const& geometry,
  68. Box& box,
  69. Strategy const& strategy)
  70. {
  71. concepts::check<Geometry const>();
  72. concepts::check<Box>();
  73. resolve_strategy::envelope<Geometry>::apply(geometry, box, strategy);
  74. }
  75. };
  76. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  77. struct envelope<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  78. {
  79. template <typename Box, typename Strategy>
  80. struct visitor: boost::static_visitor<void>
  81. {
  82. Box& m_box;
  83. Strategy const& m_strategy;
  84. visitor(Box& box, Strategy const& strategy)
  85. : m_box(box)
  86. , m_strategy(strategy)
  87. {}
  88. template <typename Geometry>
  89. void operator()(Geometry const& geometry) const
  90. {
  91. envelope<Geometry>::apply(geometry, m_box, m_strategy);
  92. }
  93. };
  94. template <typename Box, typename Strategy>
  95. static inline void
  96. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
  97. Box& box,
  98. Strategy const& strategy)
  99. {
  100. boost::apply_visitor(visitor<Box, Strategy>(box, strategy), geometry);
  101. }
  102. };
  103. } // namespace resolve_variant
  104. /*!
  105. \brief \brief_calc{envelope (with strategy)}
  106. \ingroup envelope
  107. \details \details_calc{envelope,\det_envelope}.
  108. \tparam Geometry \tparam_geometry
  109. \tparam Box \tparam_box
  110. \tparam Strategy \tparam_strategy{Envelope}
  111. \param geometry \param_geometry
  112. \param mbr \param_box \param_set{envelope}
  113. \param strategy \param_strategy{envelope}
  114. \qbk{distinguish,with strategy}
  115. \qbk{[include reference/algorithms/envelope.qbk]}
  116. \qbk{
  117. [heading Example]
  118. [envelope] [envelope_output]
  119. }
  120. */
  121. template<typename Geometry, typename Box, typename Strategy>
  122. inline void envelope(Geometry const& geometry, Box& mbr, Strategy const& strategy)
  123. {
  124. resolve_variant::envelope<Geometry>::apply(geometry, mbr, strategy);
  125. }
  126. /*!
  127. \brief \brief_calc{envelope}
  128. \ingroup envelope
  129. \details \details_calc{envelope,\det_envelope}.
  130. \tparam Geometry \tparam_geometry
  131. \tparam Box \tparam_box
  132. \param geometry \param_geometry
  133. \param mbr \param_box \param_set{envelope}
  134. \qbk{[include reference/algorithms/envelope.qbk]}
  135. \qbk{
  136. [heading Example]
  137. [envelope] [envelope_output]
  138. }
  139. */
  140. template<typename Geometry, typename Box>
  141. inline void envelope(Geometry const& geometry, Box& mbr)
  142. {
  143. resolve_variant::envelope<Geometry>::apply(geometry, mbr, default_strategy());
  144. }
  145. /*!
  146. \brief \brief_calc{envelope}
  147. \ingroup envelope
  148. \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
  149. \tparam Box \tparam_box
  150. \tparam Geometry \tparam_geometry
  151. \tparam Strategy \tparam_strategy{Envelope}
  152. \param geometry \param_geometry
  153. \param strategy \param_strategy{envelope}
  154. \return \return_calc{envelope}
  155. \qbk{distinguish,with strategy}
  156. \qbk{[include reference/algorithms/envelope.qbk]}
  157. \qbk{
  158. [heading Example]
  159. [return_envelope] [return_envelope_output]
  160. }
  161. */
  162. template<typename Box, typename Geometry, typename Strategy>
  163. inline Box return_envelope(Geometry const& geometry, Strategy const& strategy)
  164. {
  165. Box mbr;
  166. resolve_variant::envelope<Geometry>::apply(geometry, mbr, strategy);
  167. return mbr;
  168. }
  169. /*!
  170. \brief \brief_calc{envelope}
  171. \ingroup envelope
  172. \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
  173. \tparam Box \tparam_box
  174. \tparam Geometry \tparam_geometry
  175. \param geometry \param_geometry
  176. \return \return_calc{envelope}
  177. \qbk{[include reference/algorithms/envelope.qbk]}
  178. \qbk{
  179. [heading Example]
  180. [return_envelope] [return_envelope_output]
  181. }
  182. */
  183. template<typename Box, typename Geometry>
  184. inline Box return_envelope(Geometry const& geometry)
  185. {
  186. Box mbr;
  187. resolve_variant::envelope<Geometry>::apply(geometry, mbr, default_strategy());
  188. return mbr;
  189. }
  190. }} // namespace boost::geometry
  191. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERFACE_HPP