Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86634 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-11-12 02:52:06


Author: bruno.lalande
Date: 2013-11-12 02:52:06 EST (Tue, 12 Nov 2013)
New Revision: 86634
URL: http://svn.boost.org/trac/boost/changeset/86634

Log:
Made remove_spikes variant-aware.

Text files modified:
   trunk/boost/geometry/algorithms/remove_spikes.hpp | 40 +++++++++++++++++++++++++++--
   trunk/libs/geometry/test/algorithms/remove_spikes.cpp | 53 +++++++++++++++++++++------------------
   2 files changed, 65 insertions(+), 28 deletions(-)

Modified: trunk/boost/geometry/algorithms/remove_spikes.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/remove_spikes.hpp Mon Nov 11 22:04:57 2013 (r86633)
+++ trunk/boost/geometry/algorithms/remove_spikes.hpp 2013-11-12 02:52:06 EST (Tue, 12 Nov 2013) (r86634)
@@ -16,6 +16,9 @@
 
 #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/core/closure.hpp>
 #include <boost/geometry/core/coordinate_type.hpp>
@@ -188,6 +191,39 @@
 #endif
 
 
+namespace resolve_variant {
+
+template <typename Geometry>
+struct remove_spikes
+{
+ static void apply(Geometry& geometry)
+ {
+ concept::check<Geometry>();
+ dispatch::remove_spikes<Geometry>::apply(geometry);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct remove_spikes<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ struct visitor: boost::static_visitor<void>
+ {
+ template <typename Geometry>
+ void operator()(Geometry& geometry) const
+ {
+ remove_spikes<Geometry>::apply(geometry);
+ }
+ };
+
+ static inline void apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
+ {
+ boost::apply_visitor(visitor(), geometry);
+ }
+};
+
+} // namespace resolve_variant
+
+
 /*!
     \ingroup remove_spikes
     \tparam Geometry geometry type
@@ -196,9 +232,7 @@
 template <typename Geometry>
 inline void remove_spikes(Geometry& geometry)
 {
- concept::check<Geometry>();
-
- dispatch::remove_spikes<Geometry>::apply(geometry);
+ resolve_variant::remove_spikes<Geometry>::apply(geometry);
 }
 
 

Modified: trunk/libs/geometry/test/algorithms/remove_spikes.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/remove_spikes.cpp Mon Nov 11 22:04:57 2013 (r86633)
+++ trunk/libs/geometry/test/algorithms/remove_spikes.cpp 2013-11-12 02:52:06 EST (Tue, 12 Nov 2013) (r86634)
@@ -19,6 +19,8 @@
 // will avoid testing multi-geometries
 #define BOOST_GEOMETRY_UNIT_TEST_MULTI
 
+#include <boost/variant/variant.hpp>
+
 #include <geometry_test_common.hpp>
 
 // The include to test
@@ -52,37 +54,16 @@
 
 template <typename Geometry>
 inline void test_remove_spikes(std::string const& id,
- Geometry const& geometry,
+ Geometry& geometry,
             double expected_area, double expected_perimeter)
 {
- typedef typename bg::point_type<Geometry>::type point_type;
-
- Geometry processed = geometry;
- bg::remove_spikes(processed);
+ bg::remove_spikes(geometry);
 
- double detected_area = bg::area(processed);
- double detected_perimeter = bg::perimeter(processed);
+ double detected_area = bg::area(geometry);
+ double detected_perimeter = bg::perimeter(geometry);
 
     BOOST_CHECK_CLOSE(detected_area, expected_area, 0.01);
     BOOST_CHECK_CLOSE(detected_perimeter, expected_perimeter, 0.01);
-
-#if defined(TEST_WITH_SVG)
- {
- std::ostringstream filename;
- filename << "remove_spikes_" << id;
- if (! bg::closure<Geometry>::value)
- {
- filename << "_open";
- }
- filename << ".svg";
- std::ofstream svg(filename.str().c_str());
-
- bg::svg_mapper<typename bg::point_type<Geometry>::type> mapper(svg, 500, 500);
- mapper.add(geometry);
- mapper.map(geometry, "fill-opacity:0.3;opacity:0.6;fill:rgb(51,51,153);stroke:rgb(0,0,255);stroke-width:2");
- mapper.map(processed, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:3");
- }
-#endif
 }
 
 template <typename Geometry>
@@ -92,7 +73,29 @@
     Geometry geometry;
     bg::read_wkt(wkt, geometry);
     bg::correct(geometry);
+ boost::variant<Geometry> v(geometry);
+
+#if defined(TEST_WITH_SVG)
+ std::ostringstream filename;
+ filename << "remove_spikes_" << id;
+ if (! bg::closure<Geometry>::value)
+ {
+ filename << "_open";
+ }
+ filename << ".svg";
+ std::ofstream svg(filename.str().c_str());
+
+ bg::svg_mapper<typename bg::point_type<Geometry>::type> mapper(svg, 500, 500);
+ mapper.add(geometry);
+ mapper.map(geometry, "fill-opacity:0.3;opacity:0.6;fill:rgb(51,51,153);stroke:rgb(0,0,255);stroke-width:2");
+#endif
+
     test_remove_spikes(id, geometry, expected_area, expected_perimeter);
+ test_remove_spikes(id, v, expected_area, expected_perimeter);
+
+#if defined(TEST_WITH_SVG)
+ mapper.map(geometry, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:3");
+#endif
 }
 
 template <typename P, bool Clockwise, bool Closed>


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