mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-21 03:02:10 +00:00
[expand] Add variant support
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
#include <boost/geometry/strategies/compare.hpp>
|
||||
#include <boost/geometry/policies/compare.hpp>
|
||||
|
||||
#include <boost/variant/static_visitor.hpp>
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
@@ -249,6 +252,49 @@ struct expand<Box, Segment, StrategyLess, StrategyGreater, box_tag, segment_tag>
|
||||
#endif // DOXYGEN_NO_DISPATCH
|
||||
|
||||
|
||||
namespace resolve_variant {
|
||||
|
||||
template <typename Geometry>
|
||||
struct expand
|
||||
{
|
||||
template <typename Box>
|
||||
static inline void apply(Box& box, Geometry const& geometry)
|
||||
{
|
||||
concept::check_concepts_and_equal_dimensions<Box, Geometry const>();
|
||||
|
||||
dispatch::expand<Box, Geometry>::apply(box, geometry);
|
||||
}
|
||||
};
|
||||
|
||||
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
||||
struct expand<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
||||
{
|
||||
template <typename Box>
|
||||
struct visitor: boost::static_visitor<void>
|
||||
{
|
||||
Box& m_box;
|
||||
|
||||
visitor(Box& box) : m_box(box) {}
|
||||
|
||||
template <typename Geometry>
|
||||
void operator()(Geometry const& geometry) const
|
||||
{
|
||||
return expand<Geometry>::apply(m_box, geometry);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Box>
|
||||
static inline void
|
||||
apply(Box& box,
|
||||
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
|
||||
{
|
||||
return boost::apply_visitor(visitor<Box>(box), geometry);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace resolve_variant
|
||||
|
||||
|
||||
/***
|
||||
*!
|
||||
\brief Expands a box using the extend (envelope) of another geometry (box, point)
|
||||
@@ -292,7 +338,7 @@ inline void expand(Box& box, Geometry const& geometry)
|
||||
{
|
||||
concept::check_concepts_and_equal_dimensions<Box, Geometry const>();
|
||||
|
||||
dispatch::expand<Box, Geometry>::apply(box, geometry);
|
||||
resolve_variant::expand<Geometry>::apply(box, geometry);
|
||||
}
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <boost/geometry/geometries/adapted/c_array.hpp>
|
||||
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
|
||||
#include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp>
|
||||
#include <boost/variant/variant.hpp>
|
||||
#include <test_common/test_point.hpp>
|
||||
|
||||
BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
|
||||
|
||||
Reference in New Issue
Block a user