Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86461 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-10-26 17:37:49


Author: bruno.lalande
Date: 2013-10-26 17:37:49 EDT (Sat, 26 Oct 2013)
New Revision: 86461
URL: http://svn.boost.org/trac/boost/changeset/86461

Log:
Made covered_by variant-aware.

Text files modified:
   trunk/boost/geometry/algorithms/covered_by.hpp | 226 +++++++++++++++++++++++++++++++--------
   trunk/libs/geometry/test/algorithms/covered_by.cpp | 16 --
   trunk/libs/geometry/test/algorithms/test_covered_by.hpp | 32 ++++-
   3 files changed, 204 insertions(+), 70 deletions(-)

Modified: trunk/boost/geometry/algorithms/covered_by.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/covered_by.hpp Sat Oct 26 17:02:15 2013 (r86460)
+++ trunk/boost/geometry/algorithms/covered_by.hpp 2013-10-26 17:37:49 EDT (Sat, 26 Oct 2013) (r86461)
@@ -17,11 +17,16 @@
 
 #include <cstddef>
 
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
+
 #include <boost/geometry/algorithms/not_implemented.hpp>
 #include <boost/geometry/algorithms/within.hpp>
 
 #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
 #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
+#include <boost/geometry/strategies/default_strategy.hpp>
 
 namespace boost { namespace geometry
 {
@@ -104,6 +109,177 @@
 #endif // DOXYGEN_NO_DISPATCH
 
 
+namespace resolve_strategy {
+
+struct covered_by
+{
+ template <typename Geometry1, typename Geometry2, typename Strategy>
+ static inline bool apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
+ {
+ concept::within::check
+ <
+ typename tag<Geometry1>::type,
+ typename tag<Geometry2>::type,
+ typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
+ Strategy
+ >();
+ concept::check<Geometry1 const>();
+ concept::check<Geometry2 const>();
+ assert_dimension_equal<Geometry1, Geometry2>();
+
+ return dispatch::covered_by<Geometry1, Geometry2>::apply(geometry1,
+ geometry2,
+ strategy);
+ }
+
+ template <typename Geometry1, typename Geometry2>
+ static inline bool apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ default_strategy)
+ {
+ typedef typename point_type<Geometry1>::type point_type1;
+ typedef typename point_type<Geometry2>::type point_type2;
+
+ typedef typename strategy::covered_by::services::default_strategy
+ <
+ typename tag<Geometry1>::type,
+ typename tag<Geometry2>::type,
+ typename tag<Geometry1>::type,
+ typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
+ typename tag_cast
+ <
+ typename cs_tag<point_type1>::type, spherical_tag
+ >::type,
+ typename tag_cast
+ <
+ typename cs_tag<point_type2>::type, spherical_tag
+ >::type,
+ Geometry1,
+ Geometry2
+ >::type strategy_type;
+
+ return covered_by::apply(geometry1, geometry2, strategy_type());
+ }
+};
+
+} // namespace resolve_strategy
+
+
+namespace resolve_variant {
+
+template <typename Geometry1, typename Geometry2>
+struct covered_by
+{
+ template <typename Strategy>
+ static inline bool apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
+ {
+ return resolve_strategy::covered_by
+ ::apply(geometry1, geometry2, strategy);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
+struct covered_by<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
+{
+ template <typename Strategy>
+ struct visitor: boost::static_visitor<bool>
+ {
+ Geometry2 const& m_geometry2;
+ Strategy const& m_strategy;
+
+ visitor(Geometry2 const& geometry2, Strategy const& strategy)
+ : m_geometry2(geometry2), m_strategy(strategy) {}
+
+ template <typename Geometry1>
+ bool operator()(Geometry1 const& geometry1) const
+ {
+ return covered_by<Geometry1, Geometry2>
+ ::apply(geometry1, m_geometry2, m_strategy);
+ }
+ };
+
+ template <typename Strategy>
+ static inline bool
+ apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
+ {
+ return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
+ }
+};
+
+template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct covered_by<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ template <typename Strategy>
+ struct visitor: boost::static_visitor<bool>
+ {
+ Geometry1 const& m_geometry1;
+ Strategy const& m_strategy;
+
+ visitor(Geometry1 const& geometry1, Strategy const& strategy)
+ : m_geometry1(geometry1), m_strategy(strategy) {}
+
+ template <typename Geometry2>
+ bool operator()(Geometry2 const& geometry2) const
+ {
+ return covered_by<Geometry1, Geometry2>
+ ::apply(m_geometry1, geometry2, m_strategy);
+ }
+ };
+
+ template <typename Strategy>
+ static inline bool
+ apply(Geometry1 const& geometry1,
+ boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
+ Strategy const& strategy)
+ {
+ return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
+ }
+};
+
+template <
+ BOOST_VARIANT_ENUM_PARAMS(typename T1),
+ BOOST_VARIANT_ENUM_PARAMS(typename T2)
+>
+struct covered_by<
+ boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
+ boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
+>
+{
+ template <typename Strategy>
+ struct visitor: boost::static_visitor<bool>
+ {
+ Strategy const& m_strategy;
+
+ visitor(Strategy const& strategy): m_strategy(strategy) {}
+
+ template <typename Geometry1, typename Geometry2>
+ bool operator()(Geometry1 const& geometry1,
+ Geometry2 const& geometry2) const
+ {
+ return covered_by<Geometry1, Geometry2>
+ ::apply(geometry1, geometry2, m_strategy);
+ }
+ };
+
+ template <typename Strategy>
+ static inline bool
+ apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
+ boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
+ Strategy const& strategy)
+ {
+ return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
+ }
+};
+
+} // namespace resolve_variant
+
+
 /*!
 \brief \brief_check12{is inside or on border}
 \ingroup covered_by
@@ -122,36 +298,8 @@
 template<typename Geometry1, typename Geometry2>
 inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2)
 {
- concept::check<Geometry1 const>();
- concept::check<Geometry2 const>();
- assert_dimension_equal<Geometry1, Geometry2>();
-
- typedef typename point_type<Geometry1>::type point_type1;
- typedef typename point_type<Geometry2>::type point_type2;
-
- typedef typename strategy::covered_by::services::default_strategy
- <
- typename tag<Geometry1>::type,
- typename tag<Geometry2>::type,
- typename tag<Geometry1>::type,
- typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
- typename tag_cast
- <
- typename cs_tag<point_type1>::type, spherical_tag
- >::type,
- typename tag_cast
- <
- typename cs_tag<point_type2>::type, spherical_tag
- >::type,
- Geometry1,
- Geometry2
- >::type strategy_type;
-
- return dispatch::covered_by
- <
- Geometry1,
- Geometry2
- >::apply(geometry1, geometry2, strategy_type());
+ return resolve_variant::covered_by<Geometry1, Geometry2>
+ ::apply(geometry1, geometry2, default_strategy());
 }
 
 /*!
@@ -174,22 +322,8 @@
 inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2,
         Strategy const& strategy)
 {
- concept::within::check
- <
- typename tag<Geometry1>::type,
- typename tag<Geometry2>::type,
- typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
- Strategy
- >();
- concept::check<Geometry1 const>();
- concept::check<Geometry2 const>();
- assert_dimension_equal<Geometry1, Geometry2>();
-
- return dispatch::covered_by
- <
- Geometry1,
- Geometry2
- >::apply(geometry1, geometry2, strategy);
+ return resolve_variant::covered_by<Geometry1, Geometry2>
+ ::apply(geometry1, geometry2, strategy);
 }
 
 }} // namespace boost::geometry

Modified: trunk/libs/geometry/test/algorithms/covered_by.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/covered_by.cpp Sat Oct 26 17:02:15 2013 (r86460)
+++ trunk/libs/geometry/test/algorithms/covered_by.cpp 2013-10-26 17:37:49 EDT (Sat, 26 Oct 2013) (r86461)
@@ -52,22 +52,6 @@
     test_geometry<box_type, box_type>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true);
     test_geometry<box_type, box_type>("BOX(1 2,3 3)", "BOX(0 0,3 3)", true);
     test_geometry<box_type, box_type>("BOX(1 1,4 3)", "BOX(0 0,3 3)", false);
-
-
- /*
- test_within_code<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", 1);
- test_within_code<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", 0);
- test_within_code<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", 0);
- test_within_code<P, box_type>("POINT(0 3)", "BOX(0 0,2 2)", -1);
- test_within_code<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", -1);
-
- test_within_code<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", 1);
- test_within_code<box_type, box_type>("BOX(0 1,2 2)", "BOX(0 0,3 3)", 0);
- test_within_code<box_type, box_type>("BOX(1 0,2 2)", "BOX(0 0,3 3)", 0);
- test_within_code<box_type, box_type>("BOX(1 1,2 3)", "BOX(0 0,3 3)", 0);
- test_within_code<box_type, box_type>("BOX(1 1,3 2)", "BOX(0 0,3 3)", 0);
- test_within_code<box_type, box_type>("BOX(1 1,3 4)", "BOX(0 0,3 3)", -1);
- */
 }
 
 

