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

http://hadesmem.googlecode.com/ · C++ · 67 lines · 29 code · 18 blank · 20 comment · 0 complexity · c45647de9867eb0a5035c897a475288b 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. //[reverse
  8. //` Shows how to reverse a ring or polygon
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/polygon.hpp>
  12. #include <boost/geometry/geometries/ring.hpp>
  13. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  14. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  15. #include <boost/assign.hpp>
  16. int main()
  17. {
  18. using boost::assign::tuple_list_of;
  19. typedef boost::tuple<int, int> point;
  20. typedef boost::geometry::model::polygon<point> polygon;
  21. typedef boost::geometry::model::ring<point> ring;
  22. polygon poly;
  23. boost::geometry::exterior_ring(poly) = tuple_list_of(0, 0)(0, 9)(10, 10)(0, 0);
  24. boost::geometry::interior_rings(poly).push_back(tuple_list_of(1, 2)(4, 6)(2, 8)(1, 2));
  25. double area_before = boost::geometry::area(poly);
  26. boost::geometry::reverse(poly);
  27. double area_after = boost::geometry::area(poly);
  28. std::cout << boost::geometry::dsv(poly) << std::endl;
  29. std::cout << area_before << " -> " << area_after << std::endl;
  30. ring r = tuple_list_of(0, 0)(0, 9)(8, 8)(0, 0);
  31. area_before = boost::geometry::area(r);
  32. boost::geometry::reverse(r);
  33. area_after = boost::geometry::area(r);
  34. std::cout << boost::geometry::dsv(r) << std::endl;
  35. std::cout << area_before << " -> " << area_after << std::endl;
  36. return 0;
  37. }
  38. //]
  39. //[reverse_output
  40. /*`
  41. Output:
  42. [pre
  43. (((0, 0), (10, 10), (0, 9), (0, 0)), ((1, 2), (2, 8), (4, 6), (1, 2)))
  44. 38 -> -38
  45. ((0, 0), (8, 8), (0, 9), (0, 0))
  46. 36 -> -36
  47. ]
  48. */
  49. //]