Added thirdparty: boost library

This commit is contained in:
Viacheslav Demydiuk
2024-01-06 19:55:56 +02:00
parent bf49f439e1
commit bccd1e7051
15683 changed files with 3239840 additions and 0 deletions
@@ -0,0 +1,341 @@
// Boost.Geometry
// Copyright (c) 2020-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_INTERSECTION_AREAL_AREAL_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_AREAL_AREAL_HPP
#include <boost/core/ignore_unused.hpp>
#include <boost/geometry/algorithms/detail/intersection/interface.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace intersection
{
template
<
typename GeometryOut,
typename OutTag = typename geometry::detail::setop_insert_output_tag
<
typename geometry::detail::output_geometry_value
<
GeometryOut
>::type
>::type
>
struct intersection_areal_areal_
{
template
<
typename Areal1,
typename Areal2,
typename RobustPolicy,
typename Strategy
>
static inline void apply(Areal1 const& areal1,
Areal2 const& areal2,
RobustPolicy const& robust_policy,
GeometryOut& geometry_out,
Strategy const& strategy)
{
geometry::dispatch::intersection_insert
<
Areal1, Areal2,
typename boost::range_value<GeometryOut>::type,
overlay_intersection
>::apply(areal1, areal2, robust_policy,
geometry::range::back_inserter(geometry_out),
strategy);
}
};
// TODO: Ideally this should be done in one call of intersection_insert
// just like it's done for all other combinations
template <typename TupledOut>
struct intersection_areal_areal_<TupledOut, tupled_output_tag>
{
template
<
typename Areal1,
typename Areal2,
typename RobustPolicy,
typename Strategy
>
static inline void apply(Areal1 const& areal1,
Areal2 const& areal2,
RobustPolicy const& robust_policy,
TupledOut& geometry_out,
Strategy const& strategy)
{
typedef typename geometry::detail::output_geometry_value
<
TupledOut
>::type single_out;
boost::ignore_unused
<
geometry::detail::expect_output
<
Areal1, Areal2, single_out,
point_tag, linestring_tag, polygon_tag
>
>();
typedef geometry::detail::output_geometry_access
<
single_out, polygon_tag, polygon_tag
> areal;
typedef geometry::detail::output_geometry_access
<
single_out, linestring_tag, linestring_tag
> linear;
typedef geometry::detail::output_geometry_access
<
single_out, point_tag, point_tag
> pointlike;
typedef typename geometry::tuples::element
<
areal::index, TupledOut
>::type areal_out_type;
// NOTE: The same robust_policy is used in each call of
// intersection_insert. Is that correct?
// A * A -> A
call_intersection(areal1, areal2, robust_policy,
areal::get(geometry_out),
strategy);
bool const is_areal_empty = boost::empty(areal::get(geometry_out));
TupledOut temp_out;
// L * L -> (L, P)
call_intersection(geometry::detail::boundary_view<Areal1 const>(areal1),
geometry::detail::boundary_view<Areal2 const>(areal2),
robust_policy,
! is_areal_empty
? temp_out
: geometry_out,
strategy);
if (! is_areal_empty)
{
// NOTE: the original areal geometry could be used instead of boundary here
// however this results in static assert failure related to rescale policy
typedef geometry::detail::boundary_view
<
areal_out_type const
> areal_out_boundary_type;
areal_out_boundary_type areal_out_boundary(areal::get(geometry_out));
// L - L -> L
call_difference(linear::get(temp_out),
areal_out_boundary,
robust_policy,
linear::get(geometry_out),
strategy);
// P - L -> P
call_difference(pointlike::get(temp_out),
areal_out_boundary,
robust_policy,
pointlike::get(geometry_out),
strategy);
}
return;
}
private:
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename GeometryOut,
typename Strategy
>
static inline void call_intersection(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
GeometryOut& geometry_out,
Strategy const& strategy)
{
geometry::dispatch::intersection_insert
<
Geometry1,
Geometry2,
typename geometry::detail::output_geometry_value
<
GeometryOut
>::type,
overlay_intersection
>::apply(geometry1,
geometry2,
robust_policy,
geometry::detail::output_geometry_back_inserter(geometry_out),
strategy);
}
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename GeometryOut,
typename Strategy
>
static inline void call_difference(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
GeometryOut& geometry_out,
Strategy const& strategy)
{
geometry::dispatch::intersection_insert
<
Geometry1,
Geometry2,
typename boost::range_value<GeometryOut>::type,
overlay_difference
>::apply(geometry1,
geometry2,
robust_policy,
geometry::range::back_inserter(geometry_out),
strategy);
}
};
struct intersection_areal_areal
{
template
<
typename Areal1,
typename Areal2,
typename RobustPolicy,
typename GeometryOut,
typename Strategy
>
static inline bool apply(Areal1 const& areal1,
Areal2 const& areal2,
RobustPolicy const& robust_policy,
GeometryOut& geometry_out,
Strategy const& strategy)
{
intersection_areal_areal_
<
GeometryOut
>::apply(areal1, areal2, robust_policy, geometry_out, strategy);
return true;
}
};
}} // namespace detail::intersection
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template
<
typename Polygon1, typename Polygon2
>
struct intersection
<
Polygon1, Polygon2,
polygon_tag, polygon_tag,
false
>
: detail::intersection::intersection_areal_areal
{};
template
<
typename Polygon, typename Ring
>
struct intersection
<
Polygon, Ring,
polygon_tag, ring_tag,
false
>
: detail::intersection::intersection_areal_areal
{};
template
<
typename Ring1, typename Ring2
>
struct intersection
<
Ring1, Ring2,
ring_tag, ring_tag,
false
>
: detail::intersection::intersection_areal_areal
{};
template
<
typename Polygon, typename MultiPolygon
>
struct intersection
<
Polygon, MultiPolygon,
polygon_tag, multi_polygon_tag,
false
>
: detail::intersection::intersection_areal_areal
{};
template
<
typename MultiPolygon, typename Ring
>
struct intersection
<
MultiPolygon, Ring,
multi_polygon_tag, ring_tag,
false
>
: detail::intersection::intersection_areal_areal
{};
template
<
typename MultiPolygon1, typename MultiPolygon2
>
struct intersection
<
MultiPolygon1, MultiPolygon2,
multi_polygon_tag, multi_polygon_tag,
false
>
: detail::intersection::intersection_areal_areal
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_AREAL_AREAL_HPP
@@ -0,0 +1,54 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2014.
// Modifications copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// 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_INTERSECTION_BOX_BOX_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_BOX_BOX_HPP
#include <boost/geometry/algorithms/detail/intersection/interface.hpp>
#include <boost/geometry/algorithms/detail/intersection/box_box_implementation.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template
<
typename Box1, typename Box2, bool Reverse
>
struct intersection
<
Box1, Box2,
box_tag, box_tag,
Reverse
> : public detail::intersection::intersection_box_box
<
0, geometry::dimension<Box1>::value
>
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_BOX_BOX_HPP
@@ -0,0 +1,93 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2015.
// Modifications copyright (c) 2015, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// 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_INTERSECTION_BOX_BOX_IMPLEMENTATION_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_BOX_BOX_IMPLEMENTATION_HPP
#include <boost/geometry/core/access.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace intersection
{
template <std::size_t Dimension, std::size_t DimensionCount>
struct intersection_box_box
{
template
<
typename Box1, typename Box2,
typename RobustPolicy,
typename BoxOut,
typename Strategy
>
static inline bool apply(Box1 const& box1,
Box2 const& box2,
RobustPolicy const& robust_policy,
BoxOut& box_out,
Strategy const& strategy)
{
auto max1 = get<max_corner, Dimension>(box1);
auto min2 = get<min_corner, Dimension>(box2);
if (max1 < min2)
{
return false;
}
auto max2 = get<max_corner, Dimension>(box2);
auto min1 = get<min_corner, Dimension>(box1);
if (max2 < min1)
{
return false;
}
// Set dimensions of output coordinate
set<min_corner, Dimension>(box_out, min1 < min2 ? min2 : min1);
set<max_corner, Dimension>(box_out, max1 > max2 ? max2 : max1);
return intersection_box_box<Dimension + 1, DimensionCount>
::apply(box1, box2, robust_policy, box_out, strategy);
}
};
template <std::size_t DimensionCount>
struct intersection_box_box<DimensionCount, DimensionCount>
{
template
<
typename Box1, typename Box2,
typename RobustPolicy,
typename BoxOut,
typename Strategy
>
static inline bool apply(Box1 const&, Box2 const&,
RobustPolicy const&, BoxOut&, Strategy const&)
{
return true;
}
};
}} // namespace detail::intersection
#endif // DOXYGEN_NO_DETAIL
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_BOX_BOX_IMPLEMENTATION_HPP
+331
View File
@@ -0,0 +1,331 @@
// Boost.Geometry
// Copyright (c) 2022, 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_INTERSECTION_GC_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_GC_HPP
#include <tuple>
#include <boost/range/size.hpp>
#include <boost/geometry/algorithms/detail/gc_make_rtree.hpp>
#include <boost/geometry/algorithms/detail/intersection/interface.hpp>
#include <boost/geometry/views/detail/geometry_collection_view.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace intersection
{
template <typename GC, typename Multi>
struct gc_can_move_element
{
template <typename G>
using is_same_as_single = std::is_same<G, typename boost::range_value<Multi>::type>;
using gc_types = typename traits::geometry_types<GC>::type;
using found_type = typename util::sequence_find_if<gc_types, is_same_as_single>::type;
static const bool value = ! std::is_void<found_type>::value;
};
template <typename GC, typename Multi>
struct gc_can_convert_element
{
template <typename G>
using has_same_tag_as_single = std::is_same
<
typename geometry::tag<G>::type,
typename geometry::tag<typename boost::range_value<Multi>::type>::type
>;
using gc_types = typename traits::geometry_types<GC>::type;
using found_type = typename util::sequence_find_if<gc_types, has_same_tag_as_single>::type;
static const bool value = ! std::is_void<found_type>::value;
};
template
<
typename GC, typename Multi,
std::enable_if_t<gc_can_move_element<GC, Multi>::value, int> = 0
>
inline void gc_move_one_elem_multi_back(GC& gc, Multi&& multi)
{
range::emplace_back(gc, std::move(*boost::begin(multi)));
}
template
<
typename GC, typename Multi,
std::enable_if_t<! gc_can_move_element<GC, Multi>::value && gc_can_convert_element<GC, Multi>::value, int> = 0
>
inline void gc_move_one_elem_multi_back(GC& gc, Multi&& multi)
{
typename gc_can_convert_element<GC, Multi>::found_type single_out;
geometry::convert(*boost::begin(multi), single_out);
range::emplace_back(gc, std::move(single_out));
}
template
<
typename GC, typename Multi,
std::enable_if_t<! gc_can_move_element<GC, Multi>::value && ! gc_can_convert_element<GC, Multi>::value, int> = 0
>
inline void gc_move_one_elem_multi_back(GC& gc, Multi&& multi)
{
range::emplace_back(gc, std::move(multi));
}
template <typename GC, typename Multi>
inline void gc_move_multi_back(GC& gc, Multi&& multi)
{
if (! boost::empty(multi))
{
if (boost::size(multi) == 1)
{
gc_move_one_elem_multi_back(gc, std::move(multi));
}
else
{
range::emplace_back(gc, std::move(multi));
}
}
}
}} // namespace detail::intersection
#endif // DOXYGEN_NO_DETAIL
namespace resolve_collection
{
template
<
typename Geometry1, typename Geometry2, typename GeometryOut
>
struct intersection
<
Geometry1, Geometry2, GeometryOut,
geometry_collection_tag, geometry_collection_tag, geometry_collection_tag
>
{
// NOTE: for now require all of the possible output types
// technically only a subset could be needed.
using multi_point_t = typename util::sequence_find_if
<
typename traits::geometry_types<GeometryOut>::type,
util::is_multi_point
>::type;
using multi_linestring_t = typename util::sequence_find_if
<
typename traits::geometry_types<GeometryOut>::type,
util::is_multi_linestring
>::type;
using multi_polygon_t = typename util::sequence_find_if
<
typename traits::geometry_types<GeometryOut>::type,
util::is_multi_polygon
>::type;
using tuple_out_t = boost::tuple<multi_point_t, multi_linestring_t, multi_polygon_t>;
template <typename Strategy>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
bool result = false;
tuple_out_t out;
auto const rtree2 = detail::gc_make_rtree_iterators(geometry2, strategy);
detail::visit_breadth_first([&](auto const& g1)
{
bool r = g1_prod_gc2(g1, rtree2, out, strategy);
result = result || r;
return true;
}, geometry1);
detail::intersection::gc_move_multi_back(geometry_out, boost::get<0>(out));
detail::intersection::gc_move_multi_back(geometry_out, boost::get<1>(out));
detail::intersection::gc_move_multi_back(geometry_out, boost::get<2>(out));
return result;
}
private:
// Implemented as separate function because msvc is unable to do nested lambda capture
template <typename G1, typename Rtree2, typename TupleOut, typename Strategy>
static bool g1_prod_gc2(G1 const& g1, Rtree2 const& rtree2, TupleOut& out, Strategy const& strategy)
{
bool result = false;
using box1_t = detail::gc_make_rtree_box_t<G1>;
box1_t b1 = geometry::return_envelope<box1_t>(g1, strategy);
detail::expand_by_epsilon(b1);
for (auto qit = rtree2.qbegin(index::intersects(b1)); qit != rtree2.qend(); ++qit)
{
traits::iter_visit<Geometry2>::apply([&](auto const& g2)
{
TupleOut inters_result;
using g2_t = util::remove_cref_t<decltype(g2)>;
intersection<G1, g2_t, TupleOut>::apply(g1, g2, inters_result, strategy);
// TODO: If possible merge based on adjacency lists, i.e. merge
// only the intersections of elements that intersect each other
// as subgroups. So the result could contain merged intersections
// of several groups, not only one.
// TODO: It'd probably be better to gather all of the parts first
// and then merge them with merge_elements.
// NOTE: template explicitly called because gcc-6 doesn't compile it
// otherwise.
bool const r0 = intersection::template merge_result<0>(inters_result, out, strategy);
bool const r1 = intersection::template merge_result<1>(inters_result, out, strategy);
bool const r2 = intersection::template merge_result<2>(inters_result, out, strategy);
result = result || r0 || r1 || r2;
}, qit->second);
}
return result;
}
template <std::size_t Index, typename Out, typename Strategy>
static bool merge_result(Out const& inters_result, Out& out, Strategy const& strategy)
{
auto const& multi_result = boost::get<Index>(inters_result);
auto& multi_out = boost::get<Index>(out);
if (! boost::empty(multi_result))
{
std::remove_reference_t<decltype(multi_out)> temp_result;
merge_two(multi_out, multi_result, temp_result, strategy);
multi_out = std::move(temp_result);
return true;
}
return false;
}
template <typename Out, typename Strategy, std::enable_if_t<! util::is_pointlike<Out>::value, int> = 0>
static void merge_two(Out const& g1, Out const& g2, Out& out, Strategy const& strategy)
{
using rescale_policy_type = typename geometry::rescale_overlay_policy_type
<
Out, Out, typename Strategy::cs_tag
>::type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(
g1, g2, strategy);
geometry::dispatch::intersection_insert
<
Out, Out, typename boost::range_value<Out>::type,
overlay_union
>::apply(g1,
g2,
robust_policy,
geometry::range::back_inserter(out),
strategy);
}
template <typename Out, typename Strategy, std::enable_if_t<util::is_pointlike<Out>::value, int> = 0>
static void merge_two(Out const& g1, Out const& g2, Out& out, Strategy const& strategy)
{
detail::overlay::union_pointlike_pointlike_point
<
Out, Out, typename boost::range_value<Out>::type
>::apply(g1,
g2,
0, // dummy robust policy
geometry::range::back_inserter(out),
strategy);
}
};
template
<
typename Geometry1, typename Geometry2, typename GeometryOut, typename Tag1
>
struct intersection
<
Geometry1, Geometry2, GeometryOut,
Tag1, geometry_collection_tag, geometry_collection_tag
>
{
template <typename Strategy>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
using gc_view_t = geometry::detail::geometry_collection_view<Geometry1>;
return intersection
<
gc_view_t, Geometry2, GeometryOut
>::apply(gc_view_t(geometry1), geometry2, geometry_out, strategy);
}
};
template
<
typename Geometry1, typename Geometry2, typename GeometryOut, typename Tag2
>
struct intersection
<
Geometry1, Geometry2, GeometryOut,
geometry_collection_tag, Tag2, geometry_collection_tag
>
{
template <typename Strategy>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
using gc_view_t = geometry::detail::geometry_collection_view<Geometry2>;
return intersection
<
Geometry1, gc_view_t, GeometryOut
>::apply(geometry1, gc_view_t(geometry2), geometry_out, strategy);
}
};
template
<
typename Geometry1, typename Geometry2, typename GeometryOut, typename Tag1, typename Tag2
>
struct intersection
<
Geometry1, Geometry2, GeometryOut,
Tag1, Tag2, geometry_collection_tag
>
{
template <typename Strategy>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
using gc1_view_t = geometry::detail::geometry_collection_view<Geometry1>;
using gc2_view_t = geometry::detail::geometry_collection_view<Geometry2>;
return intersection
<
gc1_view_t, gc2_view_t, GeometryOut
>::apply(gc1_view_t(geometry1), gc2_view_t(geometry2), geometry_out, strategy);
}
};
} // namespace resolve_collection
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_GC_HPP
@@ -0,0 +1,28 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2014-2022.
// Modifications copyright (c) 2014-2022, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// 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_INTERSECTION_IMPLEMENTATION_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_IMPLEMENTATION_HPP
#include <boost/geometry/algorithms/detail/intersection/areal_areal.hpp>
#include <boost/geometry/algorithms/detail/intersection/box_box.hpp>
#include <boost/geometry/algorithms/detail/intersection/gc.hpp>
#include <boost/geometry/algorithms/detail/intersection/multi.hpp>
#include <boost/geometry/strategies/relate/cartesian.hpp>
#include <boost/geometry/strategies/relate/geographic.hpp>
#include <boost/geometry/strategies/relate/spherical.hpp>
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_IMPLEMENTATION_HPP
@@ -0,0 +1,391 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2014-2022.
// Modifications copyright (c) 2014-2022, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// 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_INTERSECTION_INTERFACE_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
#include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
#include <boost/geometry/algorithms/detail/tupled_output.hpp>
#include <boost/geometry/geometries/adapted/boost_variant.hpp>
#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/strategies/detail.hpp>
#include <boost/geometry/strategies/relate/services.hpp>
#include <boost/geometry/util/range.hpp>
#include <boost/geometry/util/type_traits_std.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
// By default, all is forwarded to the intersection_insert-dispatcher
template
<
typename Geometry1, typename Geometry2,
typename Tag1 = typename geometry::tag<Geometry1>::type,
typename Tag2 = typename geometry::tag<Geometry2>::type,
bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
>
struct intersection
{
template <typename RobustPolicy, typename GeometryOut, typename Strategy>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
GeometryOut& geometry_out,
Strategy const& strategy)
{
typedef typename geometry::detail::output_geometry_value
<
GeometryOut
>::type SingleOut;
intersection_insert
<
Geometry1, Geometry2, SingleOut,
overlay_intersection
>::apply(geometry1, geometry2, robust_policy,
geometry::detail::output_geometry_back_inserter(geometry_out),
strategy);
return true;
}
};
// If reversal is needed, perform it
template
<
typename Geometry1, typename Geometry2,
typename Tag1, typename Tag2
>
struct intersection
<
Geometry1, Geometry2,
Tag1, Tag2,
true
>
: intersection<Geometry2, Geometry1, Tag2, Tag1, false>
{
template <typename RobustPolicy, typename GeometryOut, typename Strategy>
static inline bool apply(
Geometry1 const& g1,
Geometry2 const& g2,
RobustPolicy const& robust_policy,
GeometryOut& out,
Strategy const& strategy)
{
return intersection
<
Geometry2, Geometry1,
Tag2, Tag1,
false
>::apply(g2, g1, robust_policy, out, strategy);
}
};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
namespace resolve_collection
{
template
<
typename Geometry1, typename Geometry2, typename GeometryOut,
typename Tag1 = typename geometry::tag<Geometry1>::type,
typename Tag2 = typename geometry::tag<Geometry2>::type,
typename TagOut = typename geometry::tag<GeometryOut>::type
>
struct intersection
{
template <typename Strategy>
static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
GeometryOut & geometry_out, Strategy const& strategy)
{
typedef typename geometry::rescale_overlay_policy_type
<
Geometry1,
Geometry2,
typename Strategy::cs_tag
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(
geometry1, geometry2, strategy);
return dispatch::intersection
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, robust_policy, geometry_out,
strategy);
}
};
} // namespace resolve_collection
namespace resolve_strategy {
template
<
typename Strategy,
bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
>
struct intersection
{
template
<
typename Geometry1,
typename Geometry2,
typename GeometryOut
>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut & geometry_out,
Strategy const& strategy)
{
return resolve_collection::intersection
<
Geometry1, Geometry2, GeometryOut
>::apply(geometry1, geometry2, geometry_out, strategy);
}
};
template <typename Strategy>
struct intersection<Strategy, false>
{
template
<
typename Geometry1,
typename Geometry2,
typename GeometryOut
>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut & geometry_out,
Strategy const& strategy)
{
using strategies::relate::services::strategy_converter;
return intersection
<
decltype(strategy_converter<Strategy>::get(strategy))
>::apply(geometry1, geometry2, geometry_out,
strategy_converter<Strategy>::get(strategy));
}
};
template <>
struct intersection<default_strategy, false>
{
template
<
typename Geometry1,
typename Geometry2,
typename GeometryOut
>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut & geometry_out,
default_strategy)
{
typedef typename strategies::relate::services::default_strategy
<
Geometry1, Geometry2
>::type strategy_type;
return intersection
<
strategy_type
>::apply(geometry1, geometry2, geometry_out, strategy_type());
}
};
} // resolve_strategy
namespace resolve_dynamic
{
template
<
typename Geometry1, typename Geometry2,
typename Tag1 = typename geometry::tag<Geometry1>::type,
typename Tag2 = typename geometry::tag<Geometry2>::type
>
struct intersection
{
template <typename GeometryOut, typename Strategy>
static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
GeometryOut& geometry_out, Strategy const& strategy)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
return resolve_strategy::intersection
<
Strategy
>::apply(geometry1, geometry2, geometry_out, strategy);
}
};
template <typename DynamicGeometry1, typename Geometry2, typename Tag2>
struct intersection<DynamicGeometry1, Geometry2, dynamic_geometry_tag, Tag2>
{
template <typename GeometryOut, typename Strategy>
static inline bool apply(DynamicGeometry1 const& geometry1, Geometry2 const& geometry2,
GeometryOut& geometry_out, Strategy const& strategy)
{
bool result = false;
traits::visit<DynamicGeometry1>::apply([&](auto const& g1)
{
result = intersection
<
util::remove_cref_t<decltype(g1)>,
Geometry2
>::apply(g1, geometry2, geometry_out, strategy);
}, geometry1);
return result;
}
};
template <typename Geometry1, typename DynamicGeometry2, typename Tag1>
struct intersection<Geometry1, DynamicGeometry2, Tag1, dynamic_geometry_tag>
{
template <typename GeometryOut, typename Strategy>
static inline bool apply(Geometry1 const& geometry1, DynamicGeometry2 const& geometry2,
GeometryOut& geometry_out, Strategy const& strategy)
{
bool result = false;
traits::visit<DynamicGeometry2>::apply([&](auto const& g2)
{
result = intersection
<
Geometry1,
util::remove_cref_t<decltype(g2)>
>::apply(geometry1, g2, geometry_out, strategy);
}, geometry2);
return result;
}
};
template <typename DynamicGeometry1, typename DynamicGeometry2>
struct intersection<DynamicGeometry1, DynamicGeometry2, dynamic_geometry_tag, dynamic_geometry_tag>
{
template <typename GeometryOut, typename Strategy>
static inline bool apply(DynamicGeometry1 const& geometry1, DynamicGeometry2 const& geometry2,
GeometryOut& geometry_out, Strategy const& strategy)
{
bool result = false;
traits::visit<DynamicGeometry1, DynamicGeometry2>::apply([&](auto const& g1, auto const& g2)
{
result = intersection
<
util::remove_cref_t<decltype(g1)>,
util::remove_cref_t<decltype(g2)>
>::apply(g1, g2, geometry_out, strategy);
}, geometry1, geometry2);
return result;
}
};
} // namespace resolve_dynamic
/*!
\brief \brief_calc2{intersection}
\ingroup intersection
\details \details_calc2{intersection, spatial set theoretic intersection}.
\tparam Geometry1 \tparam_geometry
\tparam Geometry2 \tparam_geometry
\tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
\tparam Strategy \tparam_strategy{Intersection}
\param geometry1 \param_geometry
\param geometry2 \param_geometry
\param geometry_out The output geometry, either a multi_point, multi_polygon,
multi_linestring, or a box (for intersection of two boxes)
\param strategy \param_strategy{intersection}
\qbk{distinguish,with strategy}
\qbk{[include reference/algorithms/intersection.qbk]}
*/
template
<
typename Geometry1,
typename Geometry2,
typename GeometryOut,
typename Strategy
>
inline bool intersection(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
return resolve_dynamic::intersection
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, geometry_out, strategy);
}
/*!
\brief \brief_calc2{intersection}
\ingroup intersection
\details \details_calc2{intersection, spatial set theoretic intersection}.
\tparam Geometry1 \tparam_geometry
\tparam Geometry2 \tparam_geometry
\tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
\param geometry1 \param_geometry
\param geometry2 \param_geometry
\param geometry_out The output geometry, either a multi_point, multi_polygon,
multi_linestring, or a box (for intersection of two boxes)
\qbk{[include reference/algorithms/intersection.qbk]}
*/
template
<
typename Geometry1,
typename Geometry2,
typename GeometryOut
>
inline bool intersection(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out)
{
return resolve_dynamic::intersection
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, geometry_out, default_strategy());
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
@@ -0,0 +1,596 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2014-2022.
// Modifications copyright (c) 2014-2022, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// 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_INTERSECTION_MULTI_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_MULTI_HPP
#include <type_traits>
#include <boost/geometry/core/closure.hpp>
#include <boost/geometry/core/geometry_id.hpp>
#include <boost/geometry/core/point_order.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/algorithms/detail/covered_by/implementation.hpp>
// TODO: those headers probably may be removed
#include <boost/geometry/algorithms/detail/overlay/get_ring.hpp>
#include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
#include <boost/geometry/algorithms/detail/overlay/copy_segments.hpp>
#include <boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp>
#include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
#include <boost/geometry/algorithms/detail/sections/range_by_section.hpp>
#include <boost/geometry/algorithms/detail/sections/sectionalize.hpp>
#include <boost/geometry/algorithms/detail/intersection/interface.hpp>
#include <boost/geometry/algorithms/envelope.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace intersection
{
template <typename PointOut>
struct intersection_multi_linestring_multi_linestring_point
{
template
<
typename MultiLinestring1, typename MultiLinestring2,
typename RobustPolicy,
typename OutputIterator, typename Strategy
>
static inline OutputIterator apply(MultiLinestring1 const& ml1,
MultiLinestring2 const& ml2,
RobustPolicy const& robust_policy,
OutputIterator out,
Strategy const& strategy)
{
// Note, this loop is quadratic w.r.t. number of linestrings per input.
// Future Enhancement: first do the sections of each, then intersect.
for (auto it1 = boost::begin(ml1); it1 != boost::end(ml1); ++it1)
{
for (auto it2 = boost::begin(ml2); it2 != boost::end(ml2); ++it2)
{
out = intersection_linestring_linestring_point<PointOut>
::apply(*it1, *it2, robust_policy, out, strategy);
}
}
return out;
}
};
template <typename PointOut>
struct intersection_linestring_multi_linestring_point
{
template
<
typename Linestring, typename MultiLinestring,
typename RobustPolicy,
typename OutputIterator, typename Strategy
>
static inline OutputIterator apply(Linestring const& linestring,
MultiLinestring const& ml,
RobustPolicy const& robust_policy,
OutputIterator out,
Strategy const& strategy)
{
for (auto it = boost::begin(ml); it != boost::end(ml); ++it)
{
out = intersection_linestring_linestring_point<PointOut>
::apply(linestring, *it, robust_policy, out, strategy);
}
return out;
}
};
// This loop is quite similar to the loop above, but beacuse the iterator
// is second (above) or first (below) argument, it is not trivial to merge them.
template
<
bool ReverseAreal,
typename LineStringOut,
overlay_type OverlayType,
bool FollowIsolatedPoints
>
struct intersection_of_multi_linestring_with_areal
{
template
<
typename MultiLinestring, typename Areal,
typename RobustPolicy,
typename OutputIterator, typename Strategy
>
static inline OutputIterator apply(MultiLinestring const& ml, Areal const& areal,
RobustPolicy const& robust_policy,
OutputIterator out,
Strategy const& strategy)
{
for (auto it = boost::begin(ml); it != boost::end(ml); ++it)
{
out = intersection_of_linestring_with_areal
<
ReverseAreal, LineStringOut, OverlayType, FollowIsolatedPoints
>::apply(*it, areal, robust_policy, out, strategy);
}
return out;
}
};
// This one calls the one above with reversed arguments
template
<
bool ReverseAreal,
typename LineStringOut,
overlay_type OverlayType,
bool FollowIsolatedPoints
>
struct intersection_of_areal_with_multi_linestring
{
template
<
typename Areal, typename MultiLinestring,
typename RobustPolicy,
typename OutputIterator, typename Strategy
>
static inline OutputIterator apply(Areal const& areal, MultiLinestring const& ml,
RobustPolicy const& robust_policy,
OutputIterator out,
Strategy const& strategy)
{
return intersection_of_multi_linestring_with_areal
<
ReverseAreal, LineStringOut, OverlayType, FollowIsolatedPoints
>::apply(ml, areal, robust_policy, out, strategy);
}
};
template <typename LinestringOut>
struct clip_multi_linestring
{
template
<
typename MultiLinestring, typename Box,
typename RobustPolicy,
typename OutputIterator, typename Strategy
>
static inline OutputIterator apply(MultiLinestring const& multi_linestring,
Box const& box,
RobustPolicy const& robust_policy,
OutputIterator out, Strategy const& )
{
typedef typename point_type<LinestringOut>::type point_type;
strategy::intersection::liang_barsky<Box, point_type> lb_strategy;
for (auto it = boost::begin(multi_linestring); it != boost::end(multi_linestring); ++it)
{
out = detail::intersection::clip_range_with_box
<LinestringOut>(box, *it, robust_policy, out, lb_strategy);
}
return out;
}
};
}} // namespace detail::intersection
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
// Linear
template
<
typename MultiLinestring1, typename MultiLinestring2,
typename GeometryOut,
overlay_type OverlayType,
bool Reverse1, bool Reverse2
>
struct intersection_insert
<
MultiLinestring1, MultiLinestring2,
GeometryOut,
OverlayType,
Reverse1, Reverse2,
multi_linestring_tag, multi_linestring_tag, point_tag,
linear_tag, linear_tag, pointlike_tag
> : detail::intersection::intersection_multi_linestring_multi_linestring_point
<
GeometryOut
>
{};
template
<
typename Linestring, typename MultiLinestring,
typename GeometryOut,
overlay_type OverlayType,
bool Reverse1, bool Reverse2
>
struct intersection_insert
<
Linestring, MultiLinestring,
GeometryOut,
OverlayType,
Reverse1, Reverse2,
linestring_tag, multi_linestring_tag, point_tag,
linear_tag, linear_tag, pointlike_tag
> : detail::intersection::intersection_linestring_multi_linestring_point
<
GeometryOut
>
{};
template
<
typename MultiLinestring, typename Box,
typename GeometryOut,
overlay_type OverlayType,
bool Reverse1, bool Reverse2
>
struct intersection_insert
<
MultiLinestring, Box,
GeometryOut,
OverlayType,
Reverse1, Reverse2,
multi_linestring_tag, box_tag, linestring_tag,
linear_tag, areal_tag, linear_tag
> : detail::intersection::clip_multi_linestring
<
GeometryOut
>
{};
template
<
typename Linestring, typename MultiPolygon,
typename GeometryOut,
overlay_type OverlayType,
bool ReverseLinestring, bool ReverseMultiPolygon
>
struct intersection_insert
<
Linestring, MultiPolygon,
GeometryOut,
OverlayType,
ReverseLinestring, ReverseMultiPolygon,
linestring_tag, multi_polygon_tag, linestring_tag,
linear_tag, areal_tag, linear_tag
> : detail::intersection::intersection_of_linestring_with_areal
<
ReverseMultiPolygon,
GeometryOut,
OverlayType,
false
>
{};
// Derives from areal/mls because runtime arguments are in that order.
// areal/mls reverses it itself to mls/areal
template
<
typename Polygon, typename MultiLinestring,
typename GeometryOut,
overlay_type OverlayType,
bool ReversePolygon, bool ReverseMultiLinestring
>
struct intersection_insert
<
Polygon, MultiLinestring,
GeometryOut,
OverlayType,
ReversePolygon, ReverseMultiLinestring,
polygon_tag, multi_linestring_tag, linestring_tag,
areal_tag, linear_tag, linear_tag
> : detail::intersection::intersection_of_areal_with_multi_linestring
<
ReversePolygon,
GeometryOut,
OverlayType,
false
>
{};
template
<
typename MultiLinestring, typename Ring,
typename GeometryOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReverseRing
>
struct intersection_insert
<
MultiLinestring, Ring,
GeometryOut,
OverlayType,
ReverseMultiLinestring, ReverseRing,
multi_linestring_tag, ring_tag, linestring_tag,
linear_tag, areal_tag, linear_tag
> : detail::intersection::intersection_of_multi_linestring_with_areal
<
ReverseRing,
GeometryOut,
OverlayType,
false
>
{};
template
<
typename MultiLinestring, typename Polygon,
typename GeometryOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReversePolygon
>
struct intersection_insert
<
MultiLinestring, Polygon,
GeometryOut,
OverlayType,
ReverseMultiLinestring, ReversePolygon,
multi_linestring_tag, polygon_tag, linestring_tag,
linear_tag, areal_tag, linear_tag
> : detail::intersection::intersection_of_multi_linestring_with_areal
<
ReversePolygon,
GeometryOut,
OverlayType,
false
>
{};
template
<
typename MultiLinestring, typename MultiPolygon,
typename GeometryOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReverseMultiPolygon
>
struct intersection_insert
<
MultiLinestring, MultiPolygon,
GeometryOut,
OverlayType,
ReverseMultiLinestring, ReverseMultiPolygon,
multi_linestring_tag, multi_polygon_tag, linestring_tag,
linear_tag, areal_tag, linear_tag
> : detail::intersection::intersection_of_multi_linestring_with_areal
<
ReverseMultiPolygon,
GeometryOut,
OverlayType,
false
>
{};
template
<
typename MultiLinestring, typename Ring,
typename TupledOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReverseRing
>
struct intersection_insert
<
MultiLinestring, Ring,
TupledOut,
OverlayType,
ReverseMultiLinestring, ReverseRing,
multi_linestring_tag, ring_tag, detail::tupled_output_tag,
linear_tag, areal_tag, detail::tupled_output_tag
> : detail::intersection::intersection_of_multi_linestring_with_areal
<
ReverseRing,
TupledOut,
OverlayType,
true
>
, detail::expect_output
<
MultiLinestring, Ring, TupledOut,
// NOTE: points can be the result only in case of intersection.
// TODO: union should require L and A
std::conditional_t
<
(OverlayType == overlay_intersection),
point_tag,
void
>,
linestring_tag
>
{};
template
<
typename MultiLinestring, typename Polygon,
typename TupledOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReversePolygon
>
struct intersection_insert
<
MultiLinestring, Polygon,
TupledOut,
OverlayType,
ReverseMultiLinestring, ReversePolygon,
multi_linestring_tag, polygon_tag, detail::tupled_output_tag,
linear_tag, areal_tag, detail::tupled_output_tag
> : detail::intersection::intersection_of_multi_linestring_with_areal
<
ReversePolygon,
TupledOut,
OverlayType,
true
>
, detail::expect_output
<
MultiLinestring, Polygon, TupledOut,
// NOTE: points can be the result only in case of intersection.
// TODO: union should require L and A
std::conditional_t
<
(OverlayType == overlay_intersection),
point_tag,
void
>,
linestring_tag
>
{};
template
<
typename Polygon, typename MultiLinestring,
typename TupledOut,
overlay_type OverlayType,
bool ReversePolygon, bool ReverseMultiLinestring
>
struct intersection_insert
<
Polygon, MultiLinestring,
TupledOut,
OverlayType,
ReversePolygon, ReverseMultiLinestring,
polygon_tag, multi_linestring_tag, detail::tupled_output_tag,
areal_tag, linear_tag, detail::tupled_output_tag
> : detail::intersection::intersection_of_areal_with_multi_linestring
<
ReversePolygon,
TupledOut,
OverlayType,
true
>
, detail::expect_output
<
Polygon, MultiLinestring, TupledOut,
// NOTE: points can be the result only in case of intersection.
// TODO: union should require L and A
// TODO: in general the result of difference should depend on the first argument
// but this specialization calls L/A in reality so the first argument is linear.
// So expect only L for difference?
std::conditional_t
<
(OverlayType == overlay_intersection),
point_tag,
void
>,
linestring_tag
>
{};
template
<
typename Linestring, typename MultiPolygon,
typename TupledOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReverseMultiPolygon
>
struct intersection_insert
<
Linestring, MultiPolygon,
TupledOut,
OverlayType,
ReverseMultiLinestring, ReverseMultiPolygon,
linestring_tag, multi_polygon_tag, detail::tupled_output_tag,
linear_tag, areal_tag, detail::tupled_output_tag
> : detail::intersection::intersection_of_linestring_with_areal
<
ReverseMultiPolygon, TupledOut, OverlayType, true
>
, detail::expect_output
<
Linestring, MultiPolygon, TupledOut,
// NOTE: points can be the result only in case of intersection.
// TODO: union should require L and A
std::conditional_t
<
(OverlayType == overlay_intersection),
point_tag,
void
>,
linestring_tag
>
{};
template
<
typename MultiLinestring, typename MultiPolygon,
typename TupledOut,
overlay_type OverlayType,
bool ReverseMultiLinestring, bool ReverseMultiPolygon
>
struct intersection_insert
<
MultiLinestring, MultiPolygon,
TupledOut,
OverlayType,
ReverseMultiLinestring, ReverseMultiPolygon,
multi_linestring_tag, multi_polygon_tag, detail::tupled_output_tag,
linear_tag, areal_tag, detail::tupled_output_tag
> : detail::intersection::intersection_of_multi_linestring_with_areal
<
ReverseMultiPolygon,
TupledOut,
OverlayType,
true
>
, detail::expect_output
<
MultiLinestring, MultiPolygon, TupledOut,
// NOTE: points can be the result only in case of intersection.
// TODO: union should require L and A
std::conditional_t
<
(OverlayType == overlay_intersection),
point_tag,
void
>,
linestring_tag
>
{};
} // namespace dispatch
#endif
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_MULTI_HPP