Modified: trunk/libs/geometry/test/algorithms/test_covered_by.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_covered_by.hpp Sat Oct 26 17:02:15 2013 (r86460)
+++ trunk/libs/geometry/test/algorithms/test_covered_by.hpp 2013-10-26 17:37:49 EDT (Sat, 26 Oct 2013) (r86461)
@@ -13,6 +13,8 @@
 
 #include <geometry_test_common.hpp>
 
+#include <boost/variant/variant.hpp>
+
 #include <boost/geometry/core/ring_type.hpp>
 #include <boost/geometry/algorithms/covered_by.hpp>
 #include <boost/geometry/strategies/strategies.hpp>
@@ -23,15 +25,12 @@
 
 
 template <typename Geometry1, typename Geometry2>
-void test_geometry(std::string const& wkt1,
- std::string const& wkt2, bool expected)
+void check_geometry(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::covered_by(geometry1, geometry2);
 
     BOOST_CHECK_MESSAGE(detected == expected,
@@ -41,6 +40,23 @@
         << " detected: " << detected);
 }
 
+template <typename Geometry1, typename Geometry2>
+void test_geometry(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_geometry(geometry1, geometry2, wkt1, wkt2, expected);
+ check_geometry(v1, geometry2, wkt1, wkt2, expected);
+ check_geometry(geometry1, v2, wkt1, wkt2, expected);
+ check_geometry(v1, v2, wkt1, wkt2, expected);
+}
+
 /*
 
 template <typename Point, bool Clockwise, bool Closed>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk