update boost

This commit is contained in:
2023-11-24 12:56:13 -06:00
parent cfc99971af
commit 19d727037a
9260 changed files with 849256 additions and 299957 deletions

View File

@@ -1,333 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014.
// Modifications copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_BACKWARD_COMPATIBILITY_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_BACKWARD_COMPATIBILITY_HPP
#include <boost/geometry/core/closure.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
#include <boost/geometry/algorithms/detail/distance/point_to_geometry.hpp>
#include <boost/geometry/algorithms/detail/distance/multipoint_to_geometry.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace distance
{
template<typename Point, typename Segment, typename Strategy>
struct point_to_segment
{
static inline typename strategy::distance::services::return_type
<
Strategy,
Point,
typename point_type<Segment>::type
>::type
apply(Point const& point, Segment const& segment, Strategy const& )
{
typename detail::distance::default_ps_strategy
<
Point,
typename point_type<Segment>::type,
Strategy
>::type segment_strategy;
typename point_type<Segment>::type p[2];
geometry::detail::assign_point_from_index<0>(segment, p[0]);
geometry::detail::assign_point_from_index<1>(segment, p[1]);
return segment_strategy.apply(point, p[0], p[1]);
}
};
}} // namespace detail::distance
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
// Point-segment version 1, with point-point strategy
template <typename Point, typename Segment, typename Strategy>
struct distance
<
Point, Segment, Strategy,
point_tag, segment_tag, strategy_tag_distance_point_point,
false
> : detail::distance::point_to_segment<Point, Segment, Strategy>
{};
// Point-line version 1, where point-point strategy is specified
template <typename Point, typename Linestring, typename Strategy>
struct distance
<
Point, Linestring, Strategy,
point_tag, linestring_tag, strategy_tag_distance_point_point,
false
>
{
static inline typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Linestring>::type
>::type
apply(Point const& point,
Linestring const& linestring,
Strategy const&)
{
typedef typename detail::distance::default_ps_strategy
<
Point,
typename point_type<Linestring>::type,
Strategy
>::type ps_strategy_type;
return detail::distance::point_to_range
<
Point, Linestring, closed, ps_strategy_type
>::apply(point, linestring, ps_strategy_type());
}
};
// Point-ring , where point-point strategy is specified
template <typename Point, typename Ring, typename Strategy>
struct distance
<
Point, Ring, Strategy,
point_tag, ring_tag, strategy_tag_distance_point_point,
false
>
{
typedef typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Ring>::type
>::type return_type;
static inline return_type apply(Point const& point,
Ring const& ring,
Strategy const&)
{
typedef typename detail::distance::default_ps_strategy
<
Point,
typename point_type<Ring>::type,
Strategy
>::type ps_strategy_type;
return detail::distance::point_to_ring
<
Point, Ring,
geometry::closure<Ring>::value,
ps_strategy_type
>::apply(point, ring, ps_strategy_type());
}
};
// Point-polygon , where point-point strategy is specified
template <typename Point, typename Polygon, typename Strategy>
struct distance
<
Point, Polygon, Strategy,
point_tag, polygon_tag, strategy_tag_distance_point_point,
false
>
{
typedef typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Polygon>::type
>::type return_type;
static inline return_type apply(Point const& point,
Polygon const& polygon,
Strategy const&)
{
typedef typename detail::distance::default_ps_strategy
<
Point,
typename point_type<Polygon>::type,
Strategy
>::type ps_strategy_type;
return detail::distance::point_to_polygon
<
Point,
Polygon,
geometry::closure<Polygon>::value,
ps_strategy_type
>::apply(point, polygon, ps_strategy_type());
}
};
template
<
typename Point,
typename MultiGeometry,
typename MultiGeometryTag,
typename Strategy
>
struct distance
<
Point, MultiGeometry, Strategy,
point_tag, MultiGeometryTag,
strategy_tag_distance_point_point, false
>
{
typedef typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<MultiGeometry>::type
>::type return_type;
static inline return_type apply(Point const& point,
MultiGeometry const& multigeometry,
Strategy const&)
{
typedef typename detail::distance::default_ps_strategy
<
Point,
typename point_type<MultiGeometry>::type,
Strategy
>::type ps_strategy_type;
return distance
<
Point, MultiGeometry, ps_strategy_type,
point_tag, MultiGeometryTag,
strategy_tag_distance_point_segment, false
>::apply(point, multigeometry, ps_strategy_type());
}
};
template
<
typename Geometry,
typename MultiPoint,
typename GeometryTag,
typename Strategy
>
struct distance
<
Geometry, MultiPoint, Strategy,
GeometryTag, multi_point_tag,
strategy_tag_distance_point_point, false
>
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<MultiPoint>::type,
typename point_type<Geometry>::type
>::type return_type;
static inline return_type apply(Geometry const& geometry,
MultiPoint const& multipoint,
Strategy const&)
{
typedef typename detail::distance::default_ps_strategy
<
typename point_type<MultiPoint>::type,
typename point_type<Geometry>::type,
Strategy
>::type ps_strategy_type;
return distance
<
Geometry, MultiPoint, ps_strategy_type,
GeometryTag, multi_point_tag,
strategy_tag_distance_point_segment, false
>::apply(geometry, multipoint, ps_strategy_type());
}
};
template
<
typename MultiPoint,
typename MultiGeometry,
typename MultiGeometryTag,
typename Strategy
>
struct distance
<
MultiPoint, MultiGeometry, Strategy,
multi_point_tag, MultiGeometryTag,
strategy_tag_distance_point_point, false
>
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<MultiPoint>::type,
typename point_type<MultiGeometry>::type
>::type return_type;
static inline return_type apply(MultiPoint const& multipoint,
MultiGeometry const& multigeometry,
Strategy const&)
{
typedef typename detail::distance::default_ps_strategy
<
typename point_type<MultiPoint>::type,
typename point_type<MultiGeometry>::type,
Strategy
>::type ps_strategy_type;
return distance
<
MultiPoint, MultiGeometry, ps_strategy_type,
multi_point_tag, MultiGeometryTag,
strategy_tag_distance_point_segment, false
>::apply(multipoint, multigeometry, ps_strategy_type());
}
};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_BACKWARD_COMPATIBILITY_HPP

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -29,23 +30,17 @@ namespace dispatch
{
template <typename Box1, typename Box2, typename Strategy>
template <typename Box1, typename Box2, typename Strategies>
struct distance
<
Box1, Box2, Strategy, box_tag, box_tag,
Box1, Box2, Strategies, box_tag, box_tag,
strategy_tag_distance_box_box, false
>
{
static inline typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Box1>::type,
typename point_type<Box2>::type
>::type
apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
static inline auto apply(Box1 const& box1, Box2 const& box2, Strategies const& strategies)
{
boost::ignore_unused(strategy);
return strategy.apply(box1, box2);
boost::ignore_unused(strategies);
return strategies.distance(box1, box2).apply(box1, box2);
}
};

View File

@@ -1,157 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014.
// Modifications copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_DEFAULT_STRATEGIES_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_DEFAULT_STRATEGIES_HPP
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tag_cast.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/reverse_dispatch.hpp>
#include <boost/geometry/strategies/distance.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace distance
{
// Helper metafunction for default strategy retrieval
template
<
typename Geometry1,
typename Geometry2 = Geometry1,
typename Tag1 = typename tag_cast
<
typename tag<Geometry1>::type, pointlike_tag
>::type,
typename Tag2 = typename tag_cast
<
typename tag<Geometry2>::type, pointlike_tag
>::type,
bool Reverse = geometry::reverse_dispatch<Geometry1, Geometry2>::type::value
>
struct default_strategy
: strategy::distance::services::default_strategy
<
point_tag, segment_tag,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>
{};
template
<
typename Geometry1,
typename Geometry2,
typename Tag1,
typename Tag2
>
struct default_strategy<Geometry1, Geometry2, Tag1, Tag2, true>
: default_strategy<Geometry2, Geometry1, Tag2, Tag1, false>
{};
template <typename Pointlike1, typename Pointlike2>
struct default_strategy
<
Pointlike1, Pointlike2,
pointlike_tag, pointlike_tag, false
> : strategy::distance::services::default_strategy
<
point_tag, point_tag,
typename point_type<Pointlike1>::type,
typename point_type<Pointlike2>::type
>
{};
template <typename Pointlike, typename Box>
struct default_strategy<Pointlike, Box, pointlike_tag, box_tag, false>
: strategy::distance::services::default_strategy
<
point_tag, box_tag,
typename point_type<Pointlike>::type,
typename point_type<Box>::type
>
{};
template <typename Box1, typename Box2>
struct default_strategy<Box1, Box2, box_tag, box_tag, false>
: strategy::distance::services::default_strategy
<
box_tag, box_tag,
typename point_type<Box1>::type,
typename point_type<Box2>::type
>
{};
template <typename Linear, typename Box>
struct default_strategy<Linear, Box, segment_tag, box_tag, false>
: strategy::distance::services::default_strategy
<
segment_tag, box_tag,
typename point_type<Linear>::type,
typename point_type<Box>::type
>
{};
template <typename Linear, typename Box>
struct default_strategy<Linear, Box, linear_tag, box_tag, false>
: strategy::distance::services::default_strategy
<
segment_tag, box_tag,
typename point_type<Linear>::type,
typename point_type<Box>::type
>
{};
// Helper metafunction for default point-segment strategy retrieval
template <typename Geometry1, typename Geometry2, typename Strategy>
struct default_ps_strategy
: strategy::distance::services::default_strategy
<
point_tag, segment_tag,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type,
typename cs_tag<typename point_type<Geometry1>::type>::type,
typename cs_tag<typename point_type<Geometry2>::type>::type,
Strategy
>
{};
}} // namespace detail::distance
#endif // DOXYGEN_NO_DETAIL
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_DEFAULT_STRATEGIES_HPP

