From e6f57e7523aa302452f97eb036ecef4da3ea02d3 Mon Sep 17 00:00:00 2001 From: Bruno Lalande Date: Fri, 11 Oct 2013 21:47:28 +0000 Subject: [PATCH] Made the buffer algorithm variant aware. [SVN r86240] --- include/boost/geometry/algorithms/buffer.hpp | 67 ++++++++++++++++---- test/algorithms/buffer.cpp | 11 +++- 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/include/boost/geometry/algorithms/buffer.hpp b/include/boost/geometry/algorithms/buffer.hpp index 653a8d968..f765a9bfb 100644 --- a/include/boost/geometry/algorithms/buffer.hpp +++ b/include/boost/geometry/algorithms/buffer.hpp @@ -17,7 +17,9 @@ #include #include - +#include +#include +#include #include #include @@ -103,6 +105,57 @@ struct buffer // 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 +struct devarianted_buffer +{ + template + static inline void apply(Geometry const& geometry, + Distance const& distance, + Distance const& chord_length, + GeometryOut& out) + { + buffer::apply(geometry, distance, chord_length, out); + } +}; + +template +struct devarianted_buffer > +{ + template + struct visitor: boost::static_visitor + { + 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 + void operator()(Geometry const& geometry) const + { + devarianted_buffer::apply(geometry, m_distance, m_chord_length, m_out); + } + }; + + template + static inline void apply( + boost::variant const& geometry, + Distance const& distance, + Distance const& chord_length, + GeometryOut& out + ) + { + boost::apply_visitor(visitor(distance, chord_length, out), geometry); + } +}; + } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH @@ -129,11 +182,7 @@ inline void buffer(Input const& geometry_in, Output& geometry_out, concept::check(); concept::check(); - dispatch::buffer - < - Input, - Output - >::apply(geometry_in, distance, chord_length, geometry_out); + dispatch::devarianted_buffer::apply(geometry_in, distance, chord_length, geometry_out); } /*! @@ -157,11 +206,7 @@ Output return_buffer(Input const& geometry, Distance const& distance, Distance c Output geometry_out; - dispatch::buffer - < - Input, - Output - >::apply(geometry, distance, chord_length, geometry_out); + dispatch::devarianted_buffer::apply(geometry, distance, chord_length, geometry_out); return geometry_out; } diff --git a/test/algorithms/buffer.cpp b/test/algorithms/buffer.cpp index f64a25f9d..fc591e630 100644 --- a/test/algorithms/buffer.cpp +++ b/test/algorithms/buffer.cpp @@ -13,6 +13,8 @@ // http://www.boost.org/LICENSE_1_0.txt) +#include + #include #include @@ -32,11 +34,16 @@ void test_all() P p1(0, 0); P p2(2, 2); - bg::model::box

b1(p1, p2); - bg::model::box

b2; + typedef bg::model::box

box_type; + + box_type b1(p1, p2); + box_type b2; bg::buffer(b1, b2, coordinate_type(2)); + boost::variant v(b1); + bg::buffer(v, b2, coordinate_type(2)); + // TODO: Check if buffer is correct // using bg::equals to compare boxes // (TODO: implement that)