Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80366 - in trunk/boost/geometry: algorithms algorithms/detail multi/algorithms multi/algorithms/detail
From: bruno.lalande_at_[hidden]
Date: 2012-09-02 17:14:51


Author: bruno.lalande
Date: 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
New Revision: 80366
URL: http://svn.boost.org/trac/boost/changeset/80366

Log:
Moved Strategy from class to function level in dispatch::area. Preliminary change for integration of variant geometry.
Text files modified:
   trunk/boost/geometry/algorithms/area.hpp | 111 +++++++++++++--------------------------
   trunk/boost/geometry/algorithms/correct.hpp | 4 -
   trunk/boost/geometry/algorithms/detail/calculate_null.hpp | 2
   trunk/boost/geometry/algorithms/detail/calculate_sum.hpp | 12 +---
   trunk/boost/geometry/algorithms/length.hpp | 14 ++--
   trunk/boost/geometry/algorithms/perimeter.hpp | 35 ++++++-----
   trunk/boost/geometry/multi/algorithms/area.hpp | 29 +++++-----
   trunk/boost/geometry/multi/algorithms/detail/multi_sum.hpp | 8 --
   trunk/boost/geometry/multi/algorithms/length.hpp | 32 ++++++-----
   trunk/boost/geometry/multi/algorithms/perimeter.hpp | 31 ++++++-----
   10 files changed, 119 insertions(+), 159 deletions(-)

