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

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