Documentaton and samples for for_each

Fix - added default value in free functions

[SVN r68869]
This commit is contained in:
Barend Gehrels 2011-02-14 18:39:39 +00:00
parent a6883f4ca2
commit a35b43a9df
14 changed files with 172 additions and 23 deletions

View File

@ -57,6 +57,7 @@ ALIASES = qbk{1}="\xmlonly <qbk>\1</qbk> \endxmlonly" \
tparam_container="container type, for example std::vector, std::deque" \
tparam_dimension_required="Dimension, this template parameter is required. Should contain \[0 .. n-1\] for an n-dimensional geometry" \
tparam_first_point="first point type" \
tparam_functor="Function or class with operator()" \
tparam_geometry="Any type fulfilling a Geometry Concept" \
tparam_geometry{1}="A type fulfilling a \1 Concept" \
tparam_index_required="Index, this template parameter is required. For a Box: either min_corner or max_corner. For a Segment: either 0 or 1 for first or last point." \
@ -97,8 +98,11 @@ ALIASES = qbk{1}="\xmlonly <qbk>\1</qbk> \endxmlonly" \
return_check{1}="Returns true if the geometry \1" \
return_check2{1}="Returns true if two geometries \1" \
return_out="The output iterator" \
brf_for_each{1}="Applies function [*f] to each \1" \
det_envelope="envelope (also known as axis aligned bounding box, aabb, or minimum bounding rectangle, mbr)" \
det_buffer="buffer (a polygon being the spatial point set collection within a specified maximum distance from a geometry)" \
det_for_each{1}="Applies a function [*f] (functor, having operator() defined) to each \1 making up the geometry" \
par_for_each_f{1}="Unary function, taking a \1 as argument" \
macro_x="first (usually x)" \
macro_y="second (usually y)" \
macro_z="third (usually z)" \

View File

@ -71,6 +71,8 @@ Simplify algorithm [link geometry.reference.algorithms.simplify.simplify_3 here]
[import src/examples/quick_start.cpp]
[import src/examples/algorithms/area.cpp]
[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/length.cpp]
[import src/examples/algorithms/length_with_strategy.cpp]
[import src/examples/algorithms/intersection_ls_ls_point.cpp]

View File

@ -352,6 +352,10 @@
<simplelist type="vert" columns="1">
<member><link linkend="geometry.reference.algorithms.envelope">envelope</link></member>
</simplelist>
<bridgehead renderas="sect3">For Each</bridgehead>
<simplelist type="vert" columns="1">
<member><link linkend="geometry.reference.algorithms.for_each">for each (point, segment)</link></member>
</simplelist>
<bridgehead renderas="sect3">Intersection</bridgehead>
<simplelist type="vert" columns="1">
<member><link linkend="geometry.reference.algorithms.intersection">intersection</link></member>

View File

@ -18,7 +18,7 @@
[[__box__][[qbk_ret 4]]]
[[__range__][[qbk_ret boost::size(geometry)]]]
[[__other__][[qbk_ret the sum of the number of points of its elements]]]
[[Open geometries][[qbk_ret the sum of the number of points of its elements, it adds one for open if specified]]]
[[Open geometries][[qbk_ret the sum of the number of points of its elements, it adds one for open (per ring) if specified]]]
[[Closed geometries][[qbk_ret the sum of the number of points of its elements]]]
]

View File

@ -109,9 +109,9 @@
[include reference/equals.qbk]
[endsect]
[/section:for_each for_each]
[/include reference/for_each.qbk]
[/endsect]
[section:for_each for_each]
[include reference/for_each.qbk]
[endsect]
[section:intersection intersection]
[include reference/intersection.qbk]

View File

@ -19,7 +19,7 @@ Appends one or more points to a linestring, ring, polygon, multi.
[heading Synopsis]
``template<typename Geometry, typename RoP>
void append(Geometry & geometry, RoP const & range_or_point, int ring_index, int multi_index)``
void append(Geometry & geometry, RoP const & range_or_point, int ring_index = -1, int multi_index = 0)``
[heading Parameters]

View File

