/Src/Dependencies/Boost/libs/geometry/doc/src/examples/core/rings.cpp

http://hadesmem.googlecode.com/ · C++ · 77 lines · 31 code · 18 blank · 28 comment · 0 complexity · d58da1b47cd7918d308279d2e1f7e5b6 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. //[rings
  8. /*`
  9. Shows how to access the exterior ring (one)
  10. and interior rings (zero or more) of a polygon.
  11. Also shows the related ring_type and interior_type.
  12. */
  13. #include <iostream>
  14. #include <boost/geometry.hpp>
  15. #include <boost/geometry/geometries/polygon.hpp>
  16. #include <boost/geometry/geometries/point_xy.hpp>
  17. int main()
  18. {
  19. typedef boost::geometry::model::d2::point_xy<double> point;
  20. typedef boost::geometry::model::polygon<point> polygon_type;
  21. polygon_type poly;
  22. typedef boost::geometry::ring_type<polygon_type>::type ring_type;
  23. ring_type& ring = boost::geometry::exterior_ring(poly);
  24. // For a ring of model::polygon, you can call "push_back".
  25. // (internally, it is done using a traits::push_back class)
  26. ring.push_back(point(0, 0));
  27. ring.push_back(point(0, 5));
  28. ring.push_back(point(5, 4));
  29. ring.push_back(point(0, 0));
  30. ring_type inner;
  31. inner.push_back(point(1, 1));
  32. inner.push_back(point(2, 1));
  33. inner.push_back(point(2, 2));
  34. inner.push_back(point(1, 1));
  35. typedef boost::geometry::interior_type<polygon_type>::type int_type;
  36. int_type& interiors = boost::geometry::interior_rings(poly);
  37. interiors.push_back(inner);
  38. std::cout << boost::geometry::dsv(poly) << std::endl;
  39. // So int_type defines a collection of rings,
  40. // which is a Boost.Range compatible range
  41. // The type of an element of the collection is the very same ring type again.
  42. // We show that.
  43. typedef boost::range_value<int_type>::type int_ring_type;
  44. std::cout
  45. << std::boolalpha
  46. << boost::is_same<ring_type, int_ring_type>::value
  47. << std::endl;
  48. return 0;
  49. }
  50. //]
  51. //[rings_output
  52. /*`
  53. Output:
  54. [pre
  55. (((0, 0), (0, 5), (5, 4), (0, 0)), ((1, 1), (2, 1), (2, 2), (1, 1)))
  56. true
  57. ]
  58. */
  59. //]