interface.hpp 6.5 KB

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