Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80610 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms libs/geometry/test/core
From: bruno.lalande_at_[hidden]
Date: 2012-09-20 17:48:49


Author: bruno.lalande
Date: 2012-09-20 17:48:47 EDT (Thu, 20 Sep 2012)
New Revision: 80610
URL: http://svn.boost.org/trac/boost/changeset/80610

Log:
Added support for variant geometries in area algorithms.
Text files modified:
   trunk/boost/geometry/algorithms/area.hpp | 29 +++++++++++++++++++++++++++++
   trunk/libs/geometry/test/algorithms/area.cpp | 26 ++++++++++++++++++++++++++
   trunk/libs/geometry/test/core/point_type.cpp | 7 +++++--
   3 files changed, 60 insertions(+), 2 deletions(-)

Modified: trunk/boost/geometry/algorithms/area.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/area.hpp (original)
+++ trunk/boost/geometry/algorithms/area.hpp 2012-09-20 17:48:47 EDT (Thu, 20 Sep 2012)
@@ -18,6 +18,8 @@
 #include <boost/mpl/if.hpp>
 #include <boost/range/functions.hpp>
 #include <boost/range/metafunctions.hpp>
+#include <boost/variant/static_visitor.hpp>
+#include <boost/variant/apply_visitor.hpp>
 
 #include <boost/geometry/core/closure.hpp>
 #include <boost/geometry/core/exterior_ring.hpp>
@@ -26,6 +28,7 @@
 #include <boost/geometry/core/ring_type.hpp>
 
 #include <boost/geometry/geometries/concepts/check.hpp>
+#include <boost/geometry/geometries/variant.hpp>
 
 #include <boost/geometry/algorithms/detail/calculate_null.hpp>
 #include <boost/geometry/algorithms/detail/calculate_sum.hpp>
@@ -140,6 +143,32 @@
 };
 
 
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct area<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, void>
+{
+ template <typename Strategy>
+ struct visitor: boost::static_visitor<typename Strategy::return_type>
+ {
+ Strategy const& m_strategy;
+
+ visitor(Strategy const& strategy): m_strategy(strategy) {}
+
+ template <typename Geometry>
+ typename Strategy::return_type operator()(Geometry const& geometry) const
+ {
+ return dispatch::area<Geometry>::apply(geometry, m_strategy);
+ }
+ };
+
+ template <typename Variant, typename Strategy>
+ static inline typename Strategy::return_type
+ apply(Variant const& variant_geometry, Strategy const& strategy)
+ {
+ return boost::apply_visitor(visitor<Strategy>(strategy), variant_geometry);
+ }
+};
+
+
 template <typename Geometry>
 struct area<Geometry, box_tag> : detail::area::box_area
 {};

Modified: trunk/libs/geometry/test/algorithms/area.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/area.cpp (original)
+++ trunk/libs/geometry/test/algorithms/area.cpp 2012-09-20 17:48:47 EDT (Thu, 20 Sep 2012)
@@ -25,6 +25,8 @@
 #include <test_geometries/all_custom_polygon.hpp>
 //#define GEOMETRY_TEST_DEBUG
 
+#include <boost/variant/variant.hpp>
+
 template <typename Polygon>
 void test_polygon()
 {
@@ -222,6 +224,28 @@
     BOOST_CHECK_CLOSE(int_area, double_area, 0.0001);
 }
 
+void test_variant()
+{
+ typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type;
+ typedef bg::model::polygon<double_point_type> polygon_type;
+ typedef bg::model::box<double_point_type> box_type;
+
+ polygon_type poly;
+ std::string const polygon_li = "POLYGON((18 5,18 1,15 1,15 5,12 5,12 8,15 8,18 8,18 5))";
+ bg::read_wkt(polygon_li, poly);
+
+ box_type box;
+ std::string const box_li = "BOX(0 0,2 2)";
+ bg::read_wkt(box_li, box);
+
+ boost::variant<polygon_type, box_type> v;
+
+ v = poly;
+ BOOST_CHECK_CLOSE(bg::area(v), bg::area(poly), 0.0001);
+ v = box;
+ BOOST_CHECK_CLOSE(bg::area(v), bg::area(box), 0.0001);
+}
+
 int test_main(int, char* [])
 {
     test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
@@ -242,6 +266,8 @@
 
     test_large_integers();
 
+ test_variant();
+
     // test_empty_input<bg::model::d2::point_xy<int> >();
 
     return 0;

Modified: trunk/libs/geometry/test/core/point_type.cpp
==============================================================================
--- trunk/libs/geometry/test/core/point_type.cpp (original)
+++ trunk/libs/geometry/test/core/point_type.cpp 2012-09-20 17:48:47 EDT (Thu, 20 Sep 2012)
@@ -64,9 +64,12 @@
     test_geometry<double[3], double[3]>();
 
     test_geometry<boost::tuple<double, double>,
- boost::tuple<double, double> >();
+ boost::tuple<double, double> >();
     test_geometry<boost::tuple<double, double, double>,
- boost::tuple<double, double, double> >();
+ boost::tuple<double, double, double> >();
+
+ test_geometry<boost::variant<bg::model::box<boost::tuple<double, double> > >,
+ boost::tuple<double, double> >();
 
     test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
     test_all<bg::model::point<float, 2, bg::cs::cartesian> >();


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