diff --git a/include/boost/geometry/algorithms/detail/closest_points/geometry_to_segment_or_box.hpp b/include/boost/geometry/algorithms/detail/closest_points/geometry_to_segment_or_box.hpp index e29dfa532..5c097e3b2 100644 --- a/include/boost/geometry/algorithms/detail/closest_points/geometry_to_segment_or_box.hpp +++ b/include/boost/geometry/algorithms/detail/closest_points/geometry_to_segment_or_box.hpp @@ -349,7 +349,7 @@ public: #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { - +/* template struct closest_points < @@ -358,7 +358,7 @@ struct closest_points false > : detail::closest_points::geometry_to_segment_or_box {}; - +*/ /* template struct distance diff --git a/include/boost/geometry/algorithms/detail/closest_points/linear_or_areal_to_areal.hpp b/include/boost/geometry/algorithms/detail/closest_points/linear_or_areal_to_areal.hpp index 80c3b714a..2e7404485 100644 --- a/include/boost/geometry/algorithms/detail/closest_points/linear_or_areal_to_areal.hpp +++ b/include/boost/geometry/algorithms/detail/closest_points/linear_or_areal_to_areal.hpp @@ -98,8 +98,8 @@ struct linear_to_areal return; } - // if there are no intersection points then the linear geometry (or part of it) - // is inside the areal; return any point of this part + // if there are no intersection points then check if the linear geometry + // (or part of it) is inside the areal and return any point of this part geometry::model::multi_linestring ln_out; geometry::intersection(linear, areal, ln_out, strategies); @@ -130,6 +130,37 @@ struct areal_to_linear }; +struct segment_to_areal +{ + template + static inline void apply(Segment const& segment, + Areal const& areal, + OutSegment& shortest_seg, + Strategies const& strategies, + bool = false) + { + using linestring_type = geometry::model::linestring::type>; + linestring_type linestring; + convert(segment, linestring); + return linear_to_areal::apply(linestring, areal, shortest_seg, strategies); + } +}; + +struct areal_to_segment +{ + template + static inline void apply(Areal const& areal, + Segment const& segment, + OutSegment& shortest_seg, + Strategies const& strategies, + bool = false) + { + segment_to_areal::apply(segment, areal, shortest_seg, strategies); + detail::closest_points::swap_segment_points::apply(shortest_seg); + return; + } +}; + struct areal_to_areal { template @@ -210,7 +241,7 @@ template struct closest_points < Linear, Areal, - linear_tag, areal_tag, + linear_tag, areal_tag, false > : detail::closest_points::linear_to_areal @@ -226,6 +257,26 @@ struct closest_points : detail::closest_points::areal_to_linear {}; +template +struct closest_points + < + Segment, Areal, + segment_tag, areal_tag, + false + > + : detail::closest_points::segment_to_areal +{}; + +template +struct closest_points + < + Areal, Segment, + areal_tag, segment_tag, + false + > + : detail::closest_points::areal_to_segment +{}; + template struct closest_points < diff --git a/include/boost/geometry/algorithms/detail/closest_points/linear_to_linear.hpp b/include/boost/geometry/algorithms/detail/closest_points/linear_to_linear.hpp index ab192c8d1..bbb021720 100644 --- a/include/boost/geometry/algorithms/detail/closest_points/linear_to_linear.hpp +++ b/include/boost/geometry/algorithms/detail/closest_points/linear_to_linear.hpp @@ -84,6 +84,70 @@ struct linear_to_linear } }; +struct segment_to_linear +{ + template + static inline void apply(Segment const& segment, + Linear const& linear, + OutSegment& shortest_seg, + Strategies const& strategies, + bool = false) + { + using linestring_type = geometry::model::linestring::type>; + linestring_type linestring; + convert(segment, linestring); + return linear_to_linear::apply(linestring, linear, shortest_seg, strategies); +/* + if (geometry::num_points(segment) == 1) + { + using segment_point_type = typename point_type::type; + segment_point_type point; + detail::assign_point_from_index<0>(segment, point); + dispatch::closest_points + < + segment_point_type, + Segment + >::apply(point, linear, shortest_seg, strategies); + return; + } + + if (geometry::num_points(linear) == 1) + { + dispatch::closest_points + < + typename point_type::type, + Segment + >::apply(*points_begin(linear), segment, shortest_seg, strategies); + detail::closest_points::swap_segment_points::apply(shortest_seg); + return; + } + + point_or_segment_range_to_geometry_rtree::apply( + geometry::segments_begin(linear), + geometry::segments_end(linear), + segment, + shortest_seg, + strategies); + detail::closest_points::swap_segment_points::apply(shortest_seg); + return; +*/ + } +}; + +struct linear_to_segment +{ + template + static inline void apply(Linear const& linear, + Segment const& segment, + OutSegment& shortest_seg, + Strategies const& strategies, + bool = false) + { + segment_to_linear::apply(segment, linear, shortest_seg, strategies); + detail::closest_points::swap_segment_points::apply(shortest_seg); + return; + } +}; }} // namespace detail::closest_points #endif // DOXYGEN_NO_DETAIL @@ -102,6 +166,24 @@ struct closest_points > : detail::closest_points::linear_to_linear {}; +template +struct closest_points + < + Segment, Linear, + segment_tag, linear_tag, + false + > : detail::closest_points::segment_to_linear +{}; + +template +struct closest_points + < + Linear, Segment, + linear_tag, segment_tag, + false + > : detail::closest_points::linear_to_segment +{}; + } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH diff --git a/test/algorithms/closest_points/l_ar.cpp b/test/algorithms/closest_points/l_ar.cpp index ab9d1c91b..11d20a15b 100644 --- a/test/algorithms/closest_points/l_ar.cpp +++ b/test/algorithms/closest_points/l_ar.cpp @@ -956,8 +956,8 @@ void test_closest_points_multi_linestring_box(Strategies const& strategies) template void test_all_l_ar(Strategies strategies) { - //test_closest_points_segment_polygon_or_ring(strategies); - //test_closest_points_segment_multi_polygon(strategies); + test_closest_points_segment_polygon_or_ring(strategies); + test_closest_points_segment_multi_polygon(strategies); //test_closest_points_segment_box(strategies); test_closest_points_linestring_polygon_or_ring(strategies);