1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
7 // Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
9 // This file was modified by Oracle on 2014, 2015.
10 // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
21 #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP
22 #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP
24 #include <boost/mpl/always.hpp>
25 #include <boost/mpl/bool.hpp>
26 #include <boost/mpl/vector.hpp>
28 #include <boost/variant/variant_fwd.hpp>
30 #include <boost/geometry/core/point_type.hpp>
32 #include <boost/geometry/strategies/default_strategy.hpp>
33 #include <boost/geometry/strategies/distance.hpp>
35 #include <boost/geometry/util/compress_variant.hpp>
36 #include <boost/geometry/util/transform_variant.hpp>
37 #include <boost/geometry/util/combine_if.hpp>
39 #include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
42 namespace boost { namespace geometry
46 namespace resolve_strategy
49 template <typename Geometry1, typename Geometry2, typename Strategy>
50 struct distance_result
51 : strategy::distance::services::return_type
54 typename point_type<Geometry1>::type,
55 typename point_type<Geometry2>::type
59 template <typename Geometry1, typename Geometry2>
60 struct distance_result<Geometry1, Geometry2, default_strategy>
65 typename detail::distance::default_strategy
72 } // namespace resolve_strategy
75 namespace resolve_variant
78 template <typename Geometry1, typename Geometry2, typename Strategy>
79 struct distance_result
80 : resolve_strategy::distance_result
92 BOOST_VARIANT_ENUM_PARAMS(typename T),
95 struct distance_result
97 Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
100 // A set of all variant type combinations that are compatible and
102 typedef typename util::combine_if<
103 typename boost::mpl::vector1<Geometry1>,
104 typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
105 // Here we want should remove most of the combinations that
106 // are not valid, mostly to limit the size of the resulting MPL set.
107 // But is_implementedn is not ready for prime time
109 // util::is_implemented2<boost::mpl::_1, boost::mpl::_2, dispatch::distance<boost::mpl::_1, boost::mpl::_2> >
110 boost::mpl::always<boost::mpl::true_>
111 >::type possible_input_types;
113 // The (possibly variant) result type resulting from these combinations
114 typedef typename compress_variant<
115 typename transform_variant<
116 possible_input_types,
117 resolve_strategy::distance_result<
118 boost::mpl::first<boost::mpl::_>,
119 boost::mpl::second<boost::mpl::_>,
122 boost::mpl::back_inserter<boost::mpl::vector0<> >
128 // Distance arguments are commutative
131 BOOST_VARIANT_ENUM_PARAMS(typename T),
135 struct distance_result
137 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
140 > : public distance_result
142 Geometry2, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
147 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Strategy>
148 struct distance_result
150 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
151 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
155 // A set of all variant type combinations that are compatible and
157 typedef typename util::combine_if
159 typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
160 typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
161 // Here we want to try to remove most of the combinations
162 // that are not valid, mostly to limit the size of the
163 // resulting MPL vector.
164 // But is_implemented is not ready for prime time
166 // util::is_implemented2<boost::mpl::_1, boost::mpl::_2, dispatch::distance<boost::mpl::_1, boost::mpl::_2> >
167 boost::mpl::always<boost::mpl::true_>
168 >::type possible_input_types;
170 // The (possibly variant) result type resulting from these combinations
171 typedef typename compress_variant<
172 typename transform_variant<
173 possible_input_types,
174 resolve_strategy::distance_result<
175 boost::mpl::first<boost::mpl::_>,
176 boost::mpl::second<boost::mpl::_>,
179 boost::mpl::back_inserter<boost::mpl::vector0<> >
184 } // namespace resolve_variant
188 \brief Meta-function defining return type of distance function
190 \note The strategy defines the return-type (so this situation is different
191 from length, where distance is sqr/sqrt, but length always squared)
196 typename Geometry2 = Geometry1,
197 typename Strategy = void
199 struct distance_result
200 : resolve_variant::distance_result<Geometry1, Geometry2, Strategy>
204 template <typename Geometry1, typename Geometry2>
205 struct distance_result<Geometry1, Geometry2, void>
206 : distance_result<Geometry1, Geometry2, default_strategy>
210 }} // namespace boost::geometry
213 #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_RESULT_HPP