Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85346 - in trunk: boost/geometry/algorithms libs/geometry/doc libs/geometry/test/algorithms
From: barend.gehrels_at_[hidden]
Date: 2013-08-14 11:31:47


Author: barendgehrels
Date: 2013-08-14 11:31:46 EDT (Wed, 14 Aug 2013)
New Revision: 85346
URL: http://svn.boost.org/trac/boost/changeset/85346

Log:
[geometry] added centroid calculation for segment type

Text files modified:
   trunk/boost/geometry/algorithms/centroid.hpp | 48 ++++++++++++++++++++++-----------------
   trunk/libs/geometry/doc/release_notes.qbk | 20 ++++++++++++++++
   trunk/libs/geometry/test/algorithms/centroid.cpp | 3 ++
   3 files changed, 50 insertions(+), 21 deletions(-)

Modified: trunk/boost/geometry/algorithms/centroid.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/centroid.hpp Wed Aug 14 11:31:14 2013 (r85345)
+++ trunk/boost/geometry/algorithms/centroid.hpp 2013-08-14 11:31:46 EDT (Wed, 14 Aug 2013) (r85346)
@@ -90,55 +90,56 @@
 
 template
 <
- typename Box,
+ typename Indexed,
     typename Point,
     std::size_t Dimension,
     std::size_t DimensionCount
>
-struct centroid_box_calculator
+struct centroid_indexed_calculator
 {
     typedef typename select_coordinate_type
         <
- Box, Point
+ Indexed, Point
>::type coordinate_type;
- static inline void apply(Box const& box, Point& centroid)
+ static inline void apply(Indexed const& indexed, Point& centroid)
     {
- coordinate_type const c1 = get<min_corner, Dimension>(box);
- coordinate_type const c2 = get<max_corner, Dimension>(box);
+ coordinate_type const c1 = get<min_corner, Dimension>(indexed);
+ coordinate_type const c2 = get<max_corner, Dimension>(indexed);
         coordinate_type m = c1 + c2;
- m /= 2.0;
+ coordinate_type const two = 2;
+ m /= two;
 
         set<Dimension>(centroid, m);
 
- centroid_box_calculator
+ centroid_indexed_calculator
             <
- Box, Point,
+ Indexed, Point,
                 Dimension + 1, DimensionCount
- >::apply(box, centroid);
+ >::apply(indexed, centroid);
     }
 };
 
 
-template<typename Box, typename Point, std::size_t DimensionCount>
-struct centroid_box_calculator<Box, Point, DimensionCount, DimensionCount>
+template<typename Indexed, typename Point, std::size_t DimensionCount>
+struct centroid_indexed_calculator<Indexed, Point, DimensionCount, DimensionCount>
 {
- static inline void apply(Box const& , Point& )
+ static inline void apply(Indexed const& , Point& )
     {
     }
 };
 
 
-struct centroid_box
+struct centroid_indexed
 {
- template<typename Box, typename Point, typename Strategy>
- static inline void apply(Box const& box, Point& centroid,
+ template<typename Indexed, typename Point, typename Strategy>
+ static inline void apply(Indexed const& indexed, Point& centroid,
             Strategy const&)
     {
- centroid_box_calculator
+ centroid_indexed_calculator
             <
- Box, Point,
- 0, dimension<Box>::type::value
- >::apply(box, centroid);
+ Indexed, Point,
+ 0, dimension<Indexed>::type::value
+ >::apply(indexed, centroid);
     }
 };
 
@@ -279,7 +280,12 @@
 
 template <typename Box>
 struct centroid<Box, box_tag>
- : detail::centroid::centroid_box
+ : detail::centroid::centroid_indexed
+{};
+
+template <typename Segment>
+struct centroid<Segment, segment_tag>
+ : detail::centroid::centroid_indexed
 {};
 
 template <typename Ring>

Modified: trunk/libs/geometry/doc/release_notes.qbk
==============================================================================
--- trunk/libs/geometry/doc/release_notes.qbk Wed Aug 14 11:31:14 2013 (r85345)
+++ trunk/libs/geometry/doc/release_notes.qbk 2013-08-14 11:31:46 EDT (Wed, 14 Aug 2013) (r85346)
@@ -14,6 +14,26 @@
 [section:release_notes Release Notes]
 
 [/=================]
+[heading Boost 1.55]
+[/=================]
+
+[*Additional functionality]
+
+* Added centroid for segment type
+
+[*Documentation]
+
+[*Bugfixes]
+
+[*Solved tickets]
+
+[*Internal changes]
+
+* Distance-strategy TODO
+* Transform-strategy TODO
+
+
+[/=================]
 [heading Boost 1.54]
 [/=================]
 

Modified: trunk/libs/geometry/test/algorithms/centroid.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/centroid.cpp Wed Aug 14 11:31:14 2013 (r85345)
+++ trunk/libs/geometry/test/algorithms/centroid.cpp 2013-08-14 11:31:46 EDT (Wed, 14 Aug 2013) (r85346)
@@ -51,6 +51,8 @@
     test_centroid<bg::model::linestring<P> >("LINESTRING(0 0,0 4, 4 4)", 1.0, 3.0);
     test_centroid<bg::model::linestring<P> >("LINESTRING(0 0,3 3,0 6,3 9,0 12)", 1.5, 6.0);
 
+ test_centroid<bg::model::segment<P> >("LINESTRING(1 1, 3 3)", 2.0, 2.0);
+
     test_centroid<bg::model::ring<P> >(
         "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2"
         ",3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3))",
@@ -82,6 +84,7 @@
     test_centroid<bg::model::linestring<P> >("LINESTRING(1 2 3,4 5 -6,7 -8 9,-10 11 12,13 -14 -15, 16 17 18)",
                                              5.6748865168734692, 0.31974938587214002, 1.9915270387763671);
     test_centroid<bg::model::box<P> >("POLYGON((1 2 3,5 6 7))", 3, 4, 5);
+ test_centroid<bg::model::segment<P> >("LINESTRING(1 1 1,3 3 3)", 2, 2, 2);
     test_centroid<P>("POINT(1 2 3)", 1, 2, 3);
 }
 


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