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

http://hadesmem.googlecode.com/ · 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. // Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //[for_each_point_const
  8. //` Sample using for_each_point, using a function to list coordinates
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. #include <boost/geometry/geometries/polygon.hpp>
  13. #include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
  14. template <typename Point>
  15. void list_coordinates(Point const& p)
  16. {
  17. using boost::geometry::get;
  18. std::cout << "x = " << get<0>(p) << " y = " << get<1>(p) << std::endl;
  19. }
  20. int main()
  21. {
  22. typedef boost::geometry::model::d2::point_xy<double> point;
  23. boost::geometry::model::polygon<point> poly;
  24. boost::geometry::read_wkt("POLYGON((0 0,0 4,4 0,0 0))", poly);
  25. boost::geometry::for_each_point(poly, list_coordinates<point>);
  26. return 0;
  27. }
  28. //]
  29. //[for_each_point_const_output
  30. /*`
  31. Output:
  32. [pre
  33. x = 0 y = 0
  34. x = 0 y = 4
  35. x = 4 y = 0
  36. x = 0 y = 0
  37. ]
  38. */
  39. //]