/Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/for_each_point_const.cpp

C++ | 50 lines | 19 code | 11 blank | 20 comment | 0 complexity | feff4d3adf9a44340a8af80cd0f19360 MD5 | raw file
``` 1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// QuickBook Example
3
4// Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
5
6// Use, modification and distribution is subject to the Boost Software License,
7// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9
10//[for_each_point_const
11//` Sample using for_each_point, using a function to list coordinates
12
13#include <iostream>
14
15#include <boost/geometry.hpp>
16#include <boost/geometry/geometries/point_xy.hpp>
17#include <boost/geometry/geometries/polygon.hpp>
18#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
19
20
21template <typename Point>
22void list_coordinates(Point const& p)
23{
24    using boost::geometry::get;
25    std::cout << "x = " << get<0>(p) << " y = " << get<1>(p) << std::endl;
26}
27
28int main()
29{
30    typedef boost::geometry::model::d2::point_xy<double> point;
31    boost::geometry::model::polygon<point> poly;
32    boost::geometry::read_wkt("POLYGON((0 0,0 4,4 0,0 0))", poly);
33    boost::geometry::for_each_point(poly, list_coordinates<point>);
34    return 0;
35}
36
37//]
38
39
40//[for_each_point_const_output
41/*`
42Output:
43[pre
44x = 0 y = 0
45x = 0 y = 4
46x = 4 y = 0
47x = 0 y = 0
48]
49*/
50//]
```