Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:02

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2021, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
0006 
0007 // Licensed under the Boost Software License version 1.0.
0008 // http://www.boost.org/users/license.html
0009 
0010 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_INTERFACE_HPP
0011 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_INTERFACE_HPP
0012 
0013 #include <boost/concept_check.hpp>
0014 
0015 #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
0016 #include <boost/geometry/algorithms/detail/closest_points/utilities.hpp>
0017 
0018 #include <boost/geometry/algorithms/dispatch/closest_points.hpp>
0019 
0020 #include <boost/geometry/algorithms/detail/distance/interface.hpp>
0021 
0022 #include <boost/geometry/core/point_type.hpp>
0023 
0024 #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
0025 #include <boost/geometry/geometries/concepts/check.hpp>
0026 
0027 #include <boost/geometry/strategies/default_strategy.hpp>
0028 #include <boost/geometry/strategies/detail.hpp>
0029 #include <boost/geometry/strategies/closest_points/services.hpp>
0030 
0031 
0032 namespace boost { namespace geometry
0033 {
0034 
0035 
0036 #ifndef DOXYGEN_NO_DISPATCH
0037 namespace dispatch
0038 {
0039 
0040 
0041 // If reversal is needed, perform it
0042 
0043 template
0044 <
0045     typename Geometry1,
0046     typename Geometry2,
0047     typename Tag1,
0048     typename Tag2
0049 >
0050 struct closest_points
0051 <
0052     Geometry1, Geometry2,
0053     Tag1, Tag2, true
0054 >
0055     : closest_points<Geometry2, Geometry1, Tag2, Tag1, false>
0056 {
0057     template <typename Segment, typename Strategy>
0058     static inline void apply(Geometry1 const& g1, Geometry2 const& g2,
0059                              Segment& shortest_seg, Strategy const& strategy)
0060     {
0061         closest_points
0062             <
0063                 Geometry2, Geometry1, Tag2, Tag1, false
0064             >::apply(g2, g1, shortest_seg, strategy);
0065 
0066         detail::closest_points::swap_segment_points::apply(shortest_seg);
0067     }
0068 };
0069 
0070 
0071 } // namespace dispatch
0072 #endif // DOXYGEN_NO_DISPATCH
0073 
0074 
0075 namespace resolve_strategy
0076 {
0077 
0078 template<typename Strategy>
0079 struct closest_points
0080 {
0081     template <typename Geometry1, typename Geometry2, typename Segment>
0082     static inline void apply(Geometry1 const& geometry1,
0083                              Geometry2 const& geometry2,
0084                              Segment& shortest_seg,
0085                              Strategy const& strategy)
0086     {
0087         dispatch::closest_points
0088             <
0089                 Geometry1, Geometry2
0090             >::apply(geometry1, geometry2, shortest_seg, strategy);
0091     }
0092 };
0093 
0094 template <>
0095 struct closest_points<default_strategy>
0096 {
0097     template <typename Geometry1, typename Geometry2, typename Segment>
0098     static inline void
0099     apply(Geometry1 const& geometry1,
0100           Geometry2 const& geometry2,
0101           Segment& shortest_seg,
0102           default_strategy)
0103     {
0104         using strategy_type = typename strategies::closest_points::services::default_strategy
0105             <
0106                 Geometry1, Geometry2
0107             >::type;
0108 
0109         dispatch::closest_points
0110             <
0111                 Geometry1, Geometry2
0112             >::apply(geometry1, geometry2, shortest_seg, strategy_type());
0113     }
0114 };
0115 
0116 } // namespace resolve_strategy
0117 
0118 
0119 namespace resolve_variant
0120 {
0121 
0122 
0123 template <typename Geometry1, typename Geometry2>
0124 struct closest_points
0125 {
0126     template <typename Segment, typename Strategy>
0127     static inline void apply(Geometry1 const& geometry1,
0128                              Geometry2 const& geometry2,
0129                              Segment& shortest_seg,
0130                              Strategy const& strategy)
0131     {
0132         resolve_strategy::closest_points
0133             <
0134                 Strategy
0135             >::apply(geometry1, geometry2, shortest_seg, strategy);
0136     }
0137 };
0138 
0139 //TODO: Add support for DG/GC
0140 
0141 } // namespace resolve_variant
0142 
0143 
0144 /*!
0145 \brief Calculate the closest points between two geometries \brief_strategy
0146 \ingroup closest_points
0147 \details
0148 \details The free function closest_points calculates the distance between two geometries \brief_strategy. \details_strategy_reasons
0149 \tparam Geometry1 \tparam_geometry
0150 \tparam Geometry2 \tparam_geometry
0151 \tparam Segment Any type fulfilling a Segment Concept
0152 \tparam Strategy \tparam_strategy{Closest Points}
0153 \param geometry1 \param_geometry
0154 \param geometry2 \param_geometry
0155 \param shortest_seg Output segment containing the closest points
0156 \param strategy \param_strategy{closest_points}
0157 \note The strategy can be a point-point strategy. In case of distance point-line/point-polygon
0158     it may also be a point-segment strategy.
0159 
0160 \qbk{distinguish,with strategy}
0161 
0162 \qbk{
0163 
0164 [heading Example]
0165 [closest_points_strategy]
0166 [closest_points_strategy_output]
0167 
0168 [heading See also]
0169 \* [link geometry.reference.algorithms.distance distance]
0170 }
0171 */
0172 
0173 template <typename Geometry1, typename Geometry2, typename Segment, typename Strategy>
0174 inline void closest_points(Geometry1 const& geometry1,
0175                            Geometry2 const& geometry2,
0176                            Segment& shortest_seg,
0177                            Strategy const& strategy)
0178 {
0179     concepts::check<Geometry1 const>();
0180     concepts::check<Geometry2 const>();
0181 
0182     detail::throw_on_empty_input(geometry1);
0183     detail::throw_on_empty_input(geometry2);
0184 
0185     resolve_variant::closest_points
0186         <
0187             Geometry1,
0188             Geometry2
0189         >::apply(geometry1, geometry2, shortest_seg, strategy);
0190 }
0191 
0192 
0193 /*!
0194 \brief Compute the closest points between two geometries.
0195 \ingroup closest_points
0196 \details The free function closest_points calculates the closest points between two geometries. \details_default_strategy
0197 \tparam Geometry1 \tparam_geometry
0198 \tparam Geometry2 \tparam_geometry
0199 \tparam Segment Any type fulfilling a Segment Concept
0200 \param geometry1 \param_geometry
0201 \param geometry2 \param_geometry
0202 \param shortest_seg Output segment containing the closest points
0203 
0204 \qbk{
0205 
0206 [heading Example]
0207 [closest_points]
0208 [closest_points_output]
0209 
0210 [heading See also]
0211 \* [link geometry.reference.algorithms.distance distance]
0212 }
0213 */
0214 
0215 template <typename Geometry1, typename Geometry2, typename Segment>
0216 inline void closest_points(Geometry1 const& geometry1,
0217                            Geometry2 const& geometry2,
0218                            Segment& shortest_seg)
0219 {
0220     closest_points(geometry1, geometry2, shortest_seg, default_strategy());
0221 }
0222 
0223 }} // namespace boost::geometry
0224 
0225 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_INTERFACE_HPP