[setops] Support strategies in intersection, difference, sym_difference and union_.

This commit is contained in:
Adam Wulkiewicz
2017-02-17 05:00:57 +01:00
parent e95d85c552
commit 6f7beaf01a
4 changed files with 953 additions and 129 deletions

View File

@@ -15,12 +15,14 @@
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
// TODO: those headers probably may be removed
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/util/range.hpp>
namespace boost { namespace geometry
@@ -98,33 +100,46 @@ struct intersection
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
namespace resolve_variant
{
template <typename Geometry1, typename Geometry2>
namespace resolve_strategy {
struct intersection
{
template <typename GeometryOut>
static inline bool
apply(
const Geometry1& geometry1,
const Geometry2& geometry2,
GeometryOut& geometry_out)
template
<
typename Geometry1,
typename Geometry2,
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)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
typedef typename geometry::rescale_overlay_policy_type
return dispatch::intersection
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1,
geometry2);
>::apply(geometry1, geometry2, robust_policy, geometry_out,
strategy);
}
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename GeometryOut
>
static inline bool apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
GeometryOut & geometry_out,
default_strategy)
{
typedef typename strategy::relate::services::default_strategy
<
Geometry1, Geometry2
@@ -139,44 +154,83 @@ struct intersection
}
};
} // resolve_strategy
namespace resolve_variant
{
template <typename Geometry1, typename Geometry2>
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>();
typedef typename geometry::rescale_overlay_policy_type
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1,
geometry2);
return resolve_strategy::intersection::apply(geometry1,
geometry2,
robust_policy,
geometry_out,
strategy);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
{
template <typename GeometryOut>
template <typename GeometryOut, typename Strategy>
struct visitor: static_visitor<bool>
{
Geometry2 const& m_geometry2;
GeometryOut& m_geometry_out;
Strategy const& m_strategy;
visitor(Geometry2 const& geometry2,
GeometryOut& geometry_out)
GeometryOut& geometry_out,
Strategy const& strategy)
: m_geometry2(geometry2)
, m_geometry_out(geometry_out)
, m_strategy(strategy)
{}
template <typename Geometry1>
result_type operator()(Geometry1 const& geometry1) const
bool operator()(Geometry1 const& geometry1) const
{
return intersection
<
Geometry1,
Geometry2
>::template apply
<
GeometryOut
>
(geometry1, m_geometry2, m_geometry_out);
<
Geometry1,
Geometry2
>::apply(geometry1, m_geometry2, m_geometry_out, m_strategy);
}
};
template <typename GeometryOut>
template <typename GeometryOut, typename Strategy>
static inline bool
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out)
GeometryOut& geometry_out,
Strategy const& strategy)
{
return boost::apply_visitor(visitor<GeometryOut>(geometry2, geometry_out), geometry1);
return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry2,
geometry_out,
strategy),
geometry1);
}
};
@@ -184,40 +238,43 @@ struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename GeometryOut>
template <typename GeometryOut, typename Strategy>
struct visitor: static_visitor<bool>
{
Geometry1 const& m_geometry1;
GeometryOut& m_geometry_out;
Strategy const& m_strategy;
visitor(Geometry1 const& geometry1,
GeometryOut& geometry_out)
GeometryOut& geometry_out,
Strategy const& strategy)
: m_geometry1(geometry1)
, m_geometry_out(geometry_out)
, m_strategy(strategy)
{}
template <typename Geometry2>
result_type operator()(Geometry2 const& geometry2) const
bool operator()(Geometry2 const& geometry2) const
{
return intersection
<
Geometry1,
Geometry2
>::template apply
<
GeometryOut
>
(m_geometry1, geometry2, m_geometry_out);
<
Geometry1,
Geometry2
>::apply(m_geometry1, geometry2, m_geometry_out, m_strategy);
}
};
template <typename GeometryOut>
template <typename GeometryOut, typename Strategy>
static inline bool
apply(Geometry1 const& geometry1,
const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry2,
GeometryOut& geometry_out)
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
return boost::apply_visitor(visitor<GeometryOut>(geometry1, geometry_out), geometry2);
return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry1,
geometry_out,
strategy),
geometry2);
}
};
@@ -225,44 +282,82 @@ struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
{
template <typename GeometryOut>
template <typename GeometryOut, typename Strategy>
struct visitor: static_visitor<bool>
{
GeometryOut& m_geometry_out;
Strategy const& m_strategy;
visitor(GeometryOut& geometry_out)
visitor(GeometryOut& geometry_out, Strategy const& strategy)
: m_geometry_out(geometry_out)
, m_strategy(strategy)
{}
template <typename Geometry1, typename Geometry2>
result_type operator()(Geometry1 const& geometry1,
Geometry2 const& geometry2) const
bool operator()(Geometry1 const& geometry1,
Geometry2 const& geometry2) const
{
return intersection
<
Geometry1,
Geometry2
>::template apply
<
GeometryOut
>
(geometry1, geometry2, m_geometry_out);
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, m_geometry_out, m_strategy);
}
};
template <typename GeometryOut>
template <typename GeometryOut, typename Strategy>
static inline bool
apply(const variant<BOOST_VARIANT_ENUM_PARAMS(T1)>& geometry1,
const variant<BOOST_VARIANT_ENUM_PARAMS(T2)>& geometry2,
GeometryOut& geometry_out)
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
GeometryOut& geometry_out,
Strategy const& strategy)
{
return boost::apply_visitor(visitor<GeometryOut>(geometry_out), geometry1, geometry2);
return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry_out,
strategy),
geometry1, geometry2);
}
};
} // namespace resolve_variant
/*!
\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{[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_variant::intersection
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, geometry_out, strategy);
}
/*!
\brief \brief_calc2{intersection}
\ingroup intersection
@@ -285,18 +380,14 @@ template
typename GeometryOut
>
inline bool intersection(Geometry1 const& geometry1,
Geometry2 const& geometry2,
GeometryOut& geometry_out)
Geometry2 const& geometry2,
GeometryOut& geometry_out)
{
return resolve_variant::intersection
<
Geometry1,
Geometry2
>::template apply
<
GeometryOut
>
(geometry1, geometry2, geometry_out);
Geometry1,
Geometry2
>::apply(geometry1, geometry2, geometry_out, default_strategy());
}

View File

@@ -4,6 +4,7 @@
// This file was modified by Oracle on 2017.
// Modifications copyright (c) 2017, 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,
@@ -13,10 +14,16 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_DIFFERENCE_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DIFFERENCE_HPP
#include <algorithm>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/util/range.hpp>
namespace boost { namespace geometry
{
@@ -101,18 +108,14 @@ inline OutputIterator difference_insert(Geometry1 const& geometry1,
RobustPolicy const& robust_policy,
OutputIterator out)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
concepts::check<GeometryOut>();
typename strategy::relate::services::default_strategy
typedef typename strategy::relate::services::default_strategy
<
Geometry1,
Geometry2
>::type strategy;
>::type strategy_type;
return difference_insert<GeometryOut>(geometry1, geometry2,
robust_policy, out, strategy);
robust_policy, out, strategy_type());
}
@@ -120,6 +123,250 @@ inline OutputIterator difference_insert(Geometry1 const& geometry1,
#endif // DOXYGEN_NO_DETAIL
namespace resolve_strategy {
struct difference
{
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename Collection,
typename Strategy
>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
Collection & output_collection,
Strategy const& strategy)
{
typedef typename boost::range_value<Collection>::type geometry_out;
detail::difference::difference_insert<geometry_out>(
geometry1, geometry2, robust_policy,
range::back_inserter(output_collection),
strategy);
}
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename Collection
>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
Collection & output_collection,
default_strategy)
{
typedef typename boost::range_value<Collection>::type geometry_out;
detail::difference::difference_insert<geometry_out>(
geometry1, geometry2, robust_policy,
range::back_inserter(output_collection));
}
};
} // resolve_strategy
namespace resolve_variant
{
template <typename Geometry1, typename Geometry2>
struct difference
{
template <typename Collection, typename Strategy>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
typedef typename geometry::rescale_overlay_policy_type
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1,
geometry2);
resolve_strategy::difference::apply(geometry1, geometry2,
robust_policy,
output_collection,
strategy);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
struct difference<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Geometry2 const& m_geometry2;
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
: m_geometry2(geometry2)
, m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry1>
void operator()(Geometry1 const& geometry1) const
{
difference
<
Geometry1,
Geometry2
>::apply(geometry1, m_geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(geometry2,
output_collection,
strategy),
geometry1);
}
};
template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct difference<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Geometry1 const& m_geometry1;
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Geometry1 const& geometry1,
Collection& output_collection,
Strategy const& strategy)
: m_geometry1(geometry1)
, m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry2>
void operator()(Geometry2 const& geometry2) const
{
difference
<
Geometry1,
Geometry2
>::apply(m_geometry1, geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(Geometry1 const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(geometry1,
output_collection,
strategy),
geometry2);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
struct difference<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Collection& output_collection, Strategy const& strategy)
: m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry1, typename Geometry2>
void operator()(Geometry1 const& geometry1,
Geometry2 const& geometry2) const
{
difference
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(output_collection,
strategy),
geometry1, geometry2);
}
};
} // namespace resolve_variant
/*!
\brief_calc2{difference}
\ingroup difference
\details \details_calc2{difference, spatial set theoretic difference}.
\tparam Geometry1 \tparam_geometry
\tparam Geometry2 \tparam_geometry
\tparam Collection \tparam_output_collection
\tparam Strategy \tparam_strategy{Difference}
\param geometry1 \param_geometry
\param geometry2 \param_geometry
\param output_collection the output collection
\param strategy \param_strategy{difference}
\qbk{[include reference/algorithms/difference.qbk]}
*/
template
<
typename Geometry1,
typename Geometry2,
typename Collection,
typename Strategy
>
inline void difference(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
resolve_variant::difference
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, output_collection, strategy);
}
/*!
\brief_calc2{difference}
@@ -144,25 +391,11 @@ inline void difference(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
typedef typename boost::range_value<Collection>::type geometry_out;
concepts::check<geometry_out>();
typedef typename geometry::rescale_overlay_policy_type
resolve_variant::difference
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1,
geometry2);
detail::difference::difference_insert<geometry_out>(
geometry1, geometry2, robust_policy,
range::back_inserter(output_collection));
>::apply(geometry1, geometry2, output_collection, default_strategy());
}

View File

@@ -15,13 +15,21 @@
#ifndef BOOST_GEOMETRY_ALGORITHMS_SYM_DIFFERENCE_HPP
#define BOOST_GEOMETRY_ALGORITHMS_SYM_DIFFERENCE_HPP
#include <algorithm>
#include <iterator>
#include <vector>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/union.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/util/range.hpp>
namespace boost { namespace geometry
@@ -289,6 +297,252 @@ inline OutputIterator sym_difference_insert(Geometry1 const& geometry1,
#endif // DOXYGEN_NO_DETAIL
namespace resolve_strategy {
struct sym_difference
{
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename Collection,
typename Strategy
>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
Collection & output_collection,
Strategy const& strategy)
{
typedef typename boost::range_value<Collection>::type geometry_out;
detail::sym_difference::sym_difference_insert<geometry_out>(
geometry1, geometry2, robust_policy,
range::back_inserter(output_collection),
strategy);
}
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename Collection
>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
Collection & output_collection,
default_strategy)
{
typedef typename boost::range_value<Collection>::type geometry_out;
detail::sym_difference::sym_difference_insert<geometry_out>(
geometry1, geometry2, robust_policy,
range::back_inserter(output_collection));
}
};
} // resolve_strategy
namespace resolve_variant
{
template <typename Geometry1, typename Geometry2>
struct sym_difference
{
template <typename Collection, typename Strategy>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
typedef typename geometry::rescale_overlay_policy_type
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1,
geometry2);
resolve_strategy::sym_difference::apply(geometry1, geometry2,
robust_policy,
output_collection,
strategy);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
struct sym_difference<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Geometry2 const& m_geometry2;
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
: m_geometry2(geometry2)
, m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry1>
void operator()(Geometry1 const& geometry1) const
{
sym_difference
<
Geometry1,
Geometry2
>::apply(geometry1, m_geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(geometry2,
output_collection,
strategy),
geometry1);
}
};
template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct sym_difference<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Geometry1 const& m_geometry1;
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Geometry1 const& geometry1,
Collection& output_collection,
Strategy const& strategy)
: m_geometry1(geometry1)
, m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry2>
void operator()(Geometry2 const& geometry2) const
{
sym_difference
<
Geometry1,
Geometry2
>::apply(m_geometry1, geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(Geometry1 const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(geometry1,
output_collection,
strategy),
geometry2);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
struct sym_difference<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Collection& output_collection, Strategy const& strategy)
: m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry1, typename Geometry2>
void operator()(Geometry1 const& geometry1,
Geometry2 const& geometry2) const
{
sym_difference
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(output_collection,
strategy),
geometry1, geometry2);
}
};
} // namespace resolve_variant
/*!
\brief \brief_calc2{symmetric difference}
\ingroup sym_difference
\details \details_calc2{symmetric difference, spatial set theoretic symmetric difference (XOR)}.
\tparam Geometry1 \tparam_geometry
\tparam Geometry2 \tparam_geometry
\tparam Collection output collection, either a multi-geometry,
or a std::vector<Geometry> / std::deque<Geometry> etc
\tparam Strategy \tparam_strategy{Sym_difference}
\param geometry1 \param_geometry
\param geometry2 \param_geometry
\param output_collection the output collection
\param strategy \param_strategy{sym_difference}
\qbk{[include reference/algorithms/sym_difference.qbk]}
*/
template
<
typename Geometry1,
typename Geometry2,
typename Collection,
typename Strategy
>
inline void sym_difference(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
resolve_variant::sym_difference
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, output_collection, strategy);
}
/*!
\brief \brief_calc2{symmetric difference}
\ingroup sym_difference
@@ -310,26 +564,14 @@ template
typename Collection
>
inline void sym_difference(Geometry1 const& geometry1,
Geometry2 const& geometry2, Collection& output_collection)
Geometry2 const& geometry2,
Collection& output_collection)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
typedef typename boost::range_value<Collection>::type geometry_out;
concepts::check<geometry_out>();
typedef typename geometry::rescale_overlay_policy_type
resolve_variant::sym_difference
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1, geometry2);
detail::sym_difference::sym_difference_insert<geometry_out>(
geometry1, geometry2, robust_policy,
range::back_inserter(output_collection));
>::apply(geometry1, geometry2, output_collection, default_strategy());
}

View File

@@ -25,6 +25,8 @@
#include <boost/geometry/algorithms/not_implemented.hpp>
#include <boost/geometry/algorithms/detail/overlay/overlay.hpp>
#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/util/range.hpp>
#include <boost/geometry/algorithms/detail/overlay/linear_linear.hpp>
#include <boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp>
@@ -234,6 +236,265 @@ inline OutputIterator union_insert(Geometry1 const& geometry1,
#endif // DOXYGEN_NO_DETAIL
namespace resolve_strategy {
struct union_
{
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename Collection,
typename Strategy
>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
Collection & output_collection,
Strategy const& strategy)
{
typedef typename boost::range_value<Collection>::type geometry_out;
dispatch::union_insert
<
Geometry1, Geometry2, geometry_out
>::apply(geometry1, geometry2, robust_policy,
range::back_inserter(output_collection),
strategy);
}
template
<
typename Geometry1,
typename Geometry2,
typename RobustPolicy,
typename Collection
>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
RobustPolicy const& robust_policy,
Collection & output_collection,
default_strategy)
{
typedef typename boost::range_value<Collection>::type geometry_out;
typedef typename strategy::intersection::services::default_strategy
<
typename cs_tag<geometry_out>::type
>::type strategy_type;
dispatch::union_insert
<
Geometry1, Geometry2, geometry_out
>::apply(geometry1, geometry2, robust_policy,
range::back_inserter(output_collection),
strategy_type());
}
};
} // resolve_strategy
namespace resolve_variant
{
template <typename Geometry1, typename Geometry2>
struct union_
{
template <typename Collection, typename Strategy>
static inline void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
concepts::check<typename boost::range_value<Collection>::type>();
typedef typename geometry::rescale_overlay_policy_type
<
Geometry1,
Geometry2
>::type rescale_policy_type;
rescale_policy_type robust_policy
= geometry::get_rescale_policy<rescale_policy_type>(geometry1,
geometry2);
resolve_strategy::union_::apply(geometry1, geometry2,
robust_policy,
output_collection,
strategy);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
struct union_<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Geometry2 const& m_geometry2;
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
: m_geometry2(geometry2)
, m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry1>
void operator()(Geometry1 const& geometry1) const
{
union_
<
Geometry1,
Geometry2
>::apply(geometry1, m_geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(geometry2,
output_collection,
strategy),
geometry1);
}
};
template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct union_<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Geometry1 const& m_geometry1;
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Geometry1 const& geometry1,
Collection& output_collection,
Strategy const& strategy)
: m_geometry1(geometry1)
, m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry2>
void operator()(Geometry2 const& geometry2) const
{
union_
<
Geometry1,
Geometry2
>::apply(m_geometry1, geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(Geometry1 const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(geometry1,
output_collection,
strategy),
geometry2);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
struct union_<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
{
template <typename Collection, typename Strategy>
struct visitor: static_visitor<>
{
Collection& m_output_collection;
Strategy const& m_strategy;
visitor(Collection& output_collection, Strategy const& strategy)
: m_output_collection(output_collection)
, m_strategy(strategy)
{}
template <typename Geometry1, typename Geometry2>
void operator()(Geometry1 const& geometry1,
Geometry2 const& geometry2) const
{
union_
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, m_output_collection, m_strategy);
}
};
template <typename Collection, typename Strategy>
static inline void
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
boost::apply_visitor(visitor<Collection, Strategy>(output_collection,
strategy),
geometry1, geometry2);
}
};
} // namespace resolve_variant
/*!
\brief Combines two geometries which each other
\ingroup union
\details \details_calc2{union, spatial set theoretic union}.
\tparam Geometry1 \tparam_geometry
\tparam Geometry2 \tparam_geometry
\tparam Collection output collection, either a multi-geometry,
or a std::vector<Geometry> / std::deque<Geometry> etc
\tparam Strategy \tparam_strategy{Union_}
\param geometry1 \param_geometry
\param geometry2 \param_geometry
\param output_collection the output collection
\param strategy \param_strategy{union_}
\note Called union_ because union is a reserved word.
\qbk{[include reference/algorithms/union.qbk]}
*/
template
<
typename Geometry1,
typename Geometry2,
typename Collection,
typename Strategy
>
inline void union_(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection,
Strategy const& strategy)
{
resolve_variant::union_
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, output_collection, strategy);
}
/*!
@@ -258,17 +519,14 @@ template
typename Collection
>
inline void union_(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Collection& output_collection)
Geometry2 const& geometry2,
Collection& output_collection)
{
concepts::check<Geometry1 const>();
concepts::check<Geometry2 const>();
typedef typename boost::range_value<Collection>::type geometry_out;
concepts::check<geometry_out>();
detail::union_::union_insert<geometry_out>(geometry1, geometry2,
range::back_inserter(output_collection));
resolve_variant::union_
<
Geometry1,
Geometry2
>::apply(geometry1, geometry2, output_collection, default_strategy());
}