Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86531 - in trunk: boost/geometry/algorithms libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2013-10-31 17:01:22


Author: bruno.lalande
Date: 2013-10-31 17:01:21 EDT (Thu, 31 Oct 2013)
New Revision: 86531
URL: http://svn.boost.org/trac/boost/changeset/86531

Log:
Made envelope variant-aware.

Text files modified:
   trunk/boost/geometry/algorithms/envelope.hpp | 60 +++++++++++++++++++++++++++++++++------
   trunk/libs/geometry/test/algorithms/test_envelope.hpp | 22 +++-----------
   2 files changed, 55 insertions(+), 27 deletions(-)

Modified: trunk/boost/geometry/algorithms/envelope.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/envelope.hpp Thu Oct 31 13:34:35 2013 (r86530)
+++ trunk/boost/geometry/algorithms/envelope.hpp 2013-10-31 17:01:21 EDT (Thu, 31 Oct 2013) (r86531)
@@ -14,9 +14,11 @@
 #ifndef BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
 #define BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
 
-#include <boost/range.hpp>
-
 #include <boost/numeric/conversion/cast.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/geometry/algorithms/assign.hpp>
 #include <boost/geometry/algorithms/expand.hpp>
@@ -139,6 +141,50 @@
 #endif
 
 
+namespace resolve_variant {
+
+template <typename Geometry>
+struct envelope
+{
+ template <typename Box>
+ static inline void apply(Geometry const& geometry, Box& box)
+ {
+ concept::check<Geometry const>();
+ concept::check<Box>();
+
+ dispatch::envelope<Geometry>::apply(geometry, box);
+ }
+};
+
+template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+struct envelope<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+{
+ template <typename Box>
+ struct visitor: boost::static_visitor<void>
+ {
+ Box& m_box;
+
+ visitor(Box& box): m_box(box) {}
+
+ template <typename Geometry>
+ void operator()(Geometry const& geometry) const
+ {
+ envelope<Geometry>::apply(geometry, m_box);
+ }
+ };
+
+ template <typename Box>
+ static inline void
+ apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
+ Box& box)
+ {
+ boost::apply_visitor(visitor<Box>(box), geometry);
+ }
+};
+
+} // namespace resolve_variant
+
+
 /*!
 \brief \brief_calc{envelope}
 \ingroup envelope
@@ -157,10 +203,7 @@
 template<typename Geometry, typename Box>
 inline void envelope(Geometry const& geometry, Box& mbr)
 {
- concept::check<Geometry const>();
- concept::check<Box>();
-
- dispatch::envelope<Geometry>::apply(geometry, mbr);
+ resolve_variant::envelope<Geometry>::apply(geometry, mbr);
 }
 
 
@@ -182,11 +225,8 @@
 template<typename Box, typename Geometry>
 inline Box return_envelope(Geometry const& geometry)
 {
- concept::check<Geometry const>();
- concept::check<Box>();
-
     Box mbr;
- dispatch::envelope<Geometry>::apply(geometry, mbr);
+ resolve_variant::envelope<Geometry>::apply(geometry, mbr);
     return mbr;
 }
 

Modified: trunk/libs/geometry/test/algorithms/test_envelope.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_envelope.hpp Thu Oct 31 13:34:35 2013 (r86530)
+++ trunk/libs/geometry/test/algorithms/test_envelope.hpp 2013-10-31 17:01:21 EDT (Thu, 31 Oct 2013) (r86531)
@@ -10,6 +10,8 @@
 #define BOOST_GEOMETRY_TEST_ENVELOPE_HPP
 
 
+#include <boost/variant/variant.hpp>
+
 #include <geometry_test_common.hpp>
 
 #include <boost/geometry/algorithms/envelope.hpp>
@@ -77,31 +79,17 @@
                    const T& z1 = 0, const T& z2 = 0)
 {
     typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
-
- Geometry geometry;
- bg::read_wkt(wkt, geometry);
     box_type b;
- bg::envelope(geometry, b);
-
- check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
-}
-
-template <typename Geometry, typename T>
-void test_envelope_strategy(std::string const& wkt,
- const T& x1, const T& x2,
- const T& y1, const T& y2,
- const T& z1 = 0, const T& z2 = 0)
-{
- typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
 
     Geometry geometry;
     bg::read_wkt(wkt, geometry);
- box_type b;
     bg::envelope(geometry, b);
+ check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
 
+ boost::variant<Geometry> v(geometry);
+ bg::envelope(v, b);
     check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
 }
 
 
-
 #endif


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