// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2014 Samuel Debionne, Grenoble, France.
-// This file was modified by Oracle on 2014-2020.
-// Modifications copyright (c) 2014-2020, Oracle and/or its affiliates.
-
+// This file was modified by Oracle on 2014-2021.
+// Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
#include <boost/concept_check.hpp>
+#include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
+#include <boost/geometry/algorithms/dispatch/distance.hpp>
+
#include <boost/geometry/core/point_type.hpp>
+#include <boost/geometry/core/visit.hpp>
+#include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
#include <boost/geometry/geometries/concepts/check.hpp>
-#include <boost/geometry/strategies/default_strategy.hpp>
-#include <boost/geometry/strategies/distance.hpp>
+// TODO: move these to algorithms
#include <boost/geometry/strategies/default_distance_result.hpp>
#include <boost/geometry/strategies/distance_result.hpp>
-#include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
-#include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
-
-#include <boost/geometry/algorithms/dispatch/distance.hpp>
+#include <boost/geometry/strategies/default_strategy.hpp>
+#include <boost/geometry/strategies/detail.hpp>
+#include <boost/geometry/strategies/distance/services.hpp>
namespace boost { namespace geometry
>
: distance<Geometry2, Geometry1, Strategy, Tag2, Tag1, StrategyTag, false>
{
- typedef typename strategy::distance::services::return_type
- <
- Strategy,
- typename point_type<Geometry2>::type,
- typename point_type<Geometry1>::type
- >::type return_type;
-
- static inline return_type apply(
- Geometry1 const& g1,
- Geometry2 const& g2,
- Strategy const& strategy)
+ static inline auto apply(Geometry1 const& g1, Geometry2 const& g2,
+ Strategy const& strategy)
{
return distance
<
namespace resolve_strategy
{
-template <typename Strategy>
+template
+<
+ typename Strategy,
+ bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
+>
struct distance
{
template <typename Geometry1, typename Geometry2>
- static inline typename distance_result<Geometry1, Geometry2, Strategy>::type
- apply(Geometry1 const& geometry1,
- Geometry2 const& geometry2,
- Strategy const& strategy)
+ static inline auto apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
{
return dispatch::distance
<
}
};
+template <typename Strategy>
+struct is_strategy_converter_specialized
+{
+ typedef strategies::distance::services::strategy_converter<Strategy> converter;
+ static const bool value = ! std::is_same
+ <
+ decltype(converter::get(std::declval<Strategy>())),
+ strategies::detail::not_implemented
+ >::value;
+};
+
+template <typename Strategy>
+struct distance<Strategy, false>
+{
+ template
+ <
+ typename Geometry1, typename Geometry2, typename S,
+ std::enable_if_t<is_strategy_converter_specialized<S>::value, int> = 0
+ >
+ static inline auto apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ S const& strategy)
+ {
+ typedef strategies::distance::services::strategy_converter<Strategy> converter;
+ typedef decltype(converter::get(strategy)) strategy_type;
+
+ return dispatch::distance
+ <
+ Geometry1, Geometry2, strategy_type
+ >::apply(geometry1, geometry2, converter::get(strategy));
+ }
+
+ template
+ <
+ typename Geometry1, typename Geometry2, typename S,
+ std::enable_if_t<! is_strategy_converter_specialized<S>::value, int> = 0
+ >
+ static inline auto apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ S const& strategy)
+ {
+ typedef strategies::distance::services::custom_strategy_converter
+ <
+ Geometry1, Geometry2, Strategy
+ > converter;
+ typedef decltype(converter::get(strategy)) strategy_type;
+
+ return dispatch::distance
+ <
+ Geometry1, Geometry2, strategy_type
+ >::apply(geometry1, geometry2, converter::get(strategy));
+ }
+};
+
template <>
-struct distance<default_strategy>
+struct distance<default_strategy, false>
{
template <typename Geometry1, typename Geometry2>
- static inline
- typename distance_result<Geometry1, Geometry2, default_strategy>::type
- apply(Geometry1 const& geometry1,
- Geometry2 const& geometry2,
- default_strategy)
+ static inline auto apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ default_strategy)
{
- typedef typename detail::distance::default_strategy
+ typedef typename strategies::distance::services::default_strategy
<
Geometry1, Geometry2
>::type strategy_type;
} // namespace resolve_strategy
-namespace resolve_variant
+namespace resolve_dynamic
{
-template <typename Geometry1, typename Geometry2>
+template
+<
+ typename Geometry1, typename Geometry2,
+ typename Tag1 = typename geometry::tag<Geometry1>::type,
+ typename Tag2 = typename geometry::tag<Geometry2>::type
+>
struct distance
{
template <typename Strategy>
- static inline typename distance_result<Geometry1, Geometry2, Strategy>::type
- apply(Geometry1 const& geometry1,
- Geometry2 const& geometry2,
- Strategy const& strategy)
+ static inline auto apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
{
return resolve_strategy::distance
<
};
-template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
-struct distance<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
+template <typename DynamicGeometry1, typename Geometry2, typename Tag2>
+struct distance<DynamicGeometry1, Geometry2, dynamic_geometry_tag, Tag2>
{
template <typename Strategy>
- struct visitor: static_visitor
- <
- typename distance_result
- <
- variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
- Geometry2,
- Strategy
- >::type
- >
+ static inline auto apply(DynamicGeometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
{
- Geometry2 const& m_geometry2;
- Strategy const& m_strategy;
-
- visitor(Geometry2 const& geometry2,
- Strategy const& strategy)
- : m_geometry2(geometry2),
- m_strategy(strategy)
- {}
-
- template <typename Geometry1>
- typename distance_result<Geometry1, Geometry2, Strategy>::type
- operator()(Geometry1 const& geometry1) const
+ using result_t = typename geometry::distance_result<DynamicGeometry1, Geometry2, Strategy>::type;
+ result_t result = 0;
+ traits::visit<DynamicGeometry1>::apply([&](auto const& g1)
{
- return distance
- <
- Geometry1,
- Geometry2
- >::template apply
- <
- Strategy
- >(geometry1, m_geometry2, m_strategy);
- }
- };
-
- template <typename Strategy>
- static inline typename distance_result
- <
- variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
- Geometry2,
- Strategy
- >::type
- apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
- Geometry2 const& geometry2,
- Strategy const& strategy)
- {
- return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
+ result = resolve_strategy::distance
+ <
+ Strategy
+ >::apply(g1, geometry2, strategy);
+ }, geometry1);
+ return result;
}
};
-template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
-struct distance<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+template <typename Geometry1, typename DynamicGeometry2, typename Tag1>
+struct distance<Geometry1, DynamicGeometry2, Tag1, dynamic_geometry_tag>
{
template <typename Strategy>
- struct visitor: static_visitor
- <
- typename distance_result
- <
- Geometry1,
- variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
- Strategy
- >::type
- >
+ static inline auto apply(Geometry1 const& geometry1,
+ DynamicGeometry2 const& geometry2,
+ Strategy const& strategy)
{
- Geometry1 const& m_geometry1;
- Strategy const& m_strategy;
-
- visitor(Geometry1 const& geometry1,
- Strategy const& strategy)
- : m_geometry1(geometry1),
- m_strategy(strategy)
- {}
-
- template <typename Geometry2>
- typename distance_result<Geometry1, Geometry2, Strategy>::type
- operator()(Geometry2 const& geometry2) const
+ using result_t = typename geometry::distance_result<Geometry1, DynamicGeometry2, Strategy>::type;
+ result_t result = 0;
+ traits::visit<DynamicGeometry2>::apply([&](auto const& g2)
{
- return distance
- <
- Geometry1,
- Geometry2
- >::template apply
- <
- Strategy
- >(m_geometry1, geometry2, m_strategy);
- }
- };
-
- template <typename Strategy>
- static inline typename distance_result
- <
- Geometry1,
- variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
- Strategy
- >::type
- apply(
- Geometry1 const& geometry1,
- const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry2,
- Strategy const& strategy)
- {
- return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
+ result = resolve_strategy::distance
+ <
+ Strategy
+ >::apply(geometry1, g2, strategy);
+ }, geometry2);
+ return result;
}
};
-template
-<
- BOOST_VARIANT_ENUM_PARAMS(typename T1),
- BOOST_VARIANT_ENUM_PARAMS(typename T2)
->
-struct distance
- <
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
- >
+template <typename DynamicGeometry1, typename DynamicGeometry2>
+struct distance<DynamicGeometry1, DynamicGeometry2, dynamic_geometry_tag, dynamic_geometry_tag>
{
template <typename Strategy>
- struct visitor: static_visitor
- <
- typename distance_result
- <
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>,
- Strategy
- >::type
- >
+ static inline auto apply(DynamicGeometry1 const& geometry1,
+ DynamicGeometry2 const& geometry2,
+ Strategy const& strategy)
{
- Strategy const& m_strategy;
-
- visitor(Strategy const& strategy)
- : m_strategy(strategy)
- {}
-
- template <typename Geometry1, typename Geometry2>
- typename distance_result<Geometry1, Geometry2, Strategy>::type
- operator()(Geometry1 const& geometry1, Geometry2 const& geometry2) const
+ using result_t = typename geometry::distance_result<DynamicGeometry1, DynamicGeometry2, Strategy>::type;
+ result_t result = 0;
+ traits::visit<DynamicGeometry1, DynamicGeometry2>::apply([&](auto const& g1, auto const& g2)
{
- return distance
- <
- Geometry1,
- Geometry2
- >::template apply
- <
- Strategy
- >(geometry1, geometry2, m_strategy);
- }
- };
-
- template <typename Strategy>
- static inline typename distance_result
- <
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>,
- Strategy
- >::type
- apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
- Strategy const& strategy)
- {
- return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
+ result = resolve_strategy::distance
+ <
+ Strategy
+ >::apply(g1, g2, strategy);
+ }, geometry1, geometry2);
+ return result;
}
};
-} // namespace resolve_variant
+} // namespace resolve_dynamic
/*!
for return_type<...> for your strategy.
*/
template <typename Geometry1, typename Geometry2, typename Strategy>
-inline typename distance_result<Geometry1, Geometry2, Strategy>::type
-distance(Geometry1 const& geometry1,
- Geometry2 const& geometry2,
- Strategy const& strategy)
+inline auto distance(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
detail::throw_on_empty_input(geometry1);
detail::throw_on_empty_input(geometry2);
- return resolve_variant::distance
+ return resolve_dynamic::distance
<
Geometry1,
Geometry2
\qbk{[include reference/algorithms/distance.qbk]}
*/
template <typename Geometry1, typename Geometry2>
-inline typename default_distance_result<Geometry1, Geometry2>::type
-distance(Geometry1 const& geometry1,
- Geometry2 const& geometry2)
+inline auto distance(Geometry1 const& geometry1,
+ Geometry2 const& geometry2)
{
- concepts::check<Geometry1 const>();
- concepts::check<Geometry2 const>();
-
return geometry::distance(geometry1, geometry2, default_strategy());
}