From fb6625dafb68a489bb1cf0348cbe7629bb184fa7 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Tue, 15 Feb 2011 21:16:23 +0000 Subject: [PATCH] for_each_segment doc update (doc folder) [SVN r68931] --- doc/geometry.qbk | 1 + doc/other/testcases/dissolve.ppt | Bin 42496 -> 38912 bytes doc/reference/for_each.qbk | 7 +- doc/src/examples/algorithms/Jamfile.v2 | 1 + .../algorithms/for_each_segment_const.cpp | 94 ++++++++++++++++++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 doc/src/examples/algorithms/for_each_segment_const.cpp diff --git a/doc/geometry.qbk b/doc/geometry.qbk index 04dd78198..d817c6fd4 100644 --- a/doc/geometry.qbk +++ b/doc/geometry.qbk @@ -73,6 +73,7 @@ Simplify algorithm [link geometry.reference.algorithms.simplify.simplify_3 here] [import src/examples/algorithms/area_with_strategy.cpp] [import src/examples/algorithms/for_each_point.cpp] [import src/examples/algorithms/for_each_point_const.cpp] +[import src/examples/algorithms/for_each_segment_const.cpp] [import src/examples/algorithms/length.cpp] [import src/examples/algorithms/length_with_strategy.cpp] [import src/examples/algorithms/intersection_ls_ls_point.cpp] diff --git a/doc/other/testcases/dissolve.ppt b/doc/other/testcases/dissolve.ppt index 96c1e7bdd1538ea33ff9160fb3414dc13ed9637e..65757fc4cf7eef78ac3a96381b5358a44489efa5 100644 GIT binary patch delta 1312 zcmZoT!_=^WX@U)-!$#ZVjEr8BS((1`{QLj^KL|T9FfdH!V3wKGdS?<#E=O>zf!*2D zjE<8_S(=#+Rc-#o!o|p_H+fo9F-t;37Qo1e{| z&&bNkz`)?XxofT$3-1qY1_mV&1_qa}|Nkd#ez@=+G3jM%KFD$mShq5#&j zKA>Z=zNQe<6bN^|?TXFLT8FrqzJT~3(;Fv0F%x16Q3R_FFrUt}1;o5N`IvIu-1wjt9P8DJbQHL5>wOKK(iIK&`s+eJNU54J| ztLaNwrdSm-Y_7|2WMugQ5!RXfKJy(*h;=c;k3O*u9y`wZ2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BH``}8GP0N$fQ5A?Z^(SdG6lq`&o-HSEo&*u z7lS*Do9nYbGqOz41*-vRRhsOPZ$9~bI@e_OJPnpF5DCx8HF-rWA$oThCxbMr<#)4e zfpEMw|Ib%vlmx{)8z}x6cvzy?7#R2&m_7utF)##7wl6GYDKWakxOqq6KW3IIMt2w| zFZ2nR%vDy+Vqy&8Y`$4m!|0XF%D}+H@Sa(Mfq_8)DcLYGFf_}(@%#)dA0oi{gbQpXlL#Y& z0uuv+GXwVrkdx~fSQuCs_A@dvFf#lHlZ?zP9SoE8GZo!HzTsxL!w52?1<4GMO&~LZ z8Mr^lF)%RHGcYi)Ff=f1F}cHtY7%P)1H5wD-gjGhh!7e3P|uEyoNP+7&<^9jyI4%_F)U8DQ2_^q!r*ms_$Vx#rWXd z^cn_+B5@lAP#S_HOCAOR2F-K^1~~=+2JS=#215n`2G?u`1_uTKhTr9&5?z3yl$(Je zl0kuCLJ($6^gLPI_PamoW^ diff --git a/doc/reference/for_each.qbk b/doc/reference/for_each.qbk index 355d52ce8..2444d097c 100644 --- a/doc/reference/for_each.qbk +++ b/doc/reference/for_each.qbk @@ -42,7 +42,7 @@ Or `#include ` -[heading Examples] +[heading Example] [for_each_point] [for_each_point_output] @@ -77,7 +77,7 @@ Or `#include ` -[heading Examples] +[heading Example] [for_each_point_const] [for_each_point_const_output] @@ -144,6 +144,9 @@ Or `#include ` +[heading Example] +[for_each_segment_const] [for_each_segment_const_output] + [endsect] diff --git a/doc/src/examples/algorithms/Jamfile.v2 b/doc/src/examples/algorithms/Jamfile.v2 index 4469a2f94..1f933eba2 100644 --- a/doc/src/examples/algorithms/Jamfile.v2 +++ b/doc/src/examples/algorithms/Jamfile.v2 @@ -16,6 +16,7 @@ exe area_with_strategy : area_with_strategy.cpp ; exe for_each_point : for_each_point.cpp ; exe for_each_point_const : for_each_point_const.cpp ; +exe for_each_segment_const : for_each_segment_const.cpp ; exe intersection_ls_ls_point : intersection_ls_ls_point.cpp ; exe intersection_segment : intersection_segment.cpp ; diff --git a/doc/src/examples/algorithms/for_each_segment_const.cpp b/doc/src/examples/algorithms/for_each_segment_const.cpp new file mode 100644 index 000000000..dc74c4e8c --- /dev/null +++ b/doc/src/examples/algorithms/for_each_segment_const.cpp @@ -0,0 +1,94 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, Geodan, Amsterdam, the Netherlands +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// Quickbook Example + +//[for_each_segment_const +//` Sample using for_each_segment, using a functor to get the minimum and maximum length of a segment in a linestring + +#include + +#include +#include + +#include + + +template +struct gather_segment_statistics +{ + // Remember that if coordinates are integer, the length might be floating point + // So use "double" for integers. In other cases, use coordinate type + typedef typename boost::geometry::select_most_precise + < + typename boost::geometry::coordinate_type::type, + double + >::type type; + + type min_length, max_length; + + // Initialize min and max + gather_segment_statistics() + : min_length(1e38) + , max_length(-1) + {} + + // This operator is called for each segment + inline void operator()(Segment const& s) + { + type length = boost::geometry::length(s); + if (length < min_length) min_length = length; + if (length > max_length) max_length = length; + } +}; + +int main() +{ + // Bring "+=" for a vector into scope + using namespace boost::assign; + + // Define a type + typedef boost::geometry::model::d2::point_xy point; + + // Declare a linestring + boost::geometry::model::linestring polyline; + + // Use Boost.Assign to initialize a linestring + polyline += point(0, 0), point(3, 3), point(5, 1), point(6, 2), + point(8, 0), point(4, -4), point(1, -1), point(3, 2); + + + // Declare the gathering class... + gather_segment_statistics + < + boost::geometry::model::referring_segment + > functor; + + // ... and use it, the essention. + // As also in std::for_each it is a const value, so retrieve it as a return value. + functor = boost::geometry::for_each_segment(polyline, functor); + + // Output the results + std::cout + << "Min segment length: " << functor.min_length << std::endl + << "Max segment length: " << functor.max_length << std::endl; + + return 0; +} + +//] + + +//[for_each_segment_const_output +/*` +Output: +[pre +Min segment length: 1.41421 +Max segment length: 5.65685 +] +*/ +//]