Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:50

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
0007 // Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
0008 
0009 // This file was modified by Oracle on 2014-2021.
0010 // Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
0011 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0012 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0013 
0014 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0015 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0016 
0017 // Use, modification and distribution is subject to the Boost Software License,
0018 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0019 // http://www.boost.org/LICENSE_1_0.txt)
0020 
0021 #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP
0022 #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP
0023 
0024 
0025 #include <boost/geometry/algorithms/detail/select_geometry_type.hpp>
0026 #include <boost/geometry/core/point_type.hpp>
0027 #include <boost/geometry/core/reverse_dispatch.hpp>
0028 #include <boost/geometry/strategies/default_strategy.hpp>
0029 #include <boost/geometry/strategies/detail.hpp>
0030 #include <boost/geometry/strategies/distance.hpp>
0031 #include <boost/geometry/strategies/distance/services.hpp>
0032 #include <boost/geometry/util/select_most_precise.hpp>
0033 #include <boost/geometry/util/sequence.hpp>
0034 #include <boost/geometry/util/type_traits.hpp>
0035 
0036 
0037 namespace boost { namespace geometry
0038 {
0039 
0040 
0041 namespace resolve_strategy
0042 {
0043 
0044 
0045 // TODO: This utility could be entirely implemented as:
0046 //       decltype(geometry::distance(std::declval<Geometry1>(), std::declval<Geometry2>(), std::declval<Strategy>()))
0047 //       however then the algorithm would have to be compiled.
0048 
0049 template
0050 <
0051     typename Geometry1, typename Geometry2, typename Strategy,
0052     bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
0053 >
0054 struct distance_result_strategy2_type
0055 {
0056     typedef decltype(std::declval<Strategy>().distance(
0057         std::declval<Geometry1>(), std::declval<Geometry2>())) type;
0058 };
0059 
0060 template <typename Geometry1, typename Geometry2, typename Strategy>
0061 struct distance_result_strategy2_type<Geometry1, Geometry2, Strategy, false>
0062 {
0063     typedef Strategy type;
0064 };
0065 
0066 template
0067 <
0068     typename Geometry1, typename Geometry2, typename Strategy,
0069     bool Reverse = reverse_dispatch<Geometry1, Geometry2>::value
0070 >
0071 struct distance_result_strategy_type
0072     : distance_result_strategy2_type<Geometry1, Geometry2, Strategy>
0073 {};
0074 
0075 template <typename Geometry1, typename Geometry2, typename Strategy>
0076 struct distance_result_strategy_type<Geometry1, Geometry2, Strategy, true>
0077     : distance_result_strategy_type<Geometry2, Geometry1, Strategy, false>
0078 {};
0079 
0080 
0081 template <typename Geometry1, typename Geometry2, typename Strategy>
0082 struct distance_result
0083     : strategy::distance::services::return_type
0084         <
0085             typename distance_result_strategy_type<Geometry1, Geometry2, Strategy>::type,
0086             typename point_type<Geometry1>::type,
0087             typename point_type<Geometry2>::type
0088         >
0089 {};
0090 
0091 template <typename Geometry1, typename Geometry2>
0092 struct distance_result<Geometry1, Geometry2, default_strategy>
0093     : distance_result
0094         <
0095             Geometry1,
0096             Geometry2,
0097             typename strategies::distance::services::default_strategy
0098                 <
0099                     Geometry1, Geometry2
0100                 >::type
0101         >
0102 {};
0103 
0104 
0105 } // namespace resolve_strategy
0106 
0107 
0108 #ifndef DOXYGEN_NO_DETAIL
0109 namespace detail { namespace distance
0110 {
0111 
0112 template <typename Strategy = geometry::default_strategy>
0113 struct more_precise_distance_result
0114 {
0115     template <typename Curr, typename Next>
0116     struct predicate
0117         : std::is_same
0118             <
0119                 typename resolve_strategy::distance_result
0120                     <
0121                         typename util::sequence_element<0, Curr>::type,
0122                         typename util::sequence_element<1, Curr>::type,
0123                         Strategy
0124                     >::type,
0125                 typename geometry::select_most_precise
0126                     <
0127                         typename resolve_strategy::distance_result
0128                             <
0129                                 typename util::sequence_element<0, Curr>::type,
0130                                 typename util::sequence_element<1, Curr>::type,
0131                                 Strategy
0132                             >::type,
0133                         typename resolve_strategy::distance_result
0134                             <
0135                                 typename util::sequence_element<0, Next>::type,
0136                                 typename util::sequence_element<1, Next>::type,
0137                                 Strategy
0138                             >::type
0139                     >::type
0140             >
0141     {};
0142 };
0143 
0144 }} // namespace detail::distance
0145 #endif //DOXYGEN_NO_DETAIL
0146 
0147 
0148 namespace resolve_dynamic
0149 {
0150 
0151 template
0152 <
0153     typename Geometry1, typename Geometry2, typename Strategy,
0154     bool IsDynamicOrCollection = util::is_dynamic_geometry<Geometry1>::value
0155                               || util::is_dynamic_geometry<Geometry2>::value
0156                               || util::is_geometry_collection<Geometry1>::value
0157                               || util::is_geometry_collection<Geometry2>::value
0158 >
0159 struct distance_result
0160     : resolve_strategy::distance_result
0161         <
0162             Geometry1,
0163             Geometry2,
0164             Strategy
0165         >
0166 {};
0167 
0168 
0169 template <typename Geometry1, typename Geometry2, typename Strategy>
0170 struct distance_result<Geometry1, Geometry2, Strategy, true>
0171 {
0172     // Select the most precise distance strategy result type
0173     //   for all variant type combinations.
0174     // TODO: We should ignore the combinations that are not valid
0175     //   but is_implemented is not ready for prime time.
0176     using selected_types = typename detail::select_geometry_types
0177         <
0178             Geometry1, Geometry2,
0179             detail::distance::more_precise_distance_result<Strategy>::template predicate
0180         >::type;
0181 
0182     using type = typename resolve_strategy::distance_result
0183         <
0184             typename util::sequence_element<0, selected_types>::type,
0185             typename util::sequence_element<1, selected_types>::type,
0186             Strategy
0187         >::type;
0188 };
0189 
0190 
0191 } // namespace resolve_dynamic
0192 
0193 
0194 /*!
0195 \brief Meta-function defining return type of distance function
0196 \ingroup distance
0197 \note The strategy defines the return-type (so this situation is different
0198     from length, where distance is sqr/sqrt, but length always squared)
0199  */
0200 template
0201 <
0202     typename Geometry1,
0203     typename Geometry2 = Geometry1,
0204     typename Strategy = void
0205 >
0206 struct distance_result
0207     : resolve_dynamic::distance_result<Geometry1, Geometry2, Strategy>
0208 {};
0209 
0210 
0211 template <typename Geometry1, typename Geometry2>
0212 struct distance_result<Geometry1, Geometry2, void>
0213     : distance_result<Geometry1, Geometry2, default_strategy>
0214 {};
0215 
0216 
0217 }} // namespace boost::geometry
0218 
0219 
0220 #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP