Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86523 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms libs/geometry/test/multi/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-10-30 08:03:54


Author: bruno.lalande
Date: 2013-10-30 08:03:54 EDT (Wed, 30 Oct 2013)
New Revision: 86523
URL: http://svn.boost.org/trac/boost/changeset/86523

Log:
Made disjoint variant-aware.

Added:
   trunk/libs/geometry/test/algorithms/test_disjoint.hpp (contents, props changed)
Text files modified:
   trunk/boost/geometry/algorithms/disjoint.hpp | 106 +++++++++++++++++++++++++++++++++++++--
   trunk/libs/geometry/test/algorithms/disjoint.cpp | 27 ---------
   trunk/libs/geometry/test/algorithms/test_disjoint.hpp | 63 +++++++++++++++++++++++
   trunk/libs/geometry/test/multi/algorithms/multi_disjoint.cpp | 31 ----------
   4 files changed, 165 insertions(+), 62 deletions(-)

Modified: trunk/boost/geometry/algorithms/disjoint.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/disjoint.hpp Wed Oct 30 04:44:08 2013 (r86522)
+++ trunk/boost/geometry/algorithms/disjoint.hpp 2013-10-30 08:03:54 EDT (Wed, 30 Oct 2013) (r86523)
@@ -20,6 +20,9 @@
 
 #include <boost/mpl/if.hpp>
 #include <boost/range.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
 
 #include <boost/static_assert.hpp>
 
@@ -319,6 +322,101 @@
 #endif // DOXYGEN_NO_DISPATCH
 
 
+namespace resolve_variant {
+
+template <typename Geometry1, typename Geometry2>
+struct disjoint
+{
+ static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2)
+ {
+ concept::check_concepts_and_equal_dimensions
+ <
+ Geometry1 const,
+ Geometry2 const
+ >();
+
+ return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
+struct disjoint<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 disjoint<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 disjoint<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 disjoint<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 disjoint<
+ 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 disjoint<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_check2{are disjoint}
@@ -335,13 +433,7 @@
 inline bool disjoint(Geometry1 const& geometry1,
             Geometry2 const& geometry2)
 {
- concept::check_concepts_and_equal_dimensions
- <
- Geometry1 const,
- Geometry2 const
- >();
-
- return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
+ return resolve_variant::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
 }
 
 

Modified: trunk/libs/geometry/test/algorithms/disjoint.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/disjoint.cpp Wed Oct 30 04:44:08 2013 (r86522)
+++ trunk/libs/geometry/test/algorithms/disjoint.cpp 2013-10-30 08:03:54 EDT (Wed, 30 Oct 2013) (r86523)
@@ -12,16 +12,11 @@
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <iostream>
-#include <string>
 
+#include <algorithms/test_disjoint.hpp>
 
-#include <geometry_test_common.hpp>
-
-#include <boost/geometry/algorithms/disjoint.hpp>
 #include <boost/geometry/geometries/geometries.hpp>
 #include <boost/geometry/geometries/point_xy.hpp>
-#include <boost/geometry/io/wkt/read.hpp>
 #include <boost/geometry/strategies/strategies.hpp>
 
 #include <test_common/test_point.hpp>
@@ -29,26 +24,6 @@
 #include <algorithms/test_relate.hpp>
 
 
-template <typename G1, typename G2>
-void test_disjoint(std::string const& id,
- std::string const& wkt1,
- std::string const& wkt2, bool expected)
-{
- G1 g1;
- bg::read_wkt(wkt1, g1);
-
- G2 g2;
- bg::read_wkt(wkt2, g2);
-
- bool detected = bg::disjoint(g1, g2);
- BOOST_CHECK_MESSAGE(detected == expected,
- "disjoint: " << id
- << " -> Expected: " << expected
- << " detected: " << detected);
-}
-
-
-
 template <typename P>
 void test_all()
 {

Added: trunk/libs/geometry/test/algorithms/test_disjoint.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/geometry/test/algorithms/test_disjoint.hpp 2013-10-30 08:03:54 EDT (Wed, 30 Oct 2013) (r86523)
@@ -0,0 +1,63 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// Unit Test
+
+// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
+// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
+// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
+
+// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
+// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
+
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_GEOMETRY_TEST_DISJOINT_HPP
+#define BOOST_GEOMETRY_TEST_DISJOINT_HPP
+
+#include <iostream>
+#include <string>
+#include <boost/variant/variant.hpp>
+
+#include <geometry_test_common.hpp>
+
+#include <boost/geometry/algorithms/disjoint.hpp>
+#include <boost/geometry/multi/algorithms/disjoint.hpp>
+#include <boost/geometry/multi/io/wkt/read.hpp>
+
+
+template <typename G1, typename G2>
+void check_disjoint(std::string const& id,
+ G1 const& g1,
+ G2 const& g2,
+ bool expected)
+{
+ bool detected = bg::disjoint(g1, g2);
+ BOOST_CHECK_MESSAGE(detected == expected,
+ "disjoint: " << id
+ << " -> Expected: " << expected
+ << " detected: " << detected);
+}
+
+template <typename G1, typename G2>
+void test_disjoint(std::string const& id,
+ std::string const& wkt1,
+ std::string const& wkt2, bool expected)
+{
+ G1 g1;
+ bg::read_wkt(wkt1, g1);
+
+ G2 g2;
+ bg::read_wkt(wkt2, g2);
+
+ boost::variant<G1> v1(g1);
+ boost::variant<G2> v2(g2);
+
+ check_disjoint(id, g1, g2, expected);
+ check_disjoint(id, v1, g2, expected);
+ check_disjoint(id, g1, v2, expected);
+ check_disjoint(id, v1, v2, expected);
+}
+
+
+#endif // BOOST_GEOMETRY_TEST_DISJOINT_HPP

Modified: trunk/libs/geometry/test/multi/algorithms/multi_disjoint.cpp
==============================================================================
--- trunk/libs/geometry/test/multi/algorithms/multi_disjoint.cpp Wed Oct 30 04:44:08 2013 (r86522)
+++ trunk/libs/geometry/test/multi/algorithms/multi_disjoint.cpp 2013-10-30 08:03:54 EDT (Wed, 30 Oct 2013) (r86523)
@@ -7,22 +7,15 @@
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <iostream>
-#include <string>
 
+#include <algorithms/test_disjoint.hpp>
 
-#include <geometry_test_common.hpp>
-
-#include <boost/geometry/algorithms/disjoint.hpp>
-#include <boost/geometry/io/wkt/read.hpp>
-#include <boost/geometry/multi/io/wkt/read.hpp>
 #include <boost/geometry/strategies/strategies.hpp>
 
 #include <boost/geometry/multi/algorithms/detail/sections/range_by_section.hpp>
 #include <boost/geometry/multi/algorithms/detail/sections/sectionalize.hpp>
 #include <boost/geometry/multi/algorithms/detail/point_on_border.hpp>
 #include <boost/geometry/multi/algorithms/detail/for_each_range.hpp>
-#include <boost/geometry/multi/algorithms/disjoint.hpp>
 #include <boost/geometry/multi/algorithms/within.hpp>
 #include <boost/geometry/multi/core/closure.hpp>
 #include <boost/geometry/multi/core/geometry_id.hpp>
@@ -39,26 +32,6 @@
 #include <algorithms/test_relate.hpp>
 
 
-template <typename G1, typename G2>
-void test_disjoint(std::string const& id,
- std::string const& wkt1,
- std::string const& wkt2, bool expected)
-{
- G1 g1;
- bg::read_wkt(wkt1, g1);
-
- G2 g2;
- bg::read_wkt(wkt2, g2);
-
- bool detected = bg::disjoint(g1, g2);
- BOOST_CHECK_MESSAGE(detected == expected,
- "disjoint: " << id
- << " -> Expected: " << expected
- << " detected: " << detected);
-}
-
-
-
 template <typename P>
 void test_all()
 {
@@ -154,4 +127,4 @@
 )
  select p from viewy union all select q from viewy
 -- select p.STDisjoint(q) from viewy
-*/
\ No newline at end of file
+*/


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