mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-12 00:02:09 +00:00
Made touches (2 params version) variant aware.
This commit is contained in:
@@ -28,8 +28,10 @@
|
||||
#include <boost/geometry/algorithms/disjoint.hpp>
|
||||
#include <boost/geometry/algorithms/intersects.hpp>
|
||||
#include <boost/geometry/algorithms/num_geometries.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/sub_geometry.hpp>
|
||||
#include <boost/variant/static_visitor.hpp>
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
#include <boost/variant/variant_fwd.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
@@ -489,6 +491,96 @@ struct touches<Areal1, Areal2, Tag1, Tag2, areal_tag, areal_tag, false>
|
||||
} // namespace dispatch
|
||||
#endif // DOXYGEN_NO_DISPATCH
|
||||
|
||||
|
||||
namespace resolve_variant {
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
struct touches
|
||||
{
|
||||
static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2)
|
||||
{
|
||||
concept::check<Geometry1 const>();
|
||||
concept::check<Geometry2 const>();
|
||||
|
||||
return dispatch::touches<Geometry1, Geometry2>
|
||||
::apply(geometry1, geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
|
||||
struct touches<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
|
||||
{
|
||||
struct visitor: boost::static_visitor<bool>
|
||||
{
|
||||
Geometry2 const& m_geometry2;
|
||||
|
||||
visitor(Geometry2 const& geometry2): m_geometry2(geometry2) {}
|
||||
|
||||
template <typename Geometry1>
|
||||
bool operator()(Geometry1 const& geometry1) const
|
||||
{
|
||||
return touches<Geometry1, Geometry2>::apply(geometry1, m_geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
static inline bool
|
||||
apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
|
||||
Geometry2 const& geometry2)
|
||||
{
|
||||
return boost::apply_visitor(visitor(geometry2), geometry1);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
||||
struct touches<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
||||
{
|
||||
struct visitor: boost::static_visitor<bool>
|
||||
{
|
||||
Geometry1 const& m_geometry1;
|
||||
|
||||
visitor(Geometry1 const& geometry1): m_geometry1(geometry1) {}
|
||||
|
||||
template <typename Geometry2>
|
||||
bool operator()(Geometry2 const& geometry2) const
|
||||
{
|
||||
return touches<Geometry1, Geometry2>::apply(m_geometry1, geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
static inline bool
|
||||
apply(Geometry1 const& geometry1,
|
||||
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2)
|
||||
{
|
||||
return boost::apply_visitor(visitor(geometry1), geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
template <BOOST_VARIANT_ENUM_PARAMS(typename T1),
|
||||
BOOST_VARIANT_ENUM_PARAMS(typename T2)>
|
||||
struct touches<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
|
||||
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
|
||||
{
|
||||
struct visitor: boost::static_visitor<bool>
|
||||
{
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
bool operator()(Geometry1 const& geometry1,
|
||||
Geometry2 const& geometry2) const
|
||||
{
|
||||
return touches<Geometry1, Geometry2>::apply(geometry1, geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
static inline bool
|
||||
apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
|
||||
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2)
|
||||
{
|
||||
return boost::apply_visitor(visitor(), geometry1, geometry2);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace resolve_variant
|
||||
|
||||
|
||||
/*!
|
||||
\brief \brief_check{has at least one touching point (self-tangency)}
|
||||
\note This function can be called for one geometry (self-tangency) and
|
||||
@@ -543,10 +635,7 @@ inline bool touches(Geometry const& geometry)
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
inline bool touches(Geometry1 const& geometry1, Geometry2 const& geometry2)
|
||||
{
|
||||
concept::check<Geometry1 const>();
|
||||
concept::check<Geometry2 const>();
|
||||
|
||||
return dispatch::touches<Geometry1, Geometry2>::apply(geometry1, geometry2);
|
||||
return resolve_variant::touches<Geometry1, Geometry2>::apply(geometry1, geometry2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,16 +35,15 @@
|
||||
|
||||
#include <boost/geometry/multi/io/wkt/read.hpp>
|
||||
|
||||
#include <boost/variant/variant.hpp>
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
void test_touches(std::string const& wkt1,
|
||||
std::string const& wkt2, bool expected)
|
||||
void check_touches(Geometry1 const& geometry1,
|
||||
Geometry2 const& geometry2,
|
||||
std::string const& wkt1,
|
||||
std::string const& wkt2,
|
||||
bool expected)
|
||||
{
|
||||
Geometry1 geometry1;
|
||||
Geometry2 geometry2;
|
||||
|
||||
bg::read_wkt(wkt1, geometry1);
|
||||
bg::read_wkt(wkt2, geometry2);
|
||||
|
||||
bool detected = bg::touches(geometry1, geometry2);
|
||||
|
||||
BOOST_CHECK_MESSAGE(detected == expected,
|
||||
@@ -62,6 +61,25 @@ void test_touches(std::string const& wkt1,
|
||||
<< " detected: " << detected);
|
||||
}
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
void test_touches(std::string const& wkt1,
|
||||
std::string const& wkt2, bool expected)
|
||||
{
|
||||
Geometry1 geometry1;
|
||||
Geometry2 geometry2;
|
||||
|
||||
bg::read_wkt(wkt1, geometry1);
|
||||
bg::read_wkt(wkt2, geometry2);
|
||||
|
||||
boost::variant<Geometry1> v1(geometry1);
|
||||
boost::variant<Geometry2> v2(geometry2);
|
||||
|
||||
check_touches(geometry1, geometry2, wkt1, wkt2, expected);
|
||||
check_touches(v1, geometry2, wkt1, wkt2, expected);
|
||||
check_touches(geometry1, v2, wkt1, wkt2, expected);
|
||||
check_touches(v1, v2, wkt1, wkt2, expected);
|
||||
}
|
||||
|
||||
|
||||
template <typename Geometry>
|
||||
void test_self_touches(std::string const& wkt, bool expected)
|
||||
|
||||
Reference in New Issue
Block a user