View File

@@ -0,0 +1,237 @@
// Boost.Geometry
// Copyright (c) 2021 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_GEOMETRY_COLLECTION_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_GEOMETRY_COLLECTION_HPP
#include <vector>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/detail/visit.hpp>
#include <boost/geometry/core/assert.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/distance_result.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace distance
{
template <typename Geometry, typename GeometryCollection, typename Strategies>
inline auto geometry_to_collection(Geometry const& geometry,
GeometryCollection const& collection,
Strategies const& strategies)
{
using result_t = typename geometry::distance_result<Geometry, GeometryCollection, Strategies>::type;
result_t result = 0;
bool is_first = true;
detail::visit_breadth_first([&](auto const& g)
{
result_t r = dispatch::distance
<
Geometry, util::remove_cref_t<decltype(g)>, Strategies
>::apply(geometry, g, strategies);
if (is_first)
{
result = r;
is_first = false;
}
else if (r < result)
{
result = r;
}
return result > result_t(0);
}, collection);
return result;
}
template <typename GeometryCollection1, typename GeometryCollection2, typename Strategies>
inline auto collection_to_collection(GeometryCollection1 const& collection1,
GeometryCollection2 const& collection2,
Strategies const& strategies)
{
using result_t = typename geometry::distance_result<GeometryCollection1, GeometryCollection2, Strategies>::type;
using point1_t = typename geometry::point_type<GeometryCollection1>::type;
using box1_t = model::box<point1_t>;
using point2_t = typename geometry::point_type<GeometryCollection2>::type;
using box2_t = model::box<point2_t>;
using rtree_value_t = std::pair<box1_t, typename boost::range_iterator<GeometryCollection1 const>::type>;
using rtree_params_t = index::parameters<index::rstar<4>, Strategies>;
using rtree_t = index::rtree<rtree_value_t, rtree_params_t>;
rtree_params_t rtree_params(index::rstar<4>(), strategies);
rtree_t rtree(rtree_params);
// Build rtree of boxes and iterators of elements of GC1
// TODO: replace this with visit_breadth_first_iterator to avoid creating an unnecessary container?
{
std::vector<rtree_value_t> values;
visit_breadth_first_impl<true>::apply([&](auto & g1, auto it)
{
box1_t b1 = geometry::return_envelope<box1_t>(g1, strategies);
geometry::detail::expand_by_epsilon(b1);
values.emplace_back(b1, it);
return true;
}, collection1);
rtree_t rt(values.begin(), values.end(), rtree_params);
rtree = std::move(rt);
}
result_t const zero = 0;
auto const rtree_qend = rtree.qend();
result_t result = 0;
bool is_first = true;
visit_breadth_first([&](auto const& g2)
{
box2_t b2 = geometry::return_envelope<box2_t>(g2, strategies);
geometry::detail::expand_by_epsilon(b2);
for (auto it = rtree.qbegin(index::nearest(b2, rtree.size())) ; it != rtree_qend ; ++it)
{
// If the distance between boxes is greater than or equal to previously found
// distance between geometries then stop processing the current b2 because no
// closer b1 will be found
if (! is_first)
{
result_t const bd = dispatch::distance
<
box1_t, box2_t, Strategies
>::apply(it->first, b2, strategies);
if (bd >= result)
{
break;
}
}
// Boxes are closer than the previously found distance (or it's the first time),
// calculate the new distance between geometries and check if it's closer (or assign it).
traits::iter_visit<GeometryCollection1>::apply([&](auto const& g1)
{
result_t const d = dispatch::distance
<
util::remove_cref_t<decltype(g1)>, util::remove_cref_t<decltype(g2)>,
Strategies
>::apply(g1, g2, strategies);
if (is_first)
{
result = d;
is_first = false;
}
else if (d < result)
{
result = d;
}
}, it->second);
// The smallest possible distance found, end searching.
if (! is_first && result <= zero)
{
return false;
}
}
// Just in case
return is_first || result > zero;
}, collection2);
return result;
}
}} // namespace detail::distance
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template
<
typename Geometry, typename GeometryCollection, typename Strategies, typename Tag1
>
struct distance
<
Geometry, GeometryCollection, Strategies,
Tag1, geometry_collection_tag, void, false
>
{
static inline auto apply(Geometry const& geometry,
GeometryCollection const& collection,
Strategies const& strategies)
{
assert_dimension_equal<Geometry, GeometryCollection>();
return detail::distance::geometry_to_collection(geometry, collection, strategies);
}
};
template
<
typename GeometryCollection, typename Geometry, typename Strategies, typename Tag2
>
struct distance
<
GeometryCollection, Geometry, Strategies,
geometry_collection_tag, Tag2, void, false
>
{
static inline auto apply(GeometryCollection const& collection,
Geometry const& geometry,
Strategies const& strategies)
{
assert_dimension_equal<Geometry, GeometryCollection>();
return detail::distance::geometry_to_collection(geometry, collection, strategies);
}
};
template
<
typename GeometryCollection1, typename GeometryCollection2, typename Strategies
>
struct distance
<
GeometryCollection1, GeometryCollection2, Strategies,
geometry_collection_tag, geometry_collection_tag, void, false
>
{
static inline auto apply(GeometryCollection1 const& collection1,
GeometryCollection2 const& collection2,
Strategies const& strategies)
{
assert_dimension_equal<GeometryCollection1, GeometryCollection2>();
// Build the rtree for the smaller GC (ignoring recursive GCs)
return boost::size(collection1) <= boost::size(collection2)
? detail::distance::collection_to_collection(collection1, collection2, strategies)
: detail::distance::collection_to_collection(collection2, collection1, strategies);
}
};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_SEGMENT_TO_BOX_HPP

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -12,28 +13,27 @@
#include <iterator>
#include <boost/range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/geometry_to_range.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/point_to_range.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/iterators/point_iterator.hpp>
#include <boost/geometry/iterators/segment_iterator.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/geometry_to_range.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/point_to_range.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>
#include <boost/geometry/util/condition.hpp>
@@ -54,7 +54,7 @@ template
>
struct segment_or_box_point_range_closure
: not_implemented<SegmentOrBox>
{};
{};
template <typename Segment>
struct segment_or_box_point_range_closure<Segment, segment_tag>
@@ -74,7 +74,7 @@ template
<
typename Geometry,
typename SegmentOrBox,
typename Strategy,
typename Strategies,
typename Tag = typename tag<Geometry>::type
>
class geometry_to_segment_or_box
@@ -82,28 +82,18 @@ class geometry_to_segment_or_box
private:
typedef typename point_type<SegmentOrBox>::type segment_or_box_point;
typedef typename strategy::distance::services::comparable_type
<
Strategy
>::type comparable_strategy;
typedef distance::strategy_t<Geometry, SegmentOrBox, Strategies> strategy_type;
typedef detail::closest_feature::point_to_point_range
<
typename point_type<Geometry>::type,
std::vector<segment_or_box_point>,
segment_or_box_point_range_closure<SegmentOrBox>::value,
comparable_strategy
segment_or_box_point_range_closure<SegmentOrBox>::value
> point_to_point_range;
typedef detail::closest_feature::geometry_to_range geometry_to_range;
typedef typename strategy::distance::services::return_type
<
comparable_strategy,
typename point_type<Geometry>::type,
segment_or_box_point
>::type comparable_return_type;
typedef distance::creturn_t<Geometry, SegmentOrBox, Strategies> comparable_return_type;
// assign the new minimum value for an iterator of the point range
// of a segment or a box
@@ -165,45 +155,34 @@ private:
}
};
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Geometry>::type,
segment_or_box_point
>::type return_type;
typedef distance::return_t<Geometry, SegmentOrBox, Strategies> return_type;
static inline return_type apply(Geometry const& geometry,
SegmentOrBox const& segment_or_box,
Strategy const& strategy,
Strategies const& strategies,
bool check_intersection = true)
{
typedef geometry::point_iterator<Geometry const> point_iterator_type;
typedef geometry::segment_iterator
<
Geometry const
> segment_iterator_type;
typedef typename boost::range_const_iterator
<
std::vector<segment_or_box_point>
>::type seg_or_box_const_iterator;
typedef assign_new_min_iterator<SegmentOrBox> assign_new_value;
if (check_intersection
&& geometry::intersects(geometry, segment_or_box))
&& geometry::intersects(geometry, segment_or_box, strategies))
{
return 0;
return return_type(0);
}
comparable_strategy cstrategy =
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy);
strategy_type const strategy = strategies.distance(geometry, segment_or_box);
auto const cstrategy = strategy::distance::services::get_comparable
<
strategy_type
>::apply(strategy);
// get all points of the segment or the box
std::vector<segment_or_box_point>
@@ -211,32 +190,27 @@ public:
assign_segment_or_box_points
<
SegmentOrBox,
SegmentOrBox,
std::vector<segment_or_box_point>
>::apply(segment_or_box, seg_or_box_points);
// consider all distances of the points in the geometry to the
// segment or box
comparable_return_type cd_min1(0);
point_iterator_type pit_min;
seg_or_box_const_iterator it_min1 = boost::const_begin(seg_or_box_points);
seg_or_box_const_iterator it_min2 = it_min1;
++it_min2;
auto pit_min = points_begin(geometry);
auto it_min1 = boost::const_begin(seg_or_box_points);
auto it_min2 = it_min1 + 1;
bool first = true;
for (point_iterator_type pit = points_begin(geometry);
for (auto pit = pit_min;
pit != points_end(geometry); ++pit, first = false)
{
comparable_return_type cd;
std::pair
<
seg_or_box_const_iterator, seg_or_box_const_iterator
> it_pair
= point_to_point_range::apply(*pit,
boost::const_begin(seg_or_box_points),
boost::const_end(seg_or_box_points),
cstrategy,
cd);
auto it_pair = point_to_point_range::apply(*pit,
boost::const_begin(seg_or_box_points),
boost::const_end(seg_or_box_points),
cstrategy,
cd);
if (first || cd < cd_min1)
{
@@ -251,10 +225,10 @@ public:
// segments of the geometry
comparable_return_type cd_min2(0);
segment_iterator_type sit_min;
seg_or_box_const_iterator it_min;
auto it_min = boost::const_begin(seg_or_box_points);
first = true;
for (seg_or_box_const_iterator it = boost::const_begin(seg_or_box_points);
for (auto it = boost::const_begin(seg_or_box_points);
it != boost::const_end(seg_or_box_points); ++it, first = false)
{
comparable_return_type cd;
@@ -273,7 +247,7 @@ public:
}
}
if (BOOST_GEOMETRY_CONDITION(is_comparable<Strategy>::value))
if (BOOST_GEOMETRY_CONDITION(is_comparable<strategy_type>::value))
{
return (std::min)(cd_min1, cd_min2);
}
@@ -291,71 +265,53 @@ public:
<
segment_iterator_type
>::value_type,
Strategy
>::apply(*it_min, *sit_min, strategy);
Strategies
>::apply(*it_min, *sit_min, strategies);
}
}
static inline return_type
apply(SegmentOrBox const& segment_or_box, Geometry const& geometry,
Strategy const& strategy, bool check_intersection = true)
static inline return_type apply(SegmentOrBox const& segment_or_box, Geometry const& geometry,
Strategies const& strategies, bool check_intersection = true)
{
return apply(geometry, segment_or_box, strategy, check_intersection);
return apply(geometry, segment_or_box, strategies, check_intersection);
}
};
template <typename MultiPoint, typename SegmentOrBox, typename Strategy>
template <typename MultiPoint, typename SegmentOrBox, typename Strategies>
class geometry_to_segment_or_box
<
MultiPoint, SegmentOrBox, Strategy, multi_point_tag
MultiPoint, SegmentOrBox, Strategies, multi_point_tag
>
{
private:
typedef detail::closest_feature::geometry_to_range base_type;
typedef typename boost::range_iterator
<
MultiPoint const
>::type iterator_type;
typedef detail::closest_feature::geometry_to_range geometry_to_range;
typedef distance::strategy_t<MultiPoint, SegmentOrBox, Strategies> strategy_type;
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<SegmentOrBox>::type,
typename point_type<MultiPoint>::type
>::type return_type;
typedef distance::return_t<MultiPoint, SegmentOrBox, Strategies> return_type;
static inline return_type apply(MultiPoint const& multipoint,
SegmentOrBox const& segment_or_box,
Strategy const& strategy)
Strategies const& strategies)
{
namespace sds = strategy::distance::services;
distance::creturn_t<MultiPoint, SegmentOrBox, Strategies> cd_min;
typename sds::return_type
<
typename sds::comparable_type<Strategy>::type,
typename point_type<SegmentOrBox>::type,
typename point_type<MultiPoint>::type
>::type cd_min;
iterator_type it_min
auto const it_min
= geometry_to_range::apply(segment_or_box,
boost::begin(multipoint),
boost::end(multipoint),
sds::get_comparable
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy),
strategy_type
>::apply(strategies.distance(multipoint, segment_or_box)),
cd_min);
return
is_comparable<Strategy>::value
is_comparable<strategy_type>::value
?
cd_min
:
@@ -363,8 +319,8 @@ public:
<
typename point_type<MultiPoint>::type,
SegmentOrBox,
Strategy
>::apply(*it_min, segment_or_box, strategy);
Strategies
>::apply(*it_min, segment_or_box, strategies);
}
};