Modified: trunk/boost/geometry/algorithms/area.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/area.hpp (original)
+++ trunk/boost/geometry/algorithms/area.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -49,41 +49,33 @@
 namespace detail { namespace area
 {
 
-template<typename Box, typename Strategy>
 struct box_area
 {
- typedef typename coordinate_type<Box>::type return_type;
-
- static inline return_type apply(Box const& box, Strategy const&)
+ template <typename Box, typename Strategy>
+ static inline typename coordinate_type<Box>::type
+ apply(Box const& box, Strategy const&)
     {
         // Currently only works for 2D Cartesian boxes
         assert_dimension<Box, 2>();
 
- return_type const dx = get<max_corner, 0>(box)
- - get<min_corner, 0>(box);
- return_type const dy = get<max_corner, 1>(box)
- - get<min_corner, 1>(box);
-
- return dx * dy;
+ return (get<max_corner, 0>(box) - get<min_corner, 0>(box))
+ * (get<max_corner, 1>(box) - get<min_corner, 1>(box));
     }
 };
 
 
 template
 <
- typename Ring,
     iterate_direction Direction,
- closure_selector Closure,
- typename Strategy
+ closure_selector Closure
>
 struct ring_area
 {
- BOOST_CONCEPT_ASSERT( (geometry::concept::AreaStrategy<Strategy>) );
-
- typedef typename Strategy::return_type type;
-
- static inline type apply(Ring const& ring, Strategy const& strategy)
+ template <typename Ring, typename Strategy>
+ static inline typename Strategy::return_type
+ apply(Ring const& ring, Strategy const& strategy)
     {
+ BOOST_CONCEPT_ASSERT( (geometry::concept::AreaStrategy<Strategy>) );
         assert_dimension<Ring, 2>();
 
         // Ignore warning (because using static method sometimes) on strategy
@@ -95,7 +87,7 @@
         if (int(boost::size(ring))
                 < core_detail::closure::minimum_ring_size<Closure>::value)
         {
- return type();
+ return typename Strategy::return_type();
         }
 
         typedef typename reversible_view<Ring const, Direction>::type rview_type;
@@ -136,71 +128,49 @@
 template
 <
     typename Geometry,
- typename Strategy = typename strategy::area::services::default_strategy
- <
- typename cs_tag
- <
- typename point_type<Geometry>::type
- >::type,
- typename point_type<Geometry>::type
- >::type,
     typename Tag = typename tag<Geometry>::type
>
-struct area
- : detail::calculate_null
- <
- typename Strategy::return_type,
- Geometry,
- Strategy
- > {};
+struct area : detail::calculate_null
+{
+ template <typename Strategy>
+ static inline typename Strategy::return_type apply(Geometry const& geometry, Strategy const& strategy)
+ {
+ return calculate_null::apply<typename Strategy::return_type>(geometry, strategy);
+ }
+};
 
 
-template
-<
- typename Geometry,
- typename Strategy
->
-struct area<Geometry, Strategy, box_tag>
- : detail::area::box_area<Geometry, Strategy>
+template <typename Geometry>
+struct area<Geometry, box_tag> : detail::area::box_area
 {};
 
 
-template
-<
- typename Ring,
- typename Strategy
->
-struct area<Ring, Strategy, ring_tag>
+template <typename Ring>
+struct area<Ring, ring_tag>
     : detail::area::ring_area
         <
- Ring,
             order_as_direction<geometry::point_order<Ring>::value>::value,
- geometry::closure<Ring>::value,
- Strategy
+ geometry::closure<Ring>::value
>
 {};
 
 
-template
-<
- typename Polygon,
- typename Strategy
->
-struct area<Polygon, Strategy, polygon_tag>
- : detail::calculate_polygon_sum
- <
+template <typename Polygon>
+struct area<Polygon, polygon_tag> : detail::calculate_polygon_sum
+{
+ template <typename Strategy>
+ static inline typename Strategy::return_type apply(Polygon const& polygon, Strategy const& strategy)
+ {
+ return calculate_polygon_sum::apply<
             typename Strategy::return_type,
- Polygon,
- Strategy,
             detail::area::ring_area
                 <
- typename ring_type<Polygon const>::type,
                     order_as_direction<geometry::point_order<Polygon>::value>::value,
- geometry::closure<Polygon>::value,
- Strategy
+ geometry::closure<Polygon>::value
>
- >
-{};
+ >(polygon, strategy);
+ }
+};
 
 
 } // namespace dispatch
@@ -243,10 +213,7 @@
 
     // detail::throw_on_empty_input(geometry);
         
- return dispatch::area
- <
- Geometry
- >::apply(geometry, strategy_type());
+ return dispatch::area<Geometry>::apply(geometry, strategy_type());
 }
 
 /*!
@@ -281,11 +248,7 @@
 
     // detail::throw_on_empty_input(geometry);
     
- return dispatch::area
- <
- Geometry,
- Strategy
- >::apply(geometry, strategy);
+ return dispatch::area<Geometry>::apply(geometry, strategy);
 }
 
 

Modified: trunk/boost/geometry/algorithms/correct.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/correct.hpp (original)
+++ trunk/boost/geometry/algorithms/correct.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -119,10 +119,8 @@
 
     typedef detail::area::ring_area
             <
- Ring,
                 order_as_direction<geometry::point_order<Ring>::value>::value,
- geometry::closure<Ring>::value,
- strategy_type
+ geometry::closure<Ring>::value
> ring_area_type;
 
 

Modified: trunk/boost/geometry/algorithms/detail/calculate_null.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/calculate_null.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/calculate_null.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -21,9 +21,9 @@
 namespace detail
 {
 
-template<typename ReturnType, typename Geometry, typename Strategy>
 struct calculate_null
 {
+ template<typename ReturnType, typename Geometry, typename Strategy>
     static inline ReturnType apply(Geometry const& , Strategy const&)
     {
         return ReturnType();

Modified: trunk/boost/geometry/algorithms/detail/calculate_sum.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/calculate_sum.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/calculate_sum.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -26,16 +26,9 @@
 {
 
 
-template
-<
- typename ReturnType,
- typename Polygon,
- typename Strategy,
- typename Policy
->
 class calculate_polygon_sum
 {
- template <typename Rings>
+ template <typename ReturnType, typename Policy, typename Rings, typename Strategy>
     static inline ReturnType sum_interior_rings(Rings const& rings, Strategy const& strategy)
     {
         ReturnType sum = ReturnType();
@@ -47,10 +40,11 @@
     }
 
 public :
+ template <typename ReturnType, typename Policy, typename Polygon, typename Strategy>
     static inline ReturnType apply(Polygon const& poly, Strategy const& strategy)
     {
         return Policy::apply(exterior_ring(poly), strategy)
- + sum_interior_rings(interior_rings(poly), strategy)
+ + sum_interior_rings<ReturnType, Policy>(interior_rings(poly), strategy)
             ;
     }
 };

Modified: trunk/boost/geometry/algorithms/length.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/length.hpp (original)
+++ trunk/boost/geometry/algorithms/length.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -108,12 +108,14 @@
 
 template <typename Tag, typename Geometry, typename Strategy>
 struct length : detail::calculate_null
- <
- typename default_length_result<Geometry>::type,
- Geometry,
- Strategy
- >
-{};
+{
+ typedef typename default_length_result<Geometry>::type return_type;
+
+ static inline return_type apply(Geometry const& geometry, Strategy const& strategy)
+ {
+ return calculate_null::apply<return_type>(geometry, strategy);
+ }
+};
 
 
 template <typename Geometry, typename Strategy>

Modified: trunk/boost/geometry/algorithms/perimeter.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/perimeter.hpp (original)
+++ trunk/boost/geometry/algorithms/perimeter.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -35,12 +35,14 @@
 // Default perimeter is 0.0, specializations implement calculated values
 template <typename Tag, typename Geometry, typename Strategy>
 struct perimeter : detail::calculate_null
- <
- typename default_length_result<Geometry>::type,
- Geometry,
- Strategy
- >
-{};
+{
+ typedef typename default_length_result<Geometry>::type return_type;
+
+ static inline return_type apply(Geometry const& geometry, Strategy const& strategy)
+ {
+ return calculate_null::apply<return_type>(geometry, strategy);
+ }
+};
 
 template <typename Geometry, typename Strategy>
 struct perimeter<ring_tag, Geometry, Strategy>
@@ -53,20 +55,21 @@
 {};
 
 template <typename Polygon, typename Strategy>
-struct perimeter<polygon_tag, Polygon, Strategy>
- : detail::calculate_polygon_sum
- <
- typename default_length_result<Polygon>::type,
- Polygon,
- Strategy,
- detail::length::range_length
+struct perimeter<polygon_tag, Polygon, Strategy> : detail::calculate_polygon_sum
+{
+ typedef typename default_length_result<Polygon>::type return_type;
+ typedef detail::length::range_length
                 <
                     typename ring_type<Polygon>::type,
                     Strategy,
                     closure<Polygon>::value
- >
- >
-{};
+ > policy;
+
+ static inline return_type apply(Polygon const& polygon, Strategy const& strategy)
+ {
+ return calculate_polygon_sum::apply<return_type, policy>(polygon, strategy);
+ }
+};
 
 
 // box,n-sphere: to be implemented

Modified: trunk/boost/geometry/multi/algorithms/area.hpp
==============================================================================
--- trunk/boost/geometry/multi/algorithms/area.hpp (original)
+++ trunk/boost/geometry/multi/algorithms/area.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -30,21 +30,20 @@
 #ifndef DOXYGEN_NO_DISPATCH
 namespace dispatch
 {
-template <typename MultiGeometry, typename Strategy>
-struct area<MultiGeometry, Strategy, multi_polygon_tag>
- : detail::multi_sum
- <
- typename Strategy::return_type,
- MultiGeometry,
- Strategy,
- area
- <
- typename boost::range_value<MultiGeometry>::type,
- Strategy,
- polygon_tag
- >
- >
-{};
+template <typename MultiGeometry>
+struct area<MultiGeometry, multi_polygon_tag> : detail::multi_sum
+{
+ template <typename Strategy>
+ static inline typename Strategy::return_type
+ apply(MultiGeometry const& multi, Strategy const& strategy)
+ {
+ return multi_sum::apply
+ <
+ typename Strategy::return_type,
+ area<typename boost::range_value<MultiGeometry>::type>
+ >(multi, strategy);
+ }
+};
 
 
 } // namespace dispatch

Modified: trunk/boost/geometry/multi/algorithms/detail/multi_sum.hpp
==============================================================================
--- trunk/boost/geometry/multi/algorithms/detail/multi_sum.hpp (original)
+++ trunk/boost/geometry/multi/algorithms/detail/multi_sum.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -23,15 +23,9 @@
 namespace detail
 {
 
-template
-<
- typename ReturnType,
- typename MultiGeometry,
- typename Strategy,
- typename Policy
->
 struct multi_sum
 {
+ template <typename ReturnType, typename Policy, typename MultiGeometry, typename Strategy>
     static inline ReturnType apply(MultiGeometry const& geometry, Strategy const& strategy)
     {
         ReturnType sum = ReturnType();

Modified: trunk/boost/geometry/multi/algorithms/length.hpp
==============================================================================
--- trunk/boost/geometry/multi/algorithms/length.hpp (original)
+++ trunk/boost/geometry/multi/algorithms/length.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -31,20 +31,24 @@
 {
 
 template <typename MultiLinestring, typename Strategy>
-struct length<multi_linestring_tag, MultiLinestring, Strategy>
- : detail::multi_sum
- <
- typename default_length_result<MultiLinestring>::type,
- MultiLinestring,
- Strategy,
- detail::length::range_length
- <
- typename boost::range_value<MultiLinestring>::type,
- Strategy,
- closed // no need to close it explicitly
- >
- >
-{};
+struct length<multi_linestring_tag, MultiLinestring, Strategy> : detail::multi_sum
+{
+ static inline typename default_length_result<MultiLinestring>::type
+ apply(MultiLinestring const& multi, Strategy const& strategy)
+ {
+ return multi_sum::apply
+ <
+ typename default_length_result<MultiLinestring>::type,
+ detail::length::range_length
+ <
+ typename boost::range_value<MultiLinestring>::type,
+ Strategy,
+ closed // no need to close it explicitly
+ >
+ >(multi, strategy);
+
+ }
+};
 
 
 } // namespace dispatch

Modified: trunk/boost/geometry/multi/algorithms/perimeter.hpp
==============================================================================
--- trunk/boost/geometry/multi/algorithms/perimeter.hpp (original)
+++ trunk/boost/geometry/multi/algorithms/perimeter.hpp 2012-09-02 17:14:49 EDT (Sun, 02 Sep 2012)
@@ -31,20 +31,23 @@
 namespace dispatch
 {
 template <typename MultiPolygon, typename Strategy>
-struct perimeter<multi_polygon_tag, MultiPolygon, Strategy>
- : detail::multi_sum
- <
- typename default_length_result<MultiPolygon>::type,
- MultiPolygon,
- Strategy,
- perimeter
- <
- polygon_tag,
- typename boost::range_value<MultiPolygon>::type,
- Strategy
- >
- >
-{};
+struct perimeter<multi_polygon_tag, MultiPolygon, Strategy> : detail::multi_sum
+{
+ static inline typename default_length_result<MultiPolygon>::type
+ apply(MultiPolygon const& multi, Strategy const& strategy)
+ {
+ return multi_sum::apply
+ <
+ typename default_length_result<MultiPolygon>::type,
+ perimeter
+ <
+ polygon_tag,
+ typename boost::range_value<MultiPolygon>::type,
+ Strategy
+ >
+ >(multi, strategy);
+ }
+};
 
 } // namespace dispatch
 #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