backward_compatibility.hpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2014.
  7. // Modifications copyright (c) 2014, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_BACKWARD_COMPATIBILITY_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_BACKWARD_COMPATIBILITY_HPP
  16. #include <boost/geometry/core/closure.hpp>
  17. #include <boost/geometry/core/point_type.hpp>
  18. #include <boost/geometry/core/tags.hpp>
  19. #include <boost/geometry/strategies/distance.hpp>
  20. #include <boost/geometry/strategies/tags.hpp>
  21. #include <boost/geometry/algorithms/assign.hpp>
  22. #include <boost/geometry/algorithms/dispatch/distance.hpp>
  23. #include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
  24. #include <boost/geometry/algorithms/detail/distance/point_to_geometry.hpp>
  25. #include <boost/geometry/algorithms/detail/distance/multipoint_to_geometry.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail { namespace distance
  30. {
  31. template<typename Point, typename Segment, typename Strategy>
  32. struct point_to_segment
  33. {
  34. static inline typename strategy::distance::services::return_type
  35. <
  36. Strategy,
  37. Point,
  38. typename point_type<Segment>::type
  39. >::type
  40. apply(Point const& point, Segment const& segment, Strategy const& )
  41. {
  42. typename detail::distance::default_ps_strategy
  43. <
  44. Point,
  45. typename point_type<Segment>::type,
  46. Strategy
  47. >::type segment_strategy;
  48. typename point_type<Segment>::type p[2];
  49. geometry::detail::assign_point_from_index<0>(segment, p[0]);
  50. geometry::detail::assign_point_from_index<1>(segment, p[1]);
  51. return segment_strategy.apply(point, p[0], p[1]);
  52. }
  53. };
  54. }} // namespace detail::distance
  55. #endif // DOXYGEN_NO_DETAIL
  56. #ifndef DOXYGEN_NO_DISPATCH
  57. namespace dispatch
  58. {
  59. // Point-segment version 1, with point-point strategy
  60. template <typename Point, typename Segment, typename Strategy>
  61. struct distance
  62. <
  63. Point, Segment, Strategy,
  64. point_tag, segment_tag, strategy_tag_distance_point_point,
  65. false
  66. > : detail::distance::point_to_segment<Point, Segment, Strategy>
  67. {};
  68. // Point-line version 1, where point-point strategy is specified
  69. template <typename Point, typename Linestring, typename Strategy>
  70. struct distance
  71. <
  72. Point, Linestring, Strategy,
  73. point_tag, linestring_tag, strategy_tag_distance_point_point,
  74. false
  75. >
  76. {
  77. static inline typename strategy::distance::services::return_type
  78. <
  79. Strategy, Point, typename point_type<Linestring>::type
  80. >::type
  81. apply(Point const& point,
  82. Linestring const& linestring,
  83. Strategy const&)
  84. {
  85. typedef typename detail::distance::default_ps_strategy
  86. <
  87. Point,
  88. typename point_type<Linestring>::type,
  89. Strategy
  90. >::type ps_strategy_type;
  91. return detail::distance::point_to_range
  92. <
  93. Point, Linestring, closed, ps_strategy_type
  94. >::apply(point, linestring, ps_strategy_type());
  95. }
  96. };
  97. // Point-ring , where point-point strategy is specified
  98. template <typename Point, typename Ring, typename Strategy>
  99. struct distance
  100. <
  101. Point, Ring, Strategy,
  102. point_tag, ring_tag, strategy_tag_distance_point_point,
  103. false
  104. >
  105. {
  106. typedef typename strategy::distance::services::return_type
  107. <
  108. Strategy, Point, typename point_type<Ring>::type
  109. >::type return_type;
  110. static inline return_type apply(Point const& point,
  111. Ring const& ring,
  112. Strategy const&)
  113. {
  114. typedef typename detail::distance::default_ps_strategy
  115. <
  116. Point,
  117. typename point_type<Ring>::type,
  118. Strategy
  119. >::type ps_strategy_type;
  120. return detail::distance::point_to_ring
  121. <
  122. Point, Ring,
  123. geometry::closure<Ring>::value,
  124. ps_strategy_type
  125. >::apply(point, ring, ps_strategy_type());
  126. }
  127. };
  128. // Point-polygon , where point-point strategy is specified
  129. template <typename Point, typename Polygon, typename Strategy>
  130. struct distance
  131. <
  132. Point, Polygon, Strategy,
  133. point_tag, polygon_tag, strategy_tag_distance_point_point,
  134. false
  135. >
  136. {
  137. typedef typename strategy::distance::services::return_type
  138. <
  139. Strategy, Point, typename point_type<Polygon>::type
  140. >::type return_type;
  141. static inline return_type apply(Point const& point,
  142. Polygon const& polygon,
  143. Strategy const&)
  144. {
  145. typedef typename detail::distance::default_ps_strategy
  146. <
  147. Point,
  148. typename point_type<Polygon>::type,
  149. Strategy
  150. >::type ps_strategy_type;
  151. return detail::distance::point_to_polygon
  152. <
  153. Point,
  154. Polygon,
  155. geometry::closure<Polygon>::value,
  156. ps_strategy_type
  157. >::apply(point, polygon, ps_strategy_type());
  158. }
  159. };
  160. template
  161. <
  162. typename Point,
  163. typename MultiGeometry,
  164. typename MultiGeometryTag,
  165. typename Strategy
  166. >
  167. struct distance
  168. <
  169. Point, MultiGeometry, Strategy,
  170. point_tag, MultiGeometryTag,
  171. strategy_tag_distance_point_point, false
  172. >
  173. {
  174. typedef typename strategy::distance::services::return_type
  175. <
  176. Strategy, Point, typename point_type<MultiGeometry>::type
  177. >::type return_type;
  178. static inline return_type apply(Point const& point,
  179. MultiGeometry const& multigeometry,
  180. Strategy const&)
  181. {
  182. typedef typename detail::distance::default_ps_strategy
  183. <
  184. Point,
  185. typename point_type<MultiGeometry>::type,
  186. Strategy
  187. >::type ps_strategy_type;
  188. return distance
  189. <
  190. Point, MultiGeometry, ps_strategy_type,
  191. point_tag, MultiGeometryTag,
  192. strategy_tag_distance_point_segment, false
  193. >::apply(point, multigeometry, ps_strategy_type());
  194. }
  195. };
  196. template
  197. <
  198. typename Geometry,
  199. typename MultiPoint,
  200. typename GeometryTag,
  201. typename Strategy
  202. >
  203. struct distance
  204. <
  205. Geometry, MultiPoint, Strategy,
  206. GeometryTag, multi_point_tag,
  207. strategy_tag_distance_point_point, false
  208. >
  209. {
  210. typedef typename strategy::distance::services::return_type
  211. <
  212. Strategy,
  213. typename point_type<MultiPoint>::type,
  214. typename point_type<Geometry>::type
  215. >::type return_type;
  216. static inline return_type apply(Geometry const& geometry,
  217. MultiPoint const& multipoint,
  218. Strategy const&)
  219. {
  220. typedef typename detail::distance::default_ps_strategy
  221. <
  222. typename point_type<MultiPoint>::type,
  223. typename point_type<Geometry>::type,
  224. Strategy
  225. >::type ps_strategy_type;
  226. return distance
  227. <
  228. Geometry, MultiPoint, ps_strategy_type,
  229. GeometryTag, multi_point_tag,
  230. strategy_tag_distance_point_segment, false
  231. >::apply(geometry, multipoint, ps_strategy_type());
  232. }
  233. };
  234. template
  235. <
  236. typename MultiPoint,
  237. typename MultiGeometry,
  238. typename MultiGeometryTag,
  239. typename Strategy
  240. >
  241. struct distance
  242. <
  243. MultiPoint, MultiGeometry, Strategy,
  244. multi_point_tag, MultiGeometryTag,
  245. strategy_tag_distance_point_point, false
  246. >
  247. {
  248. typedef typename strategy::distance::services::return_type
  249. <
  250. Strategy,
  251. typename point_type<MultiPoint>::type,
  252. typename point_type<MultiGeometry>::type
  253. >::type return_type;
  254. static inline return_type apply(MultiPoint const& multipoint,
  255. MultiGeometry const& multigeometry,
  256. Strategy const&)
  257. {
  258. typedef typename detail::distance::default_ps_strategy
  259. <
  260. typename point_type<MultiPoint>::type,
  261. typename point_type<MultiGeometry>::type,
  262. Strategy
  263. >::type ps_strategy_type;
  264. return distance
  265. <
  266. MultiPoint, MultiGeometry, ps_strategy_type,
  267. multi_point_tag, MultiGeometryTag,
  268. strategy_tag_distance_point_segment, false
  269. >::apply(multipoint, multigeometry, ps_strategy_type());
  270. }
  271. };
  272. } // namespace dispatch
  273. #endif // DOXYGEN_NO_DISPATCH
  274. }} // namespace boost::geometry
  275. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_BACKWARD_COMPATIBILITY_HPP