View File

@@ -5,11 +5,11 @@
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2018.
// Modifications copyright (c) 2014-2018, 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 Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
@@ -27,11 +27,15 @@
#include <boost/geometry/algorithms/detail/distance/linear_to_linear.hpp>
#include <boost/geometry/algorithms/detail/distance/linear_or_areal_to_areal.hpp>
#include <boost/geometry/algorithms/detail/distance/linear_to_box.hpp>
#include <boost/geometry/algorithms/detail/distance/geometry_collection.hpp>
#include <boost/geometry/algorithms/detail/distance/geometry_to_segment_or_box.hpp>
#include <boost/geometry/algorithms/detail/distance/segment_to_segment.hpp>
#include <boost/geometry/algorithms/detail/distance/segment_to_box.hpp>
#include <boost/geometry/algorithms/detail/distance/box_to_box.hpp>
#include <boost/geometry/algorithms/detail/distance/backward_compatibility.hpp>
#include <boost/geometry/strategies/distance/backward_compatibility.hpp>
#include <boost/geometry/strategies/distance/cartesian.hpp>
#include <boost/geometry/strategies/distance/geographic.hpp>
#include <boost/geometry/strategies/distance/spherical.hpp>
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_IMPLEMENTATION_HPP

View File

@@ -6,9 +6,8 @@
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2014 Samuel Debionne, Grenoble, France.
// This file was modified by Oracle on 2014, 2018.
// Modifications copyright (c) 2014-2018, 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
@@ -24,23 +23,22 @@
#include <boost/concept_check.hpp>
#include <boost/mpl/always.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/vector.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
@@ -66,17 +64,8 @@ struct distance
>
: 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
<
@@ -95,14 +84,17 @@ struct 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
<
@@ -111,17 +103,69 @@ struct 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;
@@ -136,18 +180,22 @@ struct distance<default_strategy>
} // 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
<
@@ -157,174 +205,72 @@ struct 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
/*!
@@ -364,10 +310,9 @@ for distance, it is probably so that there is no specialization
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>();
@@ -375,7 +320,7 @@ distance(Geometry1 const& geometry1,
detail::throw_on_empty_input(geometry1);
detail::throw_on_empty_input(geometry2);
return resolve_variant::distance
return resolve_dynamic::distance
<
Geometry1,
Geometry2
@@ -397,13 +342,9 @@ distance(Geometry1 const& geometry1,
\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());
}

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Copyright (c) 2014-2020, 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -10,7 +11,8 @@
#ifndef BOOST_GEOMETRY_ALGORITHS_DETAIL_DISTANCE_IS_COMPARABLE_HPP
#define BOOST_GEOMETRY_ALGORITHS_DETAIL_DISTANCE_IS_COMPARABLE_HPP
#include <boost/type_traits/is_same.hpp>
#include <type_traits>
#include <boost/geometry/strategies/distance.hpp>
@@ -26,7 +28,7 @@ namespace detail { namespace distance
// metafunction to determine is a strategy is comparable or not
template <typename Strategy>
struct is_comparable
: boost::is_same
: std::is_same
<
Strategy,
typename strategy::distance::services::comparable_type

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -10,13 +11,14 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_OR_AREAL_TO_AREAL_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_OR_AREAL_TO_AREAL_HPP
#include <boost/geometry/algorithms/detail/distance/linear_to_linear.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/detail/distance/linear_to_linear.hpp>
namespace boost { namespace geometry
{
@@ -26,63 +28,53 @@ namespace detail { namespace distance
{
template <typename Linear, typename Areal, typename Strategy>
template <typename Linear, typename Areal, typename Strategies>
struct linear_to_areal
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Linear>::type,
typename point_type<Areal>::type
>::type return_type;
typedef distance::return_t<Linear, Areal, Strategies> return_type;
static inline return_type apply(Linear const& linear,
Areal const& areal,
Strategy const& strategy)
Strategies const& strategies)
{
if ( geometry::intersects(linear, areal) )
if ( geometry::intersects(linear, areal, strategies) )
{
return 0;
return return_type(0);
}
return linear_to_linear
<
Linear, Areal, Strategy
>::apply(linear, areal, strategy, false);
Linear, Areal, Strategies
>::apply(linear, areal, strategies, false);
}
static inline return_type apply(Areal const& areal,
Linear const& linear,
Strategy const& strategy)
Strategies const& strategies)
{
return apply(linear, areal, strategy);
return apply(linear, areal, strategies);
}
};
template <typename Areal1, typename Areal2, typename Strategy>
template <typename Areal1, typename Areal2, typename Strategies>
struct areal_to_areal
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Areal1>::type,
typename point_type<Areal2>::type
>::type return_type;
typedef distance::return_t<Areal1, Areal2, Strategies> return_type;
static inline return_type apply(Areal1 const& areal1,
Areal2 const& areal2,
Strategy const& strategy)
Strategies const& strategies)
{
if ( geometry::intersects(areal1, areal2) )
if ( geometry::intersects(areal1, areal2, strategies) )
{
return 0;
return return_type(0);
}
return linear_to_linear
<
Areal1, Areal2, Strategy
>::apply(areal1, areal2, strategy, false);
Areal1, Areal2, Strategies
>::apply(areal1, areal2, strategies, false);
}
};
@@ -99,7 +91,7 @@ template <typename Linear, typename Areal, typename Strategy>
struct distance
<
Linear, Areal, Strategy,
linear_tag, areal_tag,
linear_tag, areal_tag,
strategy_tag_distance_point_segment, false
>
: detail::distance::linear_to_areal
@@ -112,7 +104,7 @@ template <typename Areal, typename Linear, typename Strategy>
struct distance
<
Areal, Linear, Strategy,
areal_tag, linear_tag,
areal_tag, linear_tag,
strategy_tag_distance_point_segment, false
>
: detail::distance::linear_to_areal
@@ -126,7 +118,7 @@ template <typename Areal1, typename Areal2, typename Strategy>
struct distance
<
Areal1, Areal2, Strategy,
areal_tag, areal_tag,
areal_tag, areal_tag,
strategy_tag_distance_point_segment, false
>
: detail::distance::areal_to_areal

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2018, Oracle and/or its affiliates.
// Copyright (c) 2018-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -10,9 +11,16 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP
#include <boost/geometry/core/point_type.hpp>
#include <iterator>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/iterators/segment_iterator.hpp>
#include <boost/geometry/core/point_type.hpp>
namespace boost { namespace geometry
{
@@ -21,21 +29,16 @@ namespace boost { namespace geometry
namespace detail { namespace distance
{
template <typename Linear, typename Box, typename Strategy>
template <typename Linear, typename Box, typename Strategies>
struct linear_to_box
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Linear>::type,
typename point_type<Box>::type
>::type return_type;
typedef distance::return_t<Linear, Box, Strategies> return_type;
template <typename Iterator>
static inline return_type apply(Box const& box,
Iterator begin,
Iterator end,
Strategy const& strategy)
Strategies const& strategies)
{
bool first = true;
return_type d_min(0);
@@ -44,8 +47,8 @@ struct linear_to_box
typedef typename std::iterator_traits<Iterator>::value_type
Segment;
return_type d = dispatch::distance<Segment, Box, Strategy>
::apply(*it, box, strategy);
return_type d = dispatch::distance<Segment, Box, Strategies>
::apply(*it, box, strategies);
if ( first || d < d_min )
{
@@ -57,25 +60,25 @@ struct linear_to_box
static inline return_type apply(Linear const& linear,
Box const& box,
Strategy const& strategy)
Strategies const& strategies)
{
if ( geometry::intersects(linear, box) )
{
return 0;
return return_type(0);
}
return apply(box,
geometry::segments_begin(linear),
geometry::segments_end(linear),
strategy);
strategies);
}
static inline return_type apply(Box const& box,
Linear const& linear,
Strategy const& strategy)
Strategies const& strategies)
{
return apply(linear, box, strategy);
return apply(linear, box, strategies);
}
};

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -10,19 +11,18 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/algorithms/num_segments.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/iterators/point_iterator.hpp>
#include <boost/geometry/iterators/segment_iterator.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/algorithms/num_segments.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
#include <boost/geometry/strategies/distance.hpp>
namespace boost { namespace geometry
@@ -33,19 +33,14 @@ namespace detail { namespace distance
{
template <typename Linear1, typename Linear2, typename Strategy>
template <typename Linear1, typename Linear2, typename Strategies>
struct linear_to_linear
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Linear1>::type,
typename point_type<Linear2>::type
>::type return_type;
typedef distance::return_t<Linear1, Linear2, Strategies> return_type;
static inline return_type apply(Linear1 const& linear1,
Linear2 const& linear2,
Strategy const& strategy,
Strategies const& strategies,
bool = false)
{
if (geometry::num_points(linear1) == 1)
@@ -54,8 +49,8 @@ struct linear_to_linear
<
typename point_type<Linear1>::type,
Linear2,
Strategy
>::apply(*points_begin(linear1), linear2, strategy);
Strategies
>::apply(*points_begin(linear1), linear2, strategies);
}
if (geometry::num_points(linear2) == 1)
@@ -64,8 +59,8 @@ struct linear_to_linear
<
typename point_type<Linear2>::type,
Linear1,
Strategy
>::apply(*points_begin(linear2), linear1, strategy);
Strategies
>::apply(*points_begin(linear2), linear1, strategies);
}
if (geometry::num_segments(linear2) < geometry::num_segments(linear1))
@@ -74,11 +69,11 @@ struct linear_to_linear
<
geometry::segment_iterator<Linear2 const>,
Linear1,
Strategy
Strategies
>::apply(geometry::segments_begin(linear2),
geometry::segments_end(linear2),
linear1,
strategy);
strategies);
}
@@ -86,11 +81,11 @@ struct linear_to_linear
<
geometry::segment_iterator<Linear1 const>,
Linear2,
Strategy
Strategies
>::apply(geometry::segments_begin(linear1),
geometry::segments_end(linear1),
linear2,
strategy);
strategies);
}
};
@@ -103,12 +98,12 @@ struct linear_to_linear
namespace dispatch
{
template <typename Linear1, typename Linear2, typename Strategy>
template <typename Linear1, typename Linear2, typename Strategy, typename StrategyTag>
struct distance
<
Linear1, Linear2, Strategy,
linear_tag, linear_tag,
strategy_tag_distance_point_segment, false
linear_tag, linear_tag,
StrategyTag, false
> : detail::distance::linear_to_linear
<
Linear1, Linear2, Strategy

View File

@@ -1,8 +1,10 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -10,7 +12,14 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP
#include <boost/range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
#include <boost/geometry/algorithms/covered_by.hpp>
#include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/tags.hpp>
@@ -18,13 +27,6 @@
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>
#include <boost/geometry/algorithms/covered_by.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
#include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
namespace boost { namespace geometry
{
@@ -34,139 +36,118 @@ namespace detail { namespace distance
{
template <typename MultiPoint1, typename MultiPoint2, typename Strategy>
template <typename MultiPoint1, typename MultiPoint2, typename Strategies>
struct multipoint_to_multipoint
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<MultiPoint1>::type,
typename point_type<MultiPoint2>::type
>::type return_type;
typedef distance::return_t<MultiPoint1, MultiPoint2, Strategies> return_type;
static inline return_type apply(MultiPoint1 const& multipoint1,
MultiPoint2 const& multipoint2,
Strategy const& strategy)
Strategies const& strategies)
{
if (boost::size(multipoint2) < boost::size(multipoint1))
{
return point_or_segment_range_to_geometry_rtree
<
typename boost::range_iterator<MultiPoint2 const>::type,
MultiPoint1,
Strategy
Strategies
>::apply(boost::begin(multipoint2),
boost::end(multipoint2),
multipoint1,
strategy);
strategies);
}
return point_or_segment_range_to_geometry_rtree
<
typename boost::range_iterator<MultiPoint1 const>::type,
MultiPoint2,
Strategy
Strategies
>::apply(boost::begin(multipoint1),
boost::end(multipoint1),
multipoint2,
strategy);
strategies);
}
};
template <typename MultiPoint, typename Linear, typename Strategy>
template <typename MultiPoint, typename Linear, typename Strategies>
struct multipoint_to_linear
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<MultiPoint>::type,
typename point_type<Linear>::type
>::type return_type;
static inline return_type apply(MultiPoint const& multipoint,
Linear const& linear,
Strategy const& strategy)
static inline auto apply(MultiPoint const& multipoint,
Linear const& linear,
Strategies const& strategies)
{
return detail::distance::point_or_segment_range_to_geometry_rtree
<
typename boost::range_iterator<MultiPoint const>::type,
Linear,
Strategy
Strategies
>::apply(boost::begin(multipoint),
boost::end(multipoint),
linear,
strategy);
strategies);
}
static inline return_type apply(Linear const& linear,
MultiPoint const& multipoint,
Strategy const& strategy)
static inline auto apply(Linear const& linear,
MultiPoint const& multipoint,
Strategies const& strategies)
{
return apply(multipoint, linear, strategy);
return apply(multipoint, linear, strategies);
}
};
template <typename MultiPoint, typename Areal, typename Strategy>
template <typename MultiPoint, typename Areal, typename Strategies>
class multipoint_to_areal
{
private:
struct not_covered_by_areal
struct covered_by_areal
{
not_covered_by_areal(Areal const& areal)
: m_areal(areal)
covered_by_areal(Areal const& areal, Strategies const& strategy)
: m_areal(areal), m_strategy(strategy)
{}
template <typename Point>
inline bool apply(Point const& point) const
inline bool operator()(Point const& point) const
{
return !geometry::covered_by(point, m_areal);
return geometry::covered_by(point, m_areal, m_strategy);
}
Areal const& m_areal;
Strategies const& m_strategy;
};
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<MultiPoint>::type,
typename point_type<Areal>::type
>::type return_type;
typedef distance::return_t<MultiPoint, Areal, Strategies> return_type;
static inline return_type apply(MultiPoint const& multipoint,
Areal const& areal,
Strategy const& strategy)
Strategies const& strategies)
{
not_covered_by_areal predicate(areal);
covered_by_areal predicate(areal, strategies);
if (check_iterator_range
<
not_covered_by_areal, false
>::apply(boost::begin(multipoint),
boost::end(multipoint),
predicate))
if (! boost::empty(multipoint) &&
std::none_of(boost::begin(multipoint), boost::end(multipoint), predicate))
{
return detail::distance::point_or_segment_range_to_geometry_rtree
<
typename boost::range_iterator<MultiPoint const>::type,
Areal,
Strategy
Strategies
>::apply(boost::begin(multipoint),
boost::end(multipoint),
areal,
strategy);
strategies);
}
return 0;
return return_type(0);
}
static inline return_type apply(Areal const& areal,
MultiPoint const& multipoint,
Strategy const& strategy)
Strategies const& strategies)
{
return apply(multipoint, areal, strategy);
return apply(multipoint, areal, strategies);
}
};

View File

@@ -5,8 +5,8 @@
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// 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
@@ -22,10 +22,22 @@
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_POINT_TO_GEOMETRY_HPP
#include <iterator>
#include <type_traits>
#include <boost/core/ignore_unused.hpp>
#include <boost/range.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
#include <boost/range/value_type.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/geometry_to_range.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/point_to_range.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/distance/iterator_selector.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/core/closure.hpp>
#include <boost/geometry/core/point_type.hpp>
@@ -34,20 +46,11 @@
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/util/math.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/relate/services.hpp>
#include <boost/geometry/strategies/tags.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/geometry_to_range.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/point_to_range.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/distance/iterator_selector.hpp>
#include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/util/math.hpp>
namespace boost { namespace geometry
@@ -58,12 +61,28 @@ namespace detail { namespace distance
{
template <typename P1, typename P2, typename Strategy>
template
<
typename P1, typename P2, typename Strategies,
bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategies>::value
>
struct point_to_point
{
static inline
typename strategy::distance::services::return_type<Strategy, P1, P2>::type
apply(P1 const& p1, P2 const& p2, Strategy const& strategy)
auto apply(P1 const& p1, P2 const& p2, Strategies const& strategies)
{
boost::ignore_unused(strategies);
return strategies.distance(p1, p2).apply(p1, p2);
}
};
// TEMP?
// called by geometry_to_range
template <typename P1, typename P2, typename Strategy>
struct point_to_point<P1, P2, Strategy, false>
{
static inline
auto apply(P1 const& p1, P2 const& p2, Strategy const& strategy)
{
boost::ignore_unused(strategy);
return strategy.apply(p1, p2);
@@ -71,52 +90,101 @@ struct point_to_point
};
template
<
typename Point, typename Segment, typename Strategies,
bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategies>::value
>
struct point_to_segment
{
static inline auto apply(Point const& point, Segment const& segment,
Strategies const& strategies)
{
typename point_type<Segment>::type p[2];
geometry::detail::assign_point_from_index<0>(segment, p[0]);
geometry::detail::assign_point_from_index<1>(segment, p[1]);
boost::ignore_unused(strategies);
return strategies.distance(point, segment).apply(point, p[0], p[1]);
}
};
// TEMP?
// called by geometry_to_range
template <typename Point, typename Segment, typename Strategy>
struct point_to_segment<Point, Segment, Strategy, false>
{
static inline auto apply(Point const& point, Segment const& segment,
Strategy const& strategy)
{
typename point_type<Segment>::type p[2];
geometry::detail::assign_point_from_index<0>(segment, p[0]);
geometry::detail::assign_point_from_index<1>(segment, p[1]);
boost::ignore_unused(strategy);
return strategy.apply(point, p[0], p[1]);
}
};
template
<
typename Point, typename Box, typename Strategies,
bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategies>::value
>
struct point_to_box
{
static inline auto apply(Point const& point, Box const& box,
Strategies const& strategies)
{
boost::ignore_unused(strategies);
return strategies.distance(point, box).apply(point, box);
}
};
// TEMP?
// called by geometry_to_range
template <typename Point, typename Box, typename Strategy>
struct point_to_box<Point, Box, Strategy, false>
{
static inline auto apply(Point const& point, Box const& box,
Strategy const& strategy)
{
boost::ignore_unused(strategy);
return strategy.apply(point, box);
}
};
template
<
typename Point,
typename Range,
closure_selector Closure,
typename Strategy
typename Strategies
>
class point_to_range
{
private:
typedef typename strategy::distance::services::comparable_type
<
Strategy
>::type comparable_strategy;
typedef distance::strategy_t<Point, Range, Strategies> strategy_type;
typedef detail::closest_feature::point_to_point_range
<
Point, Range, Closure, comparable_strategy
Point, Range, Closure
> point_to_point_range;
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
Point,
typename boost::range_value<Range>::type
>::type return_type;
typedef distance::return_t<Point, Range, Strategies> return_type;
static inline return_type apply(Point const& point, Range const& range,
Strategy const& strategy)
Strategies const& strategies)
{
return_type const zero = return_type(0);
if (boost::size(range) == 0)
{
return zero;
return return_type(0);
}
namespace sds = strategy::distance::services;
typename sds::return_type
<
comparable_strategy,
Point,
typename point_type<Range>::type
>::type cd_min;
distance::creturn_t<Point, Range, Strategies> cd_min;
std::pair
<
@@ -126,18 +194,18 @@ public:
= point_to_point_range::apply(point,
boost::begin(range),
boost::end(range),
sds::get_comparable
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy),
strategy_type
>::apply(strategies.distance(point, range)),
cd_min);
return
is_comparable<Strategy>::value
is_comparable<strategy_type>::value
?
cd_min
:
strategy.apply(point, *it_pair.first, *it_pair.second);
strategies.distance(point, range).apply(point, *it_pair.first, *it_pair.second);
}
};
@@ -147,29 +215,25 @@ template
typename Point,
typename Ring,
closure_selector Closure,
typename Strategy
typename Strategies
>
struct point_to_ring
{
typedef typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Ring>::type
>::type return_type;
typedef distance::return_t<Point, Ring, Strategies> return_type;
static inline return_type apply(Point const& point,
Ring const& ring,
Strategy const& strategy)
Strategies const& strategies)
{
// TODO: pass strategy
if (within::within_point_geometry(point, ring))
if (within::within_point_geometry(point, ring, strategies))
{
return return_type(0);
}
return point_to_range
<
Point, Ring, closure<Ring>::value, Strategy
>::apply(point, ring, strategy);
Point, Ring, closure<Ring>::value, Strategies
>::apply(point, ring, strategies);
}
};
@@ -179,20 +243,17 @@ template
typename Point,
typename Polygon,
closure_selector Closure,
typename Strategy
typename Strategies
>
class point_to_polygon
{
public:
typedef typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Polygon>::type
>::type return_type;
typedef distance::return_t<Point, Polygon, Strategies> return_type;
private:
typedef point_to_range
<
Point, typename ring_type<Polygon>::type, Closure, Strategy
Point, typename ring_type<Polygon>::type, Closure, Strategies
> per_ring;
struct distance_to_interior_rings
@@ -201,31 +262,29 @@ private:
static inline return_type apply(Point const& point,
InteriorRingIterator first,
InteriorRingIterator last,
Strategy const& strategy)
Strategies const& strategies)
{
for (InteriorRingIterator it = first; it != last; ++it)
{
// TODO: pass strategy
if (within::within_point_geometry(point, *it))
if (within::within_point_geometry(point, *it, strategies))
{
// the point is inside a polygon hole, so its distance
// to the polygon its distance to the polygon's
// hole boundary
return per_ring::apply(point, *it, strategy);
return per_ring::apply(point, *it, strategies);
}
}
return 0;
return return_type(0);
}
template <typename InteriorRings>
static inline return_type apply(Point const& point,
InteriorRings const& interior_rings,
Strategy const& strategy)
static inline return_type apply(Point const& point, InteriorRings const& interior_rings,
Strategies const& strategies)
{
return apply(point,
boost::begin(interior_rings),
boost::end(interior_rings),
strategy);
strategies);
}
};
@@ -233,20 +292,20 @@ private:
public:
static inline return_type apply(Point const& point,
Polygon const& polygon,
Strategy const& strategy)
Strategies const& strategies)
{
// TODO: pass strategy
if (! within::covered_by_point_geometry(point, exterior_ring(polygon)))
if (! within::covered_by_point_geometry(point, exterior_ring(polygon),
strategies))
{
// the point is outside the exterior ring, so its distance
// to the polygon is its distance to the polygon's exterior ring
return per_ring::apply(point, exterior_ring(polygon), strategy);
return per_ring::apply(point, exterior_ring(polygon), strategies);
}
// Check interior rings
return distance_to_interior_rings::apply(point,
interior_rings(polygon),
strategy);
strategies);
}
};
@@ -255,8 +314,8 @@ template
<
typename Point,
typename MultiGeometry,
typename Strategy,
bool CheckCoveredBy = boost::is_same
typename Strategies,
bool CheckCoveredBy = std::is_same
<
typename tag<MultiGeometry>::type, multi_polygon_tag
>::value
@@ -266,41 +325,35 @@ class point_to_multigeometry
private:
typedef detail::closest_feature::geometry_to_range geometry_to_range;
typedef distance::strategy_t<Point, MultiGeometry, Strategies> strategy_type;
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
Point,
typename point_type<MultiGeometry>::type
>::type return_type;
typedef distance::return_t<Point, MultiGeometry, Strategies> return_type;
static inline return_type apply(Point const& point,
MultiGeometry const& multigeometry,
Strategy const& strategy)
Strategies const& strategies)
{
typedef iterator_selector<MultiGeometry const> selector_type;
namespace sds = strategy::distance::services;
typename sds::return_type
<
typename sds::comparable_type<Strategy>::type,
Point,
typename point_type<MultiGeometry>::type
>::type cd;
distance::creturn_t<Point, MultiGeometry, Strategies> cd;
typename selector_type::iterator_type it_min
= geometry_to_range::apply(point,
selector_type::begin(multigeometry),
selector_type::end(multigeometry),
sds::get_comparable
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy),
strategy_type
>::apply(strategies.distance(point, multigeometry)),
cd);
// TODO - It would be possible to use a tool similar to result_from_distance
// but working in the opposite way, i.e. calculating the distance
// value from comparable distance value. This way the additional distance
// call would not be needed.
return
is_comparable<Strategy>::value
is_comparable<strategy_type>::value
?
cd
:
@@ -311,38 +364,32 @@ public:
<
typename selector_type::iterator_type
>::value_type,
Strategy
>::apply(point, *it_min, strategy);
Strategies
>::apply(point, *it_min, strategies);
}
};
// this is called only for multipolygons, hence the change in the
// template parameter name MultiGeometry to MultiPolygon
template <typename Point, typename MultiPolygon, typename Strategy>
struct point_to_multigeometry<Point, MultiPolygon, Strategy, true>
template <typename Point, typename MultiPolygon, typename Strategies>
struct point_to_multigeometry<Point, MultiPolygon, Strategies, true>
{
typedef typename strategy::distance::services::return_type
<
Strategy,
Point,
typename point_type<MultiPolygon>::type
>::type return_type;
typedef distance::return_t<Point, MultiPolygon, Strategies> return_type;
static inline return_type apply(Point const& point,
MultiPolygon const& multipolygon,
Strategy const& strategy)
Strategies const& strategies)
{
// TODO: pass strategy
if (within::covered_by_point_geometry(point, multipolygon))
if (within::covered_by_point_geometry(point, multipolygon, strategies))
{
return 0;
return return_type(0);
}
return point_to_multigeometry
<
Point, MultiPolygon, Strategy, false
>::apply(point, multipolygon, strategy);
Point, MultiPolygon, Strategies, false
>::apply(point, multipolygon, strategies);
}
};
@@ -358,7 +405,6 @@ namespace dispatch
{
// Point-point
template <typename P1, typename P2, typename Strategy>
struct distance
<
@@ -368,7 +414,6 @@ struct distance
{};
// Point-line version 2, where point-segment strategy is specified
template <typename Point, typename Linestring, typename Strategy>
struct distance
<
@@ -378,7 +423,6 @@ struct distance
{};
// Point-ring , where point-segment strategy is specified
template <typename Point, typename Ring, typename Strategy>
struct distance
<
@@ -391,7 +435,6 @@ struct distance
{};
// Point-polygon , where point-segment strategy is specified
template <typename Point, typename Polygon, typename Strategy>
struct distance
<
@@ -404,29 +447,13 @@ struct distance
{};
// Point-segment version 2, with point-segment strategy
template <typename Point, typename Segment, typename Strategy>
struct distance
<
Point, Segment, Strategy, point_tag, segment_tag,
strategy_tag_distance_point_segment, false
>
{
static inline typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Segment>::type
>::type apply(Point const& point,
Segment const& segment,
Strategy const& strategy)
{
typename point_type<Segment>::type p[2];
geometry::detail::assign_point_from_index<0>(segment, p[0]);
geometry::detail::assign_point_from_index<1>(segment, p[1]);
boost::ignore_unused(strategy);
return strategy.apply(point, p[0], p[1]);
}
};
> : detail::distance::point_to_segment<Point, Segment, Strategy>
{};
template <typename Point, typename Box, typename Strategy>
@@ -434,18 +461,8 @@ struct distance
<
Point, Box, Strategy, point_tag, box_tag,
strategy_tag_distance_point_box, false
>
{
static inline typename strategy::distance::services::return_type
<
Strategy, Point, typename point_type<Box>::type
>::type
apply(Point const& point, Box const& box, Strategy const& strategy)
{
boost::ignore_unused(strategy);
return strategy.apply(point, box);
}
};
> : detail::distance::point_to_box<Point, Box, Strategy>
{};
template<typename Point, typename MultiPoint, typename Strategy>

View File

@@ -1,8 +1,8 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Boost.Geometry
// 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -13,18 +13,18 @@
#include <iterator>
#include <utility>
#include <boost/geometry/core/assert.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/iterators/has_one_element.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/range_to_range.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/distance/iterator_selector.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/core/assert.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/iterators/detail/has_one_element.hpp>
#include <boost/geometry/strategies/distance.hpp>
namespace boost { namespace geometry
@@ -40,7 +40,7 @@ template
<
typename PointOrSegmentIterator,
typename Geometry,
typename Strategy
typename Strategies
>
class point_or_segment_range_to_geometry_rtree
{
@@ -54,37 +54,27 @@ private:
typedef detail::closest_feature::range_to_range_rtree range_to_range;
typedef distance::strategy_t<point_or_segment_type, Geometry, Strategies> strategy_type;
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<point_or_segment_type>::type,
typename point_type<Geometry>::type
>::type return_type;
typedef distance::return_t<point_or_segment_type, Geometry, Strategies> return_type;
static inline return_type apply(PointOrSegmentIterator first,
PointOrSegmentIterator last,
Geometry const& geometry,
Strategy const& strategy)
Strategies const& strategies)
{
namespace sds = strategy::distance::services;
BOOST_GEOMETRY_ASSERT( first != last );
if ( geometry::has_one_element(first, last) )
if ( detail::has_one_element(first, last) )
{
return dispatch::distance
<
point_or_segment_type, Geometry, Strategy
>::apply(*first, geometry, strategy);
point_or_segment_type, Geometry, Strategies
>::apply(*first, geometry, strategies);
}
typename sds::return_type
<
typename sds::comparable_type<Strategy>::type,
typename point_type<point_or_segment_type>::type,
typename point_type<Geometry>::type
>::type cd_min;
distance::creturn_t<point_or_segment_type, Geometry, Strategies> cd_min;
std::pair
<
@@ -95,28 +85,25 @@ public:
last,
selector_type::begin(geometry),
selector_type::end(geometry),
sds::get_comparable
<
Strategy
>::apply(strategy),
strategies,
cd_min);
return
is_comparable<Strategy>::value
is_comparable<strategy_type>::value
?
cd_min
:
dispatch::distance
<
point_or_segment_type,
point_or_segment_type,
typename std::iterator_traits
<
typename selector_type::iterator_type
>::value_type,
Strategy
Strategies
>::apply(closest_features.first,
*closest_features.second,
strategy);
strategies);
}
};

View File

@@ -1,6 +1,6 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014-2019 Oracle and/or its affiliates.
// Copyright (c) 2014-2023 Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
@@ -13,14 +13,23 @@
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_SEGMENT_TO_BOX_HPP
#include <cstddef>
#include <functional>
#include <type_traits>
#include <vector>
#include <boost/core/ignore_unused.hpp>
#include <boost/mpl/if.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
#include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/point_to_range.hpp>
#include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/detail/dummy_geometries.hpp>
#include <boost/geometry/algorithms/detail/equals/point_point.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/assert.hpp>
@@ -29,16 +38,6 @@
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
#include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
#include <boost/geometry/algorithms/detail/closest_feature/point_to_range.hpp>
#include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
#include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/equals/point_point.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>
#include <boost/geometry/policies/compare.hpp>
#include <boost/geometry/util/calculation_type.hpp>
@@ -50,7 +49,6 @@
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>
namespace boost { namespace geometry
{
@@ -60,26 +58,24 @@ namespace detail { namespace distance
{
// TODO: Take strategy
template <typename Segment, typename Box>
inline bool intersects_segment_box(Segment const& segment, Box const& box)
template <typename Segment, typename Box, typename Strategy>
inline bool intersects_segment_box(Segment const& segment, Box const& box,
Strategy const& strategy)
{
typedef typename strategy::disjoint::services::default_strategy
<
Segment, Box
>::type strategy_type;
return ! detail::disjoint::disjoint_segment_box::apply(segment, box,
strategy_type());
return ! detail::disjoint::disjoint_segment_box::apply(segment, box, strategy);
}
// TODO: segment_to_box_2D_generic is not used anymore. Remove?
// TODO: Furthermore this utility can potentially use different strategy than
// the one that was passed into bg::distance() but it seems this is by design.
template
<
typename Segment,
typename Box,
typename Strategy,
bool UsePointBoxStrategy = false
typename Strategies,
bool UsePointBoxStrategy = false // use only PointSegment strategy
>
class segment_to_box_2D_generic
{
@@ -87,46 +83,29 @@ private:
typedef typename point_type<Segment>::type segment_point;
typedef typename point_type<Box>::type box_point;
typedef typename strategy::distance::services::comparable_type
<
typename Strategy::distance_ps_strategy::type
>::type comparable_strategy;
typedef distance::strategy_t<box_point, Segment, Strategies> ps_strategy_type;
typedef detail::closest_feature::point_to_point_range
<
segment_point,
std::vector<box_point>,
open,
comparable_strategy
open
> point_to_point_range;
typedef typename strategy::distance::services::return_type
<
comparable_strategy, segment_point, box_point
>::type comparable_return_type;
public:
typedef typename strategy::distance::services::return_type
<
Strategy, segment_point, box_point
>::type return_type;
// TODO: Or should the return type be defined by sb_strategy_type?
typedef distance::return_t<box_point, Segment, Strategies> return_type;
static inline return_type apply(Segment const& segment,
Box const& box,
Strategy const& strategy,
Strategies const& strategies,
bool check_intersection = true)
{
if (check_intersection && intersects_segment_box(segment, box))
if (check_intersection && intersects_segment_box(segment, box, strategies))
{
return 0;
return return_type(0);
}
comparable_strategy cstrategy =
strategy::distance::services::get_comparable
<
typename Strategy::distance_ps_strategy::type
>::apply(strategy.get_distance_ps_strategy());
// get segment points
segment_point p[2];
detail::assign_point_from_index<0>(segment, p[0]);
@@ -135,8 +114,15 @@ public:
// get box points
std::vector<box_point> box_points(4);
detail::assign_box_corners_oriented<true>(box, box_points);
comparable_return_type cd[6];
ps_strategy_type const strategy = strategies.distance(dummy_point(), dummy_segment());
auto const cstrategy = strategy::distance::services::get_comparable
<
ps_strategy_type
>::apply(strategy);
distance::creturn_t<box_point, Segment, Strategies> cd[6];
for (unsigned int i = 0; i < 4; ++i)
{
cd[i] = cstrategy.apply(box_points[i], p[0], p[1]);
@@ -168,19 +154,19 @@ public:
}
}
if (BOOST_GEOMETRY_CONDITION(is_comparable<Strategy>::value))
if (BOOST_GEOMETRY_CONDITION(is_comparable<ps_strategy_type>::value))
{
return cd[imin];
}
if (imin < 4)
{
return strategy.get_distance_ps_strategy().apply(box_points[imin], p[0], p[1]);
return strategy.apply(box_points[imin], p[0], p[1]);
}
else
{
unsigned int bimin = imin - 4;
return strategy.get_distance_ps_strategy().apply(p[bimin],
return strategy.apply(p[bimin],
*bit_min[bimin].first,
*bit_min[bimin].second);
}
@@ -192,57 +178,31 @@ template
<
typename Segment,
typename Box,
typename Strategy
typename Strategies
>
class segment_to_box_2D_generic<Segment, Box, Strategy, true>
class segment_to_box_2D_generic<Segment, Box, Strategies, true> // Use both PointSegment and PointBox strategies
{
private:
typedef typename point_type<Segment>::type segment_point;
typedef typename point_type<Box>::type box_point;
typedef typename strategy::distance::services::comparable_type
<
Strategy
>::type comparable_strategy;
typedef typename strategy::distance::services::return_type
<
comparable_strategy, segment_point, box_point
>::type comparable_return_type;
typedef typename detail::distance::default_strategy
<
segment_point, Box
>::type point_box_strategy;
typedef typename strategy::distance::services::comparable_type
<
point_box_strategy
>::type point_box_comparable_strategy;
typedef distance::strategy_t<box_point, Segment, Strategies> ps_strategy_type;
typedef distance::strategy_t<segment_point, Box, Strategies> pb_strategy_type;
public:
typedef typename strategy::distance::services::return_type
<
Strategy, segment_point, box_point
>::type return_type;
// TODO: Or should the return type be defined by sb_strategy_type?
typedef distance::return_t<box_point, Segment, Strategies> return_type;
static inline return_type apply(Segment const& segment,
Box const& box,
Strategy const& strategy,
Strategies const& strategies,
bool check_intersection = true)
{
if (check_intersection && intersects_segment_box(segment, box))
if (check_intersection && intersects_segment_box(segment, box, strategies))
{
return 0;
return return_type(0);
}
comparable_strategy cstrategy =
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy);
boost::ignore_unused(cstrategy);
// get segment points
segment_point p[2];
detail::assign_point_from_index<0>(segment, p[0]);
@@ -251,15 +211,28 @@ public:
// get box points
std::vector<box_point> box_points(4);
detail::assign_box_corners_oriented<true>(box, box_points);
comparable_return_type cd[6];
distance::creturn_t<box_point, Segment, Strategies> cd[6];
ps_strategy_type ps_strategy = strategies.distance(dummy_point(), dummy_segment());
auto const ps_cstrategy = strategy::distance::services::get_comparable
<
ps_strategy_type
>::apply(ps_strategy);
boost::ignore_unused(ps_strategy, ps_cstrategy);
for (unsigned int i = 0; i < 4; ++i)
{
cd[i] = cstrategy.apply(box_points[i], p[0], p[1]);
cd[i] = ps_cstrategy.apply(box_points[i], p[0], p[1]);
}
point_box_comparable_strategy pb_cstrategy;
boost::ignore_unused(pb_cstrategy);
pb_strategy_type const pb_strategy = strategies.distance(dummy_point(), dummy_box());
auto const pb_cstrategy = strategy::distance::services::get_comparable
<
pb_strategy_type
>::apply(pb_strategy);
boost::ignore_unused(pb_strategy, pb_cstrategy);
cd[4] = pb_cstrategy.apply(p[0], box);
cd[5] = pb_cstrategy.apply(p[1], box);
@@ -272,18 +245,23 @@ public:
}
}
if (is_comparable<Strategy>::value)
{
return cd[imin];
}
if (imin < 4)
{
strategy.apply(box_points[imin], p[0], p[1]);
if (is_comparable<ps_strategy_type>::value)
{
return cd[imin];
}
return ps_strategy.apply(box_points[imin], p[0], p[1]);
}
else
{
return point_box_strategy().apply(p[imin - 4], box);
if (is_comparable<pb_strategy_type>::value)
{
return cd[imin];
}
return pb_strategy.apply(p[imin - 4], box);
}
}
};
@@ -296,7 +274,7 @@ template
typename ReturnType,
typename SegmentPoint,
typename BoxPoint,
typename SBStrategy
typename Strategies
>
class segment_to_box_2D
{
@@ -355,10 +333,8 @@ private:
SegmentPoint const& p1,
BoxPoint const& bottom_right,
BoxPoint const& top_right,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
boost::ignore_unused(sb_strategy);
// the implementation below is written for non-negative slope
// segments
//
@@ -369,8 +345,7 @@ private:
LessEqual less_equal;
typename SBStrategy::distance_ps_strategy::type ps_strategy =
sb_strategy.get_distance_ps_strategy();
auto const ps_strategy = strategies.distance(dummy_point(), dummy_segment());
if (less_equal(geometry::get<1>(bottom_right), geometry::get<1>(p0)))
{
@@ -412,19 +387,19 @@ private:
static inline ReturnType apply(SegmentPoint const& p0,
SegmentPoint const& p1,
BoxPoint const& top_left,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
boost::ignore_unused(sb_strategy);
return apply(p0, p1, p0, top_left, sb_strategy);
return apply(p0, p1, p0, top_left, strategies);
}
static inline ReturnType apply(SegmentPoint const& p0,
SegmentPoint const& p1,
SegmentPoint const& p_max,
BoxPoint const& top_left,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
boost::ignore_unused(sb_strategy);
auto const ps_strategy = strategies.distance(dummy_point(), dummy_segment());
typedef cast_to_result<ReturnType> cast;
LessEqual less_equal;
@@ -432,22 +407,21 @@ private:
// then compute the vertical (i.e. meridian for spherical) distance
if (less_equal(geometry::get<0>(top_left), geometry::get<0>(p_max)))
{
ReturnType diff =
sb_strategy.get_distance_ps_strategy().vertical_or_meridian(
ReturnType diff = ps_strategy.vertical_or_meridian(
geometry::get_as_radian<1>(p_max),
geometry::get_as_radian<1>(top_left));
return strategy::distance::services::result_from_distance
<
SBStrategy, SegmentPoint, BoxPoint
>::apply(sb_strategy, math::abs(diff));
std::remove_const_t<decltype(ps_strategy)>,
SegmentPoint, BoxPoint
>::apply(ps_strategy, math::abs(diff));
}
// p0 is to the left of the box, but p1 is above the box
// in this case the distance is realized between the
// top-left corner of the box and the segment
return cast::apply(sb_strategy.get_distance_ps_strategy().
apply(top_left, p0, p1));
return cast::apply(ps_strategy.apply(top_left, p0, p1));
}
};
@@ -460,7 +434,7 @@ private:
BoxPoint const& top_right,
BoxPoint const& bottom_left,
BoxPoint const& bottom_right,
SBStrategy const& sb_strategy,
Strategies const& strategies,
ReturnType& result)
{
// p0 lies to the right of the box
@@ -470,7 +444,7 @@ private:
<
LessEqual
>::apply(p0, p1, bottom_right, top_right,
sb_strategy);
strategies);
return true;
}
@@ -481,7 +455,7 @@ private:
<
typename other_compare<LessEqual>::type
>::apply(p1, p0, top_left, bottom_left,
sb_strategy);
strategies);
return true;
}
@@ -498,7 +472,7 @@ private:
BoxPoint const& top_right,
BoxPoint const& bottom_left,
BoxPoint const& bottom_right,
SBStrategy const& sb_strategy,
Strategies const& strategies,
ReturnType& result)
{
typedef compare_less_equal<ReturnType, false> GreaterEqual;
@@ -506,13 +480,20 @@ private:
// the segment lies below the box
if (geometry::get<1>(p1) < geometry::get<1>(bottom_left))
{
auto const sb_strategy = strategies.distance(dummy_segment(), dummy_box());
// TODO: this strategy calls this algorithm's again, specifically:
// geometry::detail::distance::segment_to_box_2D<>::call_above_of_box
// If possible rewrite them to avoid this.
// For now just pass umbrella strategy.
result = sb_strategy.template segment_below_of_box
<
LessEqual,
ReturnType
>(p0, p1,
top_left, top_right,
bottom_left, bottom_right);
bottom_left, bottom_right,
strategies);
return true;
}
@@ -522,11 +503,11 @@ private:
result = (std::min)(above_of_box
<
LessEqual
>::apply(p0, p1, top_left, sb_strategy),
>::apply(p0, p1, top_left, strategies),
above_of_box
<
GreaterEqual
>::apply(p1, p0, top_right, sb_strategy));
>::apply(p1, p0, top_right, strategies));
return true;
}
return false;
@@ -539,28 +520,23 @@ private:
SegmentPoint const& p1,
BoxPoint const& corner1,
BoxPoint const& corner2,
SBStrategy const& sb_strategy,
Strategies const& strategies,
ReturnType& result)
{
typedef typename geometry::strategy::side::services::default_strategy
<
typename geometry::cs_tag<SegmentPoint>::type
>::type side;
auto const side_strategy = strategies.side();
auto const ps_strategy = strategies.distance(dummy_point(), dummy_segment());
typedef cast_to_result<ReturnType> cast;
ReturnType diff1 = cast::apply(geometry::get<1>(p1))
- cast::apply(geometry::get<1>(p0));
typename SBStrategy::distance_ps_strategy::type ps_strategy =
sb_strategy.get_distance_ps_strategy();
int sign = diff1 < 0 ? -1 : 1;
if (side::apply(p0, p1, corner1) * sign < 0)
if (side_strategy.apply(p0, p1, corner1) * sign < 0)
{
result = cast::apply(ps_strategy.apply(corner1, p0, p1));
return true;
}
if (side::apply(p0, p1, corner2) * sign > 0)
if (side_strategy.apply(p0, p1, corner2) * sign > 0)
{
result = cast::apply(ps_strategy.apply(corner2, p0, p1));
return true;
@@ -576,7 +552,7 @@ private:
BoxPoint const& top_right,
BoxPoint const& bottom_left,
BoxPoint const& bottom_right,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
typedef compare_less_equal<ReturnType, true> less_equal;
@@ -596,7 +572,7 @@ private:
less_equal
>::apply(p0, p1,
top_left, top_right, bottom_left, bottom_right,
sb_strategy, result))
strategies, result))
{
return result;
}
@@ -606,14 +582,14 @@ private:
less_equal
>::apply(p0, p1,
top_left, top_right, bottom_left, bottom_right,
sb_strategy, result))
strategies, result))
{
return result;
}
if (check_generic_position::apply(p0, p1,
top_left, bottom_right,
sb_strategy, result))
strategies, result))
{
return result;
}
@@ -630,7 +606,7 @@ private:
BoxPoint const& top_right,
BoxPoint const& bottom_left,
BoxPoint const& bottom_right,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
typedef compare_less_equal<ReturnType, false> greater_equal;
@@ -647,7 +623,7 @@ private:
greater_equal
>::apply(p0, p1,
bottom_left, bottom_right, top_left, top_right,
sb_strategy, result))
strategies, result))
{
return result;
}
@@ -657,14 +633,14 @@ private:
greater_equal
>::apply(p1, p0,
top_right, top_left, bottom_right, bottom_left,
sb_strategy, result))
strategies, result))
{
return result;
}
if (check_generic_position::apply(p0, p1,
bottom_left, top_right,
sb_strategy, result))
strategies, result))
{
return result;
}
@@ -680,9 +656,9 @@ public:
BoxPoint const& top_right,
BoxPoint const& bottom_left,
BoxPoint const& bottom_right,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
BOOST_GEOMETRY_ASSERT( geometry::less<SegmentPoint>()(p0, p1)
BOOST_GEOMETRY_ASSERT( (geometry::less<SegmentPoint, -1, Strategies>()(p0, p1))
|| geometry::has_nan_coordinate(p0)
|| geometry::has_nan_coordinate(p1) );
@@ -692,13 +668,13 @@ public:
return negative_slope_segment(p0, p1,
top_left, top_right,
bottom_left, bottom_right,
sb_strategy);
strategies);
}
return non_negative_slope_segment(p0, p1,
top_left, top_right,
bottom_left, bottom_right,
sb_strategy);
strategies);
}
template <typename LessEqual>
@@ -706,18 +682,18 @@ public:
SegmentPoint const& p1,
SegmentPoint const& p_max,
BoxPoint const& top_left,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
return above_of_box<LessEqual>::apply(p0, p1, p_max, top_left, sb_strategy);
return above_of_box<LessEqual>::apply(p0, p1, p_max, top_left, strategies);
}
template <typename LessEqual>
static inline ReturnType call_above_of_box(SegmentPoint const& p0,
SegmentPoint const& p1,
BoxPoint const& top_left,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
return above_of_box<LessEqual>::apply(p0, p1, top_left, sb_strategy);
return above_of_box<LessEqual>::apply(p0, p1, top_left, strategies);
}
};
@@ -728,7 +704,7 @@ template
typename Segment,
typename Box,
typename std::size_t Dimension,
typename SBStrategy
typename Strategies
>
class segment_to_box
: not_implemented<Segment, Box>
@@ -739,87 +715,56 @@ template
<
typename Segment,
typename Box,
typename SBStrategy
typename Strategies
>
class segment_to_box<Segment, Box, 2, SBStrategy>
class segment_to_box<Segment, Box, 2, Strategies>
{
private:
typedef typename point_type<Segment>::type segment_point;
typedef typename point_type<Box>::type box_point;
typedef distance::strategy_t<Segment, Box, Strategies> strategy_type;
typedef typename strategy::distance::services::comparable_type
<
SBStrategy
>::type ps_comparable_strategy;
typedef typename strategy::distance::services::return_type
<
ps_comparable_strategy, segment_point, box_point
>::type comparable_return_type;
public:
typedef typename strategy::distance::services::return_type
<
SBStrategy, segment_point, box_point
>::type return_type;
typedef distance::return_t<Segment, Box, Strategies> return_type;
static inline return_type apply(Segment const& segment,
Box const& box,
SBStrategy const& sb_strategy)
Strategies const& strategies)
{
typedef typename point_type<Segment>::type segment_point;
typedef typename point_type<Box>::type box_point;
segment_point p[2];
detail::assign_point_from_index<0>(segment, p[0]);
detail::assign_point_from_index<1>(segment, p[1]);
if (detail::equals::equals_point_point(p[0], p[1],
sb_strategy.get_equals_point_point_strategy()))
if (detail::equals::equals_point_point(p[0], p[1], strategies))
{
typedef typename boost::mpl::if_
<
boost::is_same
<
ps_comparable_strategy,
SBStrategy
>,
typename strategy::distance::services::comparable_type
<
typename detail::distance::default_strategy
<
segment_point, Box
>::type
>::type,
typename detail::distance::default_strategy
<
segment_point, Box
>::type
>::type point_box_strategy_type;
return dispatch::distance
<
segment_point,
Box,
point_box_strategy_type
>::apply(p[0], box, point_box_strategy_type());
Strategies
>::apply(p[0], box, strategies);
}
box_point top_left, top_right, bottom_left, bottom_right;
detail::assign_box_corners(box, bottom_left, bottom_right,
top_left, top_right);
SBStrategy::mirror(p[0], p[1],
bottom_left, bottom_right,
top_left, top_right);
strategy_type::mirror(p[0], p[1],
bottom_left, bottom_right,
top_left, top_right);
if (geometry::less<segment_point>()(p[0], p[1]))
typedef geometry::less<segment_point, -1, Strategies> less_type;
if (less_type()(p[0], p[1]))
{
return segment_to_box_2D
<
return_type,
segment_point,
box_point,
SBStrategy
Strategies
>::apply(p[0], p[1],
top_left, top_right, bottom_left, bottom_right,
sb_strategy);
strategies);
}
else
{
@@ -828,10 +773,10 @@ public:
return_type,
segment_point,
box_point,
SBStrategy
Strategies
>::apply(p[1], p[0],
top_left, top_right, bottom_left, bottom_right,
sb_strategy);
strategies);
}
}
};
@@ -846,24 +791,15 @@ namespace dispatch
{
template <typename Segment, typename Box, typename Strategy>
template <typename Segment, typename Box, typename Strategies>
struct distance
<
Segment, Box, Strategy, segment_tag, box_tag,
Segment, Box, Strategies, segment_tag, box_tag,
strategy_tag_distance_segment_box, false
>
{
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Segment>::type,
typename point_type<Box>::type
>::type return_type;
static inline return_type apply(Segment const& segment,
Box const& box,
Strategy const& strategy)
static inline auto apply(Segment const& segment, Box const& box,
Strategies const& strategies)
{
assert_dimension_equal<Segment, Box>();
@@ -872,8 +808,8 @@ struct distance
Segment,
Box,
dimension<Segment>::value,
Strategy
>::apply(segment, box, strategy);
Strategies
>::apply(segment, box, strategies);
}
};

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, 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
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -15,20 +16,19 @@
#include <boost/core/addressof.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
#include <boost/geometry/algorithms/dispatch/distance.hpp>
#include <boost/geometry/util/condition.hpp>
namespace boost { namespace geometry
@@ -42,35 +42,18 @@ namespace detail { namespace distance
// compute segment-segment distance
template<typename Segment1, typename Segment2, typename Strategy>
template<typename Segment1, typename Segment2, typename Strategies>
class segment_to_segment
{
private:
typedef typename strategy::distance::services::comparable_type
<
Strategy
>::type comparable_strategy;
typedef typename strategy::distance::services::return_type
<
comparable_strategy,
typename point_type<Segment1>::type,
typename point_type<Segment2>::type
>::type comparable_return_type;
typedef distance::strategy_t<Segment1, Segment2, Strategies> strategy_type;
public:
typedef typename strategy::distance::services::return_type
<
Strategy,
typename point_type<Segment1>::type,
typename point_type<Segment2>::type
>::type return_type;
typedef distance::return_t<Segment1, Segment2, Strategies> return_type;
static inline return_type
apply(Segment1 const& segment1, Segment2 const& segment2,
Strategy const& strategy)
static inline return_type apply(Segment1 const& segment1, Segment2 const& segment2,
Strategies const& strategies)
{
if (geometry::intersects(segment1, segment2))
if (geometry::intersects(segment1, segment2, strategies))
{
return 0;
}
@@ -83,13 +66,14 @@ public:
detail::assign_point_from_index<0>(segment2, q[0]);
detail::assign_point_from_index<1>(segment2, q[1]);
comparable_strategy cstrategy =
strategy::distance::services::get_comparable
<
Strategy
>::apply(strategy);
strategy_type const strategy = strategies.distance(segment1, segment2);
comparable_return_type d[4];
auto const cstrategy = strategy::distance::services::get_comparable
<
strategy_type
>::apply(strategy);
distance::creturn_t<Segment1, Segment2, Strategies> d[4];
d[0] = cstrategy.apply(q[0], p[0], p[1]);
d[1] = cstrategy.apply(q[1], p[0], p[1]);
d[2] = cstrategy.apply(p[0], q[0], q[1]);
@@ -98,7 +82,7 @@ public:
std::size_t imin = std::distance(boost::addressof(d[0]),
std::min_element(d, d + 4));
if (BOOST_GEOMETRY_CONDITION(is_comparable<Strategy>::value))
if (BOOST_GEOMETRY_CONDITION(is_comparable<strategy_type>::value))
{
return d[imin];
}

View File

@@ -0,0 +1,64 @@
// Boost.Geometry
// Copyright (c) 2021, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_GEOMETRY_ALGORITHS_DETAIL_DISTANCE_STRATEGY_UTILS_HPP
#define BOOST_GEOMETRY_ALGORITHS_DETAIL_DISTANCE_STRATEGY_UTILS_HPP
#include <utility>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/strategies/distance.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace distance
{
template <typename Geometry1, typename Geometry2, typename Strategies>
using strategy_t = decltype(
std::declval<Strategies>().distance(std::declval<Geometry1>(), std::declval<Geometry2>()));
template <typename Geometry1, typename Geometry2, typename Strategies>
using return_t = typename strategy::distance::services::return_type
<
strategy_t<Geometry1, Geometry2, Strategies>,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type;
template <typename Geometry1, typename Geometry2, typename Strategies>
using cstrategy_t = typename strategy::distance::services::comparable_type
<
strategy_t<Geometry1, Geometry2, Strategies>
>::type;
template <typename Geometry1, typename Geometry2, typename Strategies>
using creturn_t = typename strategy::distance::services::return_type
<
cstrategy_t<Geometry1, Geometry2, Strategies>,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type;
}} // namespace detail::distance
#endif // DOXYGEN_NO_DETAIL
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHS_DETAIL_DISTANCE_STRATEGY_UTILS_HPP