@ -22,7 +22,7 @@ The free function buffer calculates the buffer (a polygon being the spatial poin
[heading Synopsis]
``template<typename Input, typename Output, typename Distance>
void buffer(Input const & geometry_in, Output & geometry_out, Distance const & distance, Distance const & chord_length)``
void buffer(Input const & geometry_in, Output & geometry_out, Distance const & distance, Distance const & chord_length = -1)``
[heading Parameters]
@ -58,7 +58,7 @@ The free function make_buffer calculates the buffer (a polygon being the spatial
[heading Synopsis]
``template<typename Output, typename Input, typename T, >
Output make_buffer(Input const & geometry, T const & distance, T const & chord_length)``
Output make_buffer(Input const & geometry, T const & distance, T const & chord_length = -1)``
[heading Parameters]

View File

@ -36,7 +36,7 @@ class strategy::distance::haversine
[heading Constructor(s)]
[table
[[Function] [Description] [Parameters] ]
[[``haversine( const & radius)``
[[``haversine( const & radius = 1.0)``
] [Constructor. ] [[* const &]: ['radius]: radius of the sphere, defaults to 1.0 for the unit sphere

View File

@ -15,7 +15,10 @@
[/ Generated from doxy/doxygen_output/xml/group__for__each.xml]
[section:for_each_point_2 for_each_point]
Calls functor for geometry.
Applies function [*f] to each point.
[heading Description]
Applies a function [*f] (functor, having operator() defined) to each point making up the geometry
[heading Synopsis]
``template<typename Geometry, typename Functor>
@ -25,8 +28,8 @@ Functor for_each_point(Geometry & geometry, Functor f)``
[table
[[Type] [Concept] [Name] [Description] ]
[[Geometry &] [] [geometry] [geometry to loop through ]]
[[Functor] [] [f] [functor to use]]
[[Geometry &] [Any type fulfilling a Geometry Concept ] [geometry] [A model of the specified concept ]]
[[Functor] [Function or class with operator()] [f] [Unary function, taking a point as argument ]]
]
@ -39,12 +42,18 @@ Or
`#include <boost/geometry/algorithms/for_each.hpp>`
[heading Examples]
[for_each_point] [for_each_point_output]
[endsect]
[section:for_each_point_2 for_each_point]
[section:for_each_point_2_const_version for_each_point (const version)]
Calls functor for geometry.
Applies function [*f] to each point.
[heading Description]
Applies a function [*f] (functor, having operator() defined) to each point making up the geometry
[heading Synopsis]
``template<typename Geometry, typename Functor>
@ -54,8 +63,8 @@ Functor for_each_point(Geometry const & geometry, Functor f)``
[table
[[Type] [Concept] [Name] [Description] ]
[[Geometry const &] [] [geometry] [geometry to loop through ]]
[[Functor] [] [f] [functor to use]]
[[Geometry const &] [Any type fulfilling a Geometry Concept ] [geometry] [A model of the specified concept ]]
[[Functor] [Function or class with operator()] [f] [Unary function, taking a const point as argument ]]
]
@ -68,12 +77,18 @@ Or
`#include <boost/geometry/algorithms/for_each.hpp>`
[heading Examples]
[for_each_point_const] [for_each_point_const_output]
[endsect]
[section:for_each_segment_2 for_each_segment]
Calls functor for segments on linestrings, rings, polygons, ...
Applies function [*f] to each segment.
[heading Description]
Applies a function [*f] (functor, having operator() defined) to each segment making up the geometry
[heading Synopsis]
``template<typename Geometry, typename Functor>
@ -83,8 +98,8 @@ Functor for_each_segment(Geometry & geometry, Functor f)``
[table
[[Type] [Concept] [Name] [Description] ]
[[Geometry &] [] [geometry] [geometry to loop through ]]
[[Functor] [] [f] [functor to use]]
[[Geometry &] [Any type fulfilling a Geometry Concept ] [geometry] [A model of the specified concept ]]
[[Functor] [Function or class with operator() ] [f] [Unary function, taking a segment as argument ]]
]
@ -100,9 +115,12 @@ Or
[endsect]
[section:for_each_segment_2 for_each_segment]
[section:for_each_segment_2_const_version for_each_segment (const version)]
Calls functor for segments on linestrings, rings, polygons, ...
Applies function [*f] to each segment.
[heading Description]
Applies a function [*f] (functor, having operator() defined) to each segment making up the geometry
[heading Synopsis]
``template<typename Geometry, typename Functor>
@ -112,8 +130,8 @@ Functor for_each_segment(Geometry const & geometry, Functor f)``
[table
[[Type] [Concept] [Name] [Description] ]
[[Geometry const &] [] [geometry] [geometry to loop through ]]
[[Functor] [] [f] [functor to use]]
[[Geometry const &] [Any type fulfilling a Geometry Concept ] [geometry] [A model of the specified concept ]]
[[Functor] [Function or class with operator()] [f] [Unary function, taking a const segment as argument ]]
]

View File

@ -22,7 +22,7 @@ The free function num_points calculates the number of points of a geometry.
[heading Synopsis]
``template<typename Geometry>
std::size_t num_points(Geometry const & geometry, bool add_for_open)``
std::size_t num_points(Geometry const & geometry, bool add_for_open = false)``
[heading Parameters]

View File

@ -41,6 +41,7 @@ static inline void add_or_set(std::vector<parameter>& parameters, parameter cons
if (it->brief_description.empty()) it->brief_description = p.brief_description;
if (it->type.empty()) it->type = p.type;
if (it->fulltype.empty()) it->fulltype = p.fulltype;
if (it->default_value.empty()) it->default_value = p.default_value;
}
else
{

View File

@ -14,6 +14,9 @@ project boost-geometry-doc-example-algorithms
exe area : area.cpp ;
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 intersection_ls_ls_point : intersection_ls_ls_point.cpp ;
exe intersection_segment : intersection_segment.cpp ;

View File

@ -0,0 +1,68 @@
// 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_point
//` Convenient usage of for_each_point, rounding all points of a geometry
#include <iostream>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
template <typename Point>
class round_coordinates
{
private :
typedef typename boost::geometry::coordinate_type<Point>::type coordinate_type;
coordinate_type factor;
inline coordinate_type round(coordinate_type value)
{
return floor(0.5 + (value / factor)) * factor;
}
public :
round_coordinates(coordinate_type f)
: factor(f)
{}
inline void operator()(Point& p)
{
using boost::geometry::get;
using boost::geometry::set;
set<0>(p, round(get<0>(p)));
set<1>(p, round(get<1>(p)));
}
};
int main()
{
typedef boost::geometry::model::d2::point_xy<double> point;
boost::geometry::model::polygon<point> poly;
boost::geometry::read_wkt("POLYGON((0 0,1.123 9.987,8.876 2.234,0 0),(3.345 4.456,7.654 8.765,9.123 5.432,3.345 4.456))", poly);
boost::geometry::for_each_point(poly, round_coordinates<point>(0.1));
std::cout << "Rounded: " << boost::geometry::wkt(poly) << std::endl;
return 0;
}
//]
//[for_each_point_output
/*`
Output:
[pre
Rounded: POLYGON((0 0,1.1 10,8.9 2.2,0 0),(3.3 4.5,7.7 8.8,9.1 5.4,3.3 4.5))
]
*/
//]

View File

@ -0,0 +1,49 @@
// 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_point_const
//` Sample using for_each_point, using a function to list coordinates
#include <iostream>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
template <typename Point>
void list_coordinates(Point const& p)
{
using boost::geometry::get;
std::cout << "x = " << get<0>(p) << " y = " << get<1>(p) << std::endl;
}
int main()
{
typedef boost::geometry::model::d2::point_xy<double> point;
boost::geometry::model::polygon<point> poly;
boost::geometry::read_wkt("POLYGON((0 0,0 4,4 0,0 0))", poly);
boost::geometry::for_each_point(poly, list_coordinates<point>);
return 0;
}
//]
//[for_each_point_const_output
/*`
Output:
[pre
x = 0 y = 0
x = 0 y = 4
x = 4 y = 0
x = 0 y = 0
]
*/
//]