Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82463 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-01-12 13:28:01


Author: bruno.lalande
Date: 2013-01-12 13:28:00 EST (Sat, 12 Jan 2013)
New Revision: 82463
URL: http://svn.boost.org/trac/boost/changeset/82463

Log:
Made the equals algorithm variant-aware.
Text files modified:
   trunk/boost/geometry/algorithms/equals.hpp | 95 +++++++++++++++++++++++++++++++++++++--
   trunk/libs/geometry/test/algorithms/test_equals.hpp | 35 ++++++++++----
   2 files changed, 112 insertions(+), 18 deletions(-)

Modified: trunk/boost/geometry/algorithms/equals.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/equals.hpp (original)
+++ trunk/boost/geometry/algorithms/equals.hpp 2013-01-12 13:28:00 EST (Sat, 12 Jan 2013)
@@ -39,6 +39,9 @@
 
 #include <boost/geometry/algorithms/detail/equals/collect_vectors.hpp>
 
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+
 
 namespace boost { namespace geometry
 {
@@ -239,6 +242,90 @@
 {};
 
 
+template <typename Geometry1, typename Geometry2>
+struct devarianted_equals
+{
+ static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2)
+ {
+ concept::check_concepts_and_equal_dimensions
+ <
+ Geometry1 const,
+ Geometry2 const
+ >();
+ return equals<Geometry1, Geometry2>::apply(geometry1, geometry2);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
+struct devarianted_equals<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
+{
+ struct visitor: static_visitor<bool>
+ {
+ Geometry2 const& m_geometry2;
+
+ visitor(Geometry2 const& geometry2)
+ : m_geometry2(geometry2)
+ {}
+
+ template <typename Geometry1>
+ inline bool operator()(Geometry1 const& geometry1) const
+ {
+ return devarianted_equals<Geometry1, Geometry2>::apply(geometry1, m_geometry2);
+ }
+
+ };
+
+ static inline bool apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1, Geometry2 const& geometry2)
+ {
+ return apply_visitor(visitor(geometry2), geometry1);
+ }
+};
+
+template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct devarianted_equals<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ struct visitor: static_visitor<bool>
+ {
+ Geometry1 const& m_geometry1;
+
+ visitor(Geometry1 const& geometry1)
+ : m_geometry1(geometry1)
+ {}
+
+ template <typename Geometry2>
+ inline bool operator()(Geometry2 const& geometry2) const
+ {
+ return devarianted_equals<Geometry1, Geometry2>::apply(m_geometry1, geometry2);
+ }
+
+ };
+
+ static inline bool apply(Geometry1 const& geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2)
+ {
+ return apply_visitor(visitor(geometry1), geometry2);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
+struct devarianted_equals<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
+{
+ struct visitor: static_visitor<bool>
+ {
+ template <typename Geometry1, typename Geometry2>
+ inline bool operator()(Geometry1 const& geometry1, Geometry2 const& geometry2) const
+ {
+ return devarianted_equals<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 apply_visitor(visitor(), geometry1, geometry2);
+ }
+};
+
+
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 
@@ -263,13 +350,7 @@
 template <typename Geometry1, typename Geometry2>
 inline bool equals(Geometry1 const& geometry1, Geometry2 const& geometry2)
 {
- concept::check_concepts_and_equal_dimensions
- <
- Geometry1 const,
- Geometry2 const
- >();
-
- return dispatch::equals<Geometry1, Geometry2>::apply(geometry1, geometry2);
+ return dispatch::devarianted_equals<Geometry1, Geometry2>::apply(geometry1, geometry2);
 }
 
 

Modified: trunk/libs/geometry/test/algorithms/test_equals.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_equals.hpp (original)
+++ trunk/libs/geometry/test/algorithms/test_equals.hpp 2013-01-12 13:28:00 EST (Sat, 12 Jan 2013)
@@ -15,8 +15,27 @@
 #include <boost/geometry/core/ring_type.hpp>
 #include <boost/geometry/algorithms/equals.hpp>
 #include <boost/geometry/strategies/strategies.hpp>
-
 #include <boost/geometry/io/wkt/read.hpp>
+#include <boost/variant/variant.hpp>
+
+
+template <typename Geometry1, typename Geometry2>
+void check_geometry(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ std::string const& caseid,
+ std::string const& wkt1,
+ std::string const& wkt2,
+ bool expected)
+{
+ bool detected = bg::equals(geometry1, geometry2);
+
+ BOOST_CHECK_MESSAGE(detected == expected,
+ "case: " << caseid
+ << " equals: " << wkt1
+ << " to " << wkt2
+ << " -> Expected: " << expected
+ << " detected: " << detected);
+}
 
 
 template <typename Geometry1, typename Geometry2>
@@ -24,22 +43,16 @@
             std::string const& wkt1,
             std::string const& wkt2, bool expected)
 {
- //std::cout << caseid << " expected: " << int(expected) << std::endl;
- //std::cout << wkt1 << std::endl;
     Geometry1 geometry1;
     Geometry2 geometry2;
 
     bg::read_wkt(wkt1, geometry1);
     bg::read_wkt(wkt2, geometry2);
 
- bool detected = bg::equals(geometry1, geometry2);
-
- BOOST_CHECK_MESSAGE(detected == expected,
- "case: " << caseid
- << " equals: " << wkt1
- << " to " << wkt2
- << " -> Expected: " << expected
- << " detected: " << detected);
+ check_geometry(geometry1, geometry2, caseid, wkt1, wkt2, expected);
+ check_geometry(boost::variant<Geometry1>(geometry1), geometry2, caseid, wkt1, wkt2, expected);
+ check_geometry(geometry1, boost::variant<Geometry2>(geometry2), caseid, wkt1, wkt2, expected);
+ check_geometry(boost::variant<Geometry1>(geometry1), boost::variant<Geometry2>(geometry2), caseid, wkt1, wkt2, expected);
 }
 
 #endif


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