Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86240 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-10-11 17:47:28


Author: bruno.lalande
Date: 2013-10-11 17:47:28 EDT (Fri, 11 Oct 2013)
New Revision: 86240
URL: http://svn.boost.org/trac/boost/changeset/86240

Log:
Made the buffer algorithm variant aware.

Text files modified:
   trunk/boost/geometry/algorithms/buffer.hpp | 67 +++++++++++++++++++++++++++++++++------
   trunk/libs/geometry/test/algorithms/buffer.cpp | 11 +++++-
   2 files changed, 65 insertions(+), 13 deletions(-)

Modified: trunk/boost/geometry/algorithms/buffer.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/buffer.hpp Fri Oct 11 16:49:05 2013 (r86239)
+++ trunk/boost/geometry/algorithms/buffer.hpp 2013-10-11 17:47:28 EDT (Fri, 11 Oct 2013) (r86240)
@@ -17,7 +17,9 @@
 #include <cstddef>
 
 #include <boost/numeric/conversion/cast.hpp>
-
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/variant/variant_fwd.hpp>
 
 #include <boost/geometry/algorithms/clear.hpp>
 #include <boost/geometry/algorithms/not_implemented.hpp>
@@ -103,6 +105,57 @@
 // of a set of geometries are often lateron combined using a "dissolve" operation.
 // Two points close to each other get a combined kidney shaped buffer then.
 
+
+template <typename Geometry>
+struct devarianted_buffer
+{
+ template <typename Distance, typename GeometryOut>
+ static inline void apply(Geometry const& geometry,
+ Distance const& distance,
+ Distance const& chord_length,
+ GeometryOut& out)
+ {
+ buffer<Geometry, GeometryOut>::apply(geometry, distance, chord_length, out);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct devarianted_buffer<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ template <typename Distance, typename GeometryOut>
+ struct visitor: boost::static_visitor<void>
+ {
+ Distance const& m_distance;
+ Distance const& m_chord_length;
+ GeometryOut& m_out;
+
+ visitor(Distance const& distance,
+ Distance const& chord_length,
+ GeometryOut& out)
+ : m_distance(distance),
+ m_chord_length(chord_length),
+ m_out(out)
+ {}
+
+ template <typename Geometry>
+ void operator()(Geometry const& geometry) const
+ {
+ devarianted_buffer<Geometry>::apply(geometry, m_distance, m_chord_length, m_out);
+ }
+ };
+
+ template <typename Distance, typename GeometryOut>
+ static inline void apply(
+ boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
+ Distance const& distance,
+ Distance const& chord_length,
+ GeometryOut& out
+ )
+ {
+ boost::apply_visitor(visitor<Distance, GeometryOut>(distance, chord_length, out), geometry);
+ }
+};
+
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH
 
@@ -129,11 +182,7 @@
     concept::check<Input const>();
     concept::check<Output>();
 
- dispatch::buffer
- <
- Input,
- Output
- >::apply(geometry_in, distance, chord_length, geometry_out);
+ dispatch::devarianted_buffer<Input>::apply(geometry_in, distance, chord_length, geometry_out);
 }
 
 /*!
@@ -157,11 +206,7 @@
 
     Output geometry_out;
 
- dispatch::buffer
- <
- Input,
- Output
- >::apply(geometry, distance, chord_length, geometry_out);
+ dispatch::devarianted_buffer<Input>::apply(geometry, distance, chord_length, geometry_out);
 
     return geometry_out;
 }

Modified: trunk/libs/geometry/test/algorithms/buffer.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/buffer.cpp Fri Oct 11 16:49:05 2013 (r86239)
+++ trunk/libs/geometry/test/algorithms/buffer.cpp 2013-10-11 17:47:28 EDT (Fri, 11 Oct 2013) (r86240)
@@ -13,6 +13,8 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 
 
+#include <boost/variant/variant.hpp>
+
 #include <geometry_test_common.hpp>
 
 #include <boost/geometry/algorithms/buffer.hpp>
@@ -32,11 +34,16 @@
 
     P p1(0, 0);
     P p2(2, 2);
- bg::model::box<P> b1(p1, p2);
 
- bg::model::box<P> b2;
+ typedef bg::model::box<P> box_type;
+
+ box_type b1(p1, p2);
+ box_type b2;
     bg::buffer(b1, b2, coordinate_type(2));
 
+ boost::variant<box_type> v(b1);
+ bg::buffer(v, b2, coordinate_type(2));
+
     // TODO: Check if buffer is correct
     // using bg::equals to compare boxes
     // (TODO: implement that)


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