interface.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2017-2022.
  6. // Modifications copyright (c) 2017-2022 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_INTERFACE_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_INTERFACE_HPP
  15. #include <boost/geometry/algorithms/clear.hpp>
  16. #include <boost/geometry/algorithms/not_implemented.hpp>
  17. #include <boost/geometry/core/visit.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/geometries/adapted/boost_variant.hpp>
  20. #include <boost/geometry/geometries/concepts/check.hpp>
  21. #include <boost/geometry/strategies/buffer/services.hpp>
  22. #include <boost/geometry/util/type_traits_std.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_DISPATCH
  26. namespace dispatch
  27. {
  28. template
  29. <
  30. typename Input,
  31. typename Output,
  32. typename TagIn = typename tag<Input>::type,
  33. typename TagOut = typename tag<Output>::type
  34. >
  35. struct buffer_dc : not_implemented<TagIn, TagOut>
  36. {};
  37. template
  38. <
  39. typename Input,
  40. typename Output,
  41. typename TagIn = typename tag<Input>::type,
  42. typename TagOut = typename tag<Output>::type
  43. >
  44. struct buffer_all : not_implemented<TagIn, TagOut>
  45. {};
  46. } // namespace dispatch
  47. #endif // DOXYGEN_NO_DISPATCH
  48. namespace resolve_dynamic
  49. {
  50. template
  51. <
  52. typename Input,
  53. typename TagIn = typename geometry::tag<Input>::type
  54. >
  55. struct buffer_dc
  56. {
  57. template <typename Output, typename Distance>
  58. static inline void apply(Input const& geometry_in,
  59. Output& geometry_out,
  60. Distance const& distance,
  61. Distance const& chord_length)
  62. {
  63. dispatch::buffer_dc<Input, Output>::apply(geometry_in, geometry_out, distance, chord_length);
  64. }
  65. };
  66. template <typename Input>
  67. struct buffer_dc<Input, dynamic_geometry_tag>
  68. {
  69. template <typename Output, typename Distance>
  70. static inline void apply(Input const& geometry_in,
  71. Output& geometry_out,
  72. Distance const& distance,
  73. Distance const& chord_length)
  74. {
  75. traits::visit<Input>::apply([&](auto const& g)
  76. {
  77. dispatch::buffer_dc
  78. <
  79. util::remove_cref_t<decltype(g)>, Output
  80. >::apply(g, geometry_out, distance, chord_length);
  81. }, geometry_in);
  82. }
  83. };
  84. template
  85. <
  86. typename Input,
  87. typename TagIn = typename geometry::tag<Input>::type
  88. >
  89. struct buffer_all
  90. {
  91. template
  92. <
  93. typename Output,
  94. typename DistanceStrategy,
  95. typename SideStrategy,
  96. typename JoinStrategy,
  97. typename EndStrategy,
  98. typename PointStrategy
  99. >
  100. static inline void apply(Input const& geometry_in,
  101. Output& geometry_out,
  102. DistanceStrategy const& distance_strategy,
  103. SideStrategy const& side_strategy,
  104. JoinStrategy const& join_strategy,
  105. EndStrategy const& end_strategy,
  106. PointStrategy const& point_strategy)
  107. {
  108. typename strategies::buffer::services::default_strategy
  109. <
  110. Input
  111. >::type strategies;
  112. dispatch::buffer_all
  113. <
  114. Input, Output
  115. >::apply(geometry_in, geometry_out, distance_strategy, side_strategy,
  116. join_strategy, end_strategy, point_strategy, strategies);
  117. }
  118. };
  119. template <typename Input>
  120. struct buffer_all<Input, dynamic_geometry_tag>
  121. {
  122. template
  123. <
  124. typename Output,
  125. typename DistanceStrategy,
  126. typename SideStrategy,
  127. typename JoinStrategy,
  128. typename EndStrategy,
  129. typename PointStrategy
  130. >
  131. static inline void apply(Input const& geometry_in,
  132. Output& geometry_out,
  133. DistanceStrategy const& distance_strategy,
  134. SideStrategy const& side_strategy,
  135. JoinStrategy const& join_strategy,
  136. EndStrategy const& end_strategy,
  137. PointStrategy const& point_strategy)
  138. {
  139. traits::visit<Input>::apply([&](auto const& g)
  140. {
  141. buffer_all
  142. <
  143. util::remove_cref_t<decltype(g)>
  144. >::apply(g, geometry_out, distance_strategy, side_strategy,
  145. join_strategy, end_strategy, point_strategy);
  146. }, geometry_in);
  147. }
  148. };
  149. } // namespace resolve_dynamic
  150. /*!
  151. \brief \brief_calc{buffer}
  152. \ingroup buffer
  153. \details \details_calc{buffer, \det_buffer}.
  154. \tparam Input \tparam_geometry
  155. \tparam Output \tparam_geometry
  156. \tparam Distance \tparam_numeric
  157. \param geometry_in \param_geometry
  158. \param geometry_out \param_geometry
  159. \param distance The distance to be used for the buffer
  160. \param chord_length (optional) The length of the chord's in the generated arcs around points or bends
  161. \qbk{[include reference/algorithms/buffer.qbk]}
  162. */
  163. template <typename Input, typename Output, typename Distance>
  164. inline void buffer(Input const& geometry_in, Output& geometry_out,
  165. Distance const& distance, Distance const& chord_length = -1)
  166. {
  167. concepts::check<Input const>();
  168. concepts::check<Output>();
  169. resolve_dynamic::buffer_dc<Input>::apply(geometry_in, geometry_out, distance, chord_length);
  170. }
  171. /*!
  172. \brief \brief_calc{buffer}
  173. \ingroup buffer
  174. \details \details_calc{return_buffer, \det_buffer}. \details_return{buffer}.
  175. \tparam Input \tparam_geometry
  176. \tparam Output \tparam_geometry
  177. \tparam Distance \tparam_numeric
  178. \param geometry \param_geometry
  179. \param distance The distance to be used for the buffer
  180. \param chord_length (optional) The length of the chord's in the generated arcs
  181. around points or bends (RESERVED, NOT YET USED)
  182. \return \return_calc{buffer}
  183. */
  184. template <typename Output, typename Input, typename Distance>
  185. inline Output return_buffer(Input const& geometry, Distance const& distance,
  186. Distance const& chord_length = -1)
  187. {
  188. concepts::check<Input const>();
  189. concepts::check<Output>();
  190. Output geometry_out;
  191. resolve_dynamic::buffer_dc<Input>::apply(geometry, geometry_out, distance, chord_length);
  192. return geometry_out;
  193. }
  194. /*!
  195. \brief \brief_calc{buffer}
  196. \ingroup buffer
  197. \details \details_calc{buffer, \det_buffer}.
  198. \tparam GeometryIn \tparam_geometry
  199. \tparam GeometryOut \tparam_geometry{GeometryOut}
  200. \tparam DistanceStrategy A strategy defining distance (or radius)
  201. \tparam SideStrategy A strategy defining creation along sides
  202. \tparam JoinStrategy A strategy defining creation around convex corners
  203. \tparam EndStrategy A strategy defining creation at linestring ends
  204. \tparam PointStrategy A strategy defining creation around points
  205. \param geometry_in \param_geometry
  206. \param geometry_out output geometry, e.g. multi polygon,
  207. will contain a buffered version of the input geometry
  208. \param distance_strategy The distance strategy to be used
  209. \param side_strategy The side strategy to be used
  210. \param join_strategy The join strategy to be used
  211. \param end_strategy The end strategy to be used
  212. \param point_strategy The point strategy to be used
  213. \qbk{distinguish,with strategies}
  214. \qbk{[include reference/algorithms/buffer_with_strategies.qbk]}
  215. */
  216. template
  217. <
  218. typename GeometryIn,
  219. typename GeometryOut,
  220. typename DistanceStrategy,
  221. typename SideStrategy,
  222. typename JoinStrategy,
  223. typename EndStrategy,
  224. typename PointStrategy
  225. >
  226. inline void buffer(GeometryIn const& geometry_in,
  227. GeometryOut& geometry_out,
  228. DistanceStrategy const& distance_strategy,
  229. SideStrategy const& side_strategy,
  230. JoinStrategy const& join_strategy,
  231. EndStrategy const& end_strategy,
  232. PointStrategy const& point_strategy)
  233. {
  234. concepts::check<GeometryIn const>();
  235. concepts::check<GeometryOut>();
  236. geometry::clear(geometry_out);
  237. resolve_dynamic::buffer_all
  238. <
  239. GeometryIn, GeometryOut
  240. >::apply(geometry_in, geometry_out, distance_strategy, side_strategy,
  241. join_strategy, end_strategy, point_strategy);
  242. }
  243. }} // namespace boost::geometry
  244. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_INTERFACE_HPP