File indexing completed on 2025-01-18 09:35:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_LINEAR_TO_LINEAR_HPP
0011 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_LINEAR_TO_LINEAR_HPP
0012
0013 #include <boost/geometry/algorithms/detail/closest_points/range_to_geometry_rtree.hpp>
0014 #include <boost/geometry/algorithms/detail/closest_points/utilities.hpp>
0015
0016 #include <boost/geometry/algorithms/num_points.hpp>
0017 #include <boost/geometry/algorithms/num_segments.hpp>
0018
0019 #include <boost/geometry/core/point_type.hpp>
0020
0021 #include <boost/geometry/iterators/point_iterator.hpp>
0022 #include <boost/geometry/iterators/segment_iterator.hpp>
0023
0024
0025 namespace boost { namespace geometry
0026 {
0027
0028 #ifndef DOXYGEN_NO_DETAIL
0029 namespace detail { namespace closest_points
0030 {
0031
0032
0033 struct linear_to_linear
0034 {
0035 template <typename Linear1, typename Linear2, typename Segment, typename Strategies>
0036 static inline void apply(Linear1 const& linear1,
0037 Linear2 const& linear2,
0038 Segment& shortest_seg,
0039 Strategies const& strategies,
0040 bool = false)
0041 {
0042 if (geometry::num_points(linear1) == 1)
0043 {
0044 dispatch::closest_points
0045 <
0046 typename point_type<Linear1>::type,
0047 Linear2
0048 >::apply(*points_begin(linear1), linear2, shortest_seg, strategies);
0049 return;
0050 }
0051
0052 if (geometry::num_points(linear2) == 1)
0053 {
0054 dispatch::closest_points
0055 <
0056 typename point_type<Linear2>::type,
0057 Linear1
0058 >::apply(*points_begin(linear2), linear1, shortest_seg, strategies);
0059 detail::closest_points::swap_segment_points::apply(shortest_seg);
0060 return;
0061 }
0062
0063 if (geometry::num_segments(linear1) < geometry::num_segments(linear2))
0064 {
0065 point_or_segment_range_to_geometry_rtree::apply(
0066 geometry::segments_begin(linear2),
0067 geometry::segments_end(linear2),
0068 linear1,
0069 shortest_seg,
0070 strategies);
0071 detail::closest_points::swap_segment_points::apply(shortest_seg);
0072 return;
0073 }
0074
0075 point_or_segment_range_to_geometry_rtree::apply(
0076 geometry::segments_begin(linear1),
0077 geometry::segments_end(linear1),
0078 linear2,
0079 shortest_seg,
0080 strategies);
0081 }
0082 };
0083
0084 struct segment_to_linear
0085 {
0086 template <typename Segment, typename Linear, typename OutSegment, typename Strategies>
0087 static inline void apply(Segment const& segment,
0088 Linear const& linear,
0089 OutSegment& shortest_seg,
0090 Strategies const& strategies,
0091 bool = false)
0092 {
0093 using linestring_type = geometry::model::linestring
0094 <typename point_type<Segment>::type>;
0095 linestring_type linestring;
0096 convert(segment, linestring);
0097 linear_to_linear::apply(linestring, linear, shortest_seg, strategies);
0098 }
0099 };
0100
0101 struct linear_to_segment
0102 {
0103 template <typename Linear, typename Segment, typename OutSegment, typename Strategies>
0104 static inline void apply(Linear const& linear,
0105 Segment const& segment,
0106 OutSegment& shortest_seg,
0107 Strategies const& strategies,
0108 bool = false)
0109 {
0110 segment_to_linear::apply(segment, linear, shortest_seg, strategies);
0111 detail::closest_points::swap_segment_points::apply(shortest_seg);
0112 }
0113 };
0114
0115 }}
0116 #endif
0117
0118
0119 #ifndef DOXYGEN_NO_DISPATCH
0120 namespace dispatch
0121 {
0122
0123 template <typename Linear1, typename Linear2>
0124 struct closest_points
0125 <
0126 Linear1, Linear2,
0127 linear_tag, linear_tag,
0128 false
0129 > : detail::closest_points::linear_to_linear
0130 {};
0131
0132 template <typename Segment, typename Linear>
0133 struct closest_points
0134 <
0135 Segment, Linear,
0136 segment_tag, linear_tag,
0137 false
0138 > : detail::closest_points::segment_to_linear
0139 {};
0140
0141 template <typename Linear, typename Segment>
0142 struct closest_points
0143 <
0144 Linear, Segment,
0145 linear_tag, segment_tag,
0146 false
0147 > : detail::closest_points::linear_to_segment
0148 {};
0149
0150 }
0151 #endif
0152
0153 }}
0154
0155 #endif