• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3 
4 // Copyright (c) 2011-2012 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
8 // http://www.boost.org/LICENSE_1_0.txt)
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 
19 
20 template <typename Point>
list_coordinates(Point const & p)21 void list_coordinates(Point const& p)
22 {
23     using boost::geometry::get;
24     std::cout << "x = " << get<0>(p) << " y = " << get<1>(p) << std::endl;
25 }
26 
main()27 int main()
28 {
29     typedef boost::geometry::model::d2::point_xy<double> point;
30     boost::geometry::model::polygon<point> poly;
31     boost::geometry::read_wkt("POLYGON((0 0,0 4,4 0,0 0))", poly);
32     boost::geometry::for_each_point(poly, list_coordinates<point>);
33     return 0;
34 }
35 
36 //]
37 
38 
39 //[for_each_point_const_output
40 /*`
41 Output:
42 [pre
43 x = 0 y = 0
44 x = 0 y = 4
45 x = 4 y = 0
46 x = 0 y = 0
47 ]
48 */
49 //]
50