mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-10 23:42:12 +00:00
[intersection] Add variant support
This commit is contained in:
@@ -167,6 +167,175 @@ struct intersection
|
||||
} // namespace dispatch
|
||||
#endif // DOXYGEN_NO_DISPATCH
|
||||
|
||||
|
||||
namespace resolve_variant
|
||||
{
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
struct intersection
|
||||
{
|
||||
template <typename GeometryOut>
|
||||
static inline bool
|
||||
apply(
|
||||
const Geometry1& geometry1,
|
||||
const Geometry2& geometry2,
|
||||
GeometryOut& geometry_out)
|
||||
{
|
||||
concept::check<Geometry1 const>();
|
||||
concept::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);
|
||||
|
||||
typedef strategy_intersection
|
||||
<
|
||||
typename cs_tag<Geometry1>::type,
|
||||
Geometry1,
|
||||
Geometry2,
|
||||
typename geometry::point_type<Geometry1>::type,
|
||||
rescale_policy_type
|
||||
> strategy;
|
||||
|
||||
return dispatch::intersection
|
||||
<
|
||||
Geometry1,
|
||||
Geometry2
|
||||
>::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>
|
||||
struct visitor: static_visitor<bool>
|
||||
{
|
||||
Geometry2 const& m_geometry2;
|
||||
GeometryOut& m_geometry_out;
|
||||
|
||||
visitor(Geometry2 const& geometry2,
|
||||
GeometryOut& geometry_out)
|
||||
: m_geometry2(geometry2),
|
||||
m_geometry_out(geometry_out)
|
||||
{}
|
||||
|
||||
template <typename Geometry1>
|
||||
result_type operator()(Geometry1 const& geometry1) const
|
||||
{
|
||||
return intersection
|
||||
<
|
||||
Geometry1,
|
||||
Geometry2
|
||||
>::template apply
|
||||
<
|
||||
GeometryOut
|
||||
>
|
||||
(geometry1, m_geometry2, m_geometry_out);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename GeometryOut>
|
||||
static inline bool
|
||||
apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
|
||||
Geometry2 const& geometry2,
|
||||
GeometryOut& geometry_out)
|
||||
{
|
||||
return apply_visitor(visitor<GeometryOut>(geometry2, geometry_out), geometry1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
||||
struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
||||
{
|
||||
template <typename GeometryOut>
|
||||
struct visitor: static_visitor<bool>
|
||||
{
|
||||
Geometry1 const& m_geometry1;
|
||||
GeometryOut& m_geometry_out;
|
||||
|
||||
visitor(Geometry1 const& geometry1,
|
||||
GeometryOut& geometry_out)
|
||||
: m_geometry1(geometry1),
|
||||
m_geometry_out(geometry_out)
|
||||
{}
|
||||
|
||||
template <typename Geometry2>
|
||||
result_type operator()(Geometry2 const& geometry2) const
|
||||
{
|
||||
return intersection
|
||||
<
|
||||
Geometry1,
|
||||
Geometry2
|
||||
>::template apply
|
||||
<
|
||||
GeometryOut
|
||||
>
|
||||
(m_geometry1, geometry2, m_geometry_out);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename GeometryOut>
|
||||
static inline bool
|
||||
apply(
|
||||
Geometry1 const& geometry1,
|
||||
const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry2,
|
||||
GeometryOut& geometry_out)
|
||||
{
|
||||
return apply_visitor(visitor<GeometryOut>(geometry1, geometry_out), geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
||||
struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
||||
{
|
||||
template <typename GeometryOut>
|
||||
struct visitor: static_visitor<bool>
|
||||
{
|
||||
GeometryOut& m_geometry_out;
|
||||
|
||||
visitor(GeometryOut& geometry_out)
|
||||
: m_geometry_out(geometry_out)
|
||||
{}
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
result_type operator()(
|
||||
Geometry1 const& geometry1,
|
||||
Geometry2 const& geometry2) const
|
||||
{
|
||||
return intersection
|
||||
<
|
||||
Geometry1,
|
||||
Geometry2
|
||||
>::template apply
|
||||
<
|
||||
GeometryOut
|
||||
>
|
||||
(geometry1, geometry2, m_geometry_out);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename GeometryOut>
|
||||
static inline void
|
||||
apply(
|
||||
const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry1,
|
||||
const variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry2,
|
||||
GeometryOut& geometry_out)
|
||||
{
|
||||
return apply_visitor(visitor<GeometryOut>(geometry_out), geometry1, geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace resolve_variant
|
||||
|
||||
|
||||
/*!
|
||||
\brief \brief_calc2{intersection}
|
||||
@@ -196,29 +365,15 @@ inline bool intersection(Geometry1 const& geometry1,
|
||||
concept::check<Geometry1 const>();
|
||||
concept::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);
|
||||
|
||||
typedef strategy_intersection
|
||||
<
|
||||
typename cs_tag<Geometry1>::type,
|
||||
Geometry1,
|
||||
Geometry2,
|
||||
typename geometry::point_type<Geometry1>::type,
|
||||
rescale_policy_type
|
||||
> strategy;
|
||||
|
||||
return dispatch::intersection
|
||||
return resolve_variant::intersection
|
||||
<
|
||||
Geometry1,
|
||||
Geometry2
|
||||
>::apply(geometry1, geometry2, robust_policy, geometry_out, strategy());
|
||||
>::template apply
|
||||
<
|
||||
GeometryOut
|
||||
>
|
||||
(geometry1, geometry2, geometry_out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user