Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86606 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-11-10 18:07:59


Author: bruno.lalande
Date: 2013-11-10 18:07:59 EST (Sun, 10 Nov 2013)
New Revision: 86606
URL: http://svn.boost.org/trac/boost/changeset/86606

Log:
Made within algorithm variant-aware.

Text files modified:
   trunk/boost/geometry/algorithms/within.hpp | 237 +++++++++++++++++++++++++++++++++------
   trunk/libs/geometry/test/algorithms/test_within.hpp | 30 +++-
   2 files changed, 219 insertions(+), 48 deletions(-)

Modified: trunk/boost/geometry/algorithms/within.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/within.hpp Sat Nov 9 15:05:44 2013 (r86605)
+++ trunk/boost/geometry/algorithms/within.hpp 2013-11-10 18:07:59 EST (Sun, 10 Nov 2013) (r86606)
@@ -20,6 +20,9 @@
 #include <boost/concept_check.hpp>
 #include <boost/range.hpp>
 #include <boost/typeof/typeof.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
 
 #include <boost/geometry/algorithms/make.hpp>
 #include <boost/geometry/algorithms/not_implemented.hpp>
@@ -35,8 +38,9 @@
 #include <boost/geometry/core/tags.hpp>
 
 #include <boost/geometry/geometries/concepts/check.hpp>
-#include <boost/geometry/strategies/within.hpp>
 #include <boost/geometry/strategies/concepts/within_concept.hpp>
+#include <boost/geometry/strategies/default_strategy.hpp>
+#include <boost/geometry/strategies/within.hpp>
 #include <boost/geometry/util/math.hpp>
 #include <boost/geometry/util/order_as_direction.hpp>
 #include <boost/geometry/views/closeable_view.hpp>
@@ -239,6 +243,195 @@
 #endif // DOXYGEN_NO_DISPATCH
 
 
+namespace resolve_strategy
+{
+
+struct within
+{
+ 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
+ >();
+
+ return dispatch::within<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::within::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 apply(geometry1, geometry2, strategy_type());
+ }
+};
+
+} // namespace resolve_strategy
+
+
+namespace resolve_variant
+{
+
+template <typename Geometry1, typename Geometry2>
+struct within
+{
+ template <typename Strategy>
+ static inline bool apply(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ Strategy const& strategy)
+ {
+ concept::check<Geometry1 const>();
+ concept::check<Geometry2 const>();
+ assert_dimension_equal<Geometry1, Geometry2>();
+
+ return resolve_strategy::within::apply(geometry1,
+ geometry2,
+ strategy);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
+struct within<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 within<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 within<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 within<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 within<
+ 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 within<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
+ );
+ }
+};
+
+}
+
+
 /*!
 \brief \brief_check12{is completely inside}
 \ingroup within
@@ -263,36 +456,11 @@
 template<typename Geometry1, typename Geometry2>
 inline bool within(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::within::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::within
+ return resolve_variant::within
         <
             Geometry1,
             Geometry2
- >::apply(geometry1, geometry2, strategy_type());
+ >::apply(geometry1, geometry2, default_strategy());
 }
 
 /*!
@@ -325,18 +493,7 @@
 inline bool within(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::within
+ return resolve_variant::within
         <
             Geometry1,
             Geometry2

Modified: trunk/libs/geometry/test/algorithms/test_within.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_within.hpp Sat Nov 9 15:05:44 2013 (r86605)
+++ trunk/libs/geometry/test/algorithms/test_within.hpp 2013-11-10 18:07:59 EST (Sun, 10 Nov 2013) (r86606)
@@ -11,6 +11,8 @@
 #define BOOST_GEOMETRY_TEST_WITHIN_HPP
 
 
+#include <boost/variant/variant.hpp>
+
 #include <geometry_test_common.hpp>
 
 #include <boost/geometry/core/ring_type.hpp>
@@ -27,15 +29,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::within(geometry1, geometry2);
 
     BOOST_CHECK_MESSAGE(detected == expected,
@@ -45,7 +44,22 @@
         << " 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>
 void test_ordered_ring(std::string const& wkt_point,


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