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

http://hadesmem.googlecode.com/ · C++ · 61 lines · 21 code · 18 blank · 22 comment · 0 complexity · 56761cb691298b541b1efe835ec9e35a 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. //[append
  8. //` Shows usage of Boost.Geometry's append to append a point or a range to a polygon
  9. #include <iostream>
  10. #include <boost/assign.hpp>
  11. #include <boost/geometry.hpp>
  12. #include <boost/geometry/geometries/polygon.hpp>
  13. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  14. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  15. int main()
  16. {
  17. using boost::assign::tuple_list_of;
  18. using boost::make_tuple;
  19. using boost::geometry::append;
  20. typedef boost::geometry::model::polygon<boost::tuple<int, int> > polygon;
  21. polygon poly;
  22. // Append a range
  23. append(poly, tuple_list_of(0, 0)(0, 10)(11, 11)(10, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::append >*/
  24. // Append a point (in this case the closing point
  25. append(poly, make_tuple(0, 0));
  26. // Create an interior ring (append does not do this automatically)
  27. boost::geometry::interior_rings(poly).resize(1);
  28. // Append a range to the interior ring
  29. append(poly, tuple_list_of(2, 2)(2, 5)(6, 6)(5, 2), 0);
  30. // Append a point to the first interior ring
  31. append(poly, make_tuple(2, 2), 0);
  32. std::cout << boost::geometry::dsv(poly) << std::endl;
  33. return 0;
  34. }
  35. //]
  36. //[append_output
  37. /*`
  38. Output:
  39. [pre
  40. (((0, 0), (0, 10), (11, 11), (10, 0), (0, 0)), ((2, 2), (2, 5), (6, 6), (5, 2), (2, 2)))
  41. ]
  42. */
  43. //]