Skip to content

Commit

Permalink
Merge pull request boostorg#812 from awulkiew/feature/strategies_dist…
Browse files Browse the repository at this point in the history
…ance

Umbrella strategies for distance() and comparable_distance().
  • Loading branch information
awulkiew authored Mar 31, 2021
2 parents 8077c7f + dbc8c29 commit 29a6a9f
Show file tree
Hide file tree
Showing 50 changed files with 2,209 additions and 1,922 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2014-2020, Oracle and/or its affiliates.
// 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

Expand Down Expand Up @@ -36,15 +36,14 @@ template
<
typename Point,
typename Range,
closure_selector Closure,
typename Strategy
closure_selector Closure
>
class point_to_point_range
{
protected:
typedef typename boost::range_iterator<Range const>::type iterator_type;

template <typename Distance>
template <typename Strategy, typename Distance>
static inline void apply(Point const& point,
iterator_type first,
iterator_type last,
Expand Down Expand Up @@ -98,7 +97,7 @@ class point_to_point_range
public:
typedef typename std::pair<iterator_type, iterator_type> return_type;

template <typename Distance>
template <typename Strategy, typename Distance>
static inline return_type apply(Point const& point,
iterator_type first,
iterator_type last,
Expand All @@ -111,6 +110,7 @@ class point_to_point_range
return std::make_pair(it_min1, it_min2);
}

template <typename Strategy>
static inline return_type apply(Point const& point,
iterator_type first,
iterator_type last,
Expand All @@ -126,7 +126,7 @@ class point_to_point_range
return apply(point, first, last, strategy, dist_min);
}

template <typename Distance>
template <typename Strategy, typename Distance>
static inline return_type apply(Point const& point,
Range const& range,
Strategy const& strategy,
Expand All @@ -139,6 +139,7 @@ class point_to_point_range
dist_min);
}

template <typename Strategy>
static inline return_type apply(Point const& point,
Range const& range,
Strategy const& strategy)
Expand All @@ -150,15 +151,15 @@ class point_to_point_range


// specialization for open ranges
template <typename Point, typename Range, typename Strategy>
class point_to_point_range<Point, Range, open, Strategy>
: point_to_point_range<Point, Range, closed, Strategy>
template <typename Point, typename Range>
class point_to_point_range<Point, Range, open>
: point_to_point_range<Point, Range, closed>
{
private:
typedef point_to_point_range<Point, Range, closed, Strategy> base_type;
typedef point_to_point_range<Point, Range, closed> base_type;
typedef typename base_type::iterator_type iterator_type;

template <typename Distance>
template <typename Strategy, typename Distance>
static inline void apply(Point const& point,
iterator_type first,
iterator_type last,
Expand Down Expand Up @@ -193,7 +194,7 @@ class point_to_point_range<Point, Range, open, Strategy>
public:
typedef typename std::pair<iterator_type, iterator_type> return_type;

template <typename Distance>
template <typename Strategy, typename Distance>
static inline return_type apply(Point const& point,
iterator_type first,
iterator_type last,
Expand All @@ -207,6 +208,7 @@ class point_to_point_range<Point, Range, open, Strategy>
return std::make_pair(it_min1, it_min2);
}

template <typename Strategy>
static inline return_type apply(Point const& point,
iterator_type first,
iterator_type last,
Expand All @@ -224,7 +226,7 @@ class point_to_point_range<Point, Range, open, Strategy>
return apply(point, first, last, strategy, dist_min);
}

template <typename Distance>
template <typename Strategy, typename Distance>
static inline return_type apply(Point const& point,
Range const& range,
Strategy const& strategy,
Expand All @@ -237,6 +239,7 @@ class point_to_point_range<Point, Range, open, Strategy>
dist_min);
}

template <typename Strategy>
static inline return_type apply(Point const& point,
Range const& range,
Strategy const& strategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,23 @@ class range_to_range_rtree
<
typename RTreeRangeIterator,
typename QueryRangeIterator,
typename Strategy,
typename Strategies,
typename RTreeValueType,
typename Distance
>
static inline void apply(RTreeRangeIterator rtree_first,
RTreeRangeIterator rtree_last,
QueryRangeIterator queries_first,
QueryRangeIterator queries_last,
Strategy const& strategy,
Strategies const& strategies,
RTreeValueType& rtree_min,
QueryRangeIterator& qit_min,
Distance& dist_min)
{
using strategies::index::services::strategy_converter;
typedef index::parameters
<
index::linear<8>,
decltype(strategy_converter<Strategy>::get(strategy))
index::linear<8>, Strategies
> index_parameters_type;
typedef index::rtree<RTreeValueType, index_parameters_type> rtree_type;

Expand All @@ -70,8 +69,7 @@ class range_to_range_rtree

// create -- packing algorithm
rtree_type rt(rtree_first, rtree_last,
index_parameters_type(index::linear<8>(),
strategy_converter<Strategy>::get(strategy)));
index_parameters_type(index::linear<8>(), strategies));

RTreeValueType t_v;
bool first = true;
Expand All @@ -97,8 +95,8 @@ class range_to_range_rtree
<
QueryRangeIterator
>::value_type,
Strategy
>::apply(t_v, *qit, strategy);
Strategies
>::apply(t_v, *qit, strategies);

if (first || dist < dist_min)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.

// This file was modified by Oracle on 2014, 2019.
// Modifications copyright (c) 2014, 2019, 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
Expand All @@ -26,6 +26,9 @@
#include <boost/geometry/strategies/default_comparable_distance_result.hpp>
#include <boost/geometry/strategies/distance.hpp>

#include <boost/geometry/strategies/distance/comparable.hpp>
#include <boost/geometry/strategies/distance/services.hpp>

#include <boost/geometry/algorithms/detail/distance/interface.hpp>


Expand All @@ -36,8 +39,33 @@ namespace boost { namespace geometry
namespace resolve_strategy
{

template <typename Strategy>

template
<
typename Strategies,
bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategies>::value
>
struct comparable_distance
{
template <typename Geometry1, typename Geometry2>
static inline
typename comparable_distance_result<Geometry1, Geometry2, Strategies>::type
apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Strategies const& strategies)
{
return dispatch::distance
<
Geometry1, Geometry2,
strategies::distance::detail::comparable<Strategies>
>::apply(geometry1,
geometry2,
strategies::distance::detail::comparable<Strategies>(strategies));
}
};

template <typename Strategy>
struct comparable_distance<Strategy, false>
{
template <typename Geometry1, typename Geometry2>
static inline
Expand All @@ -46,25 +74,28 @@ struct comparable_distance
Geometry2 const& geometry2,
Strategy const& strategy)
{
typedef typename strategy::distance::services::comparable_type
<
Strategy
>::type comparable_strategy_type;
using strategies::distance::services::strategy_converter;

typedef decltype(strategy_converter<Strategy>::get(strategy))
strategies_type;
typedef strategies::distance::detail::comparable
<
strategies_type
> comparable_strategies_type;

return dispatch::distance
<
Geometry1, Geometry2, comparable_strategy_type
Geometry1, Geometry2,
comparable_strategies_type
>::apply(geometry1,
geometry2,
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy));
comparable_strategies_type(
strategy_converter<Strategy>::get(strategy)));
}
};

template <>
struct comparable_distance<default_strategy>
struct comparable_distance<default_strategy, false>
{
template <typename Geometry1, typename Geometry2>
static inline typename comparable_distance_result
Expand All @@ -75,13 +106,13 @@ struct comparable_distance<default_strategy>
Geometry2 const& geometry2,
default_strategy)
{
typedef typename strategy::distance::services::comparable_type
typedef strategies::distance::detail::comparable
<
typename detail::distance::default_strategy
typename strategies::distance::services::default_strategy
<
Geometry1, Geometry2
>::type
>::type comparable_strategy_type;
> comparable_strategy_type;

return dispatch::distance
<
Expand Down
Loading

0 comments on commit 29a6a9f

Please sign in to comment.