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

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
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//[append
11//` Shows usage of Boost.Geometry's append to append a point or a range to a polygon
12
13#include <iostream>
14
15#include <boost/assign.hpp>
16
17#include <boost/geometry.hpp>
18#include <boost/geometry/geometries/polygon.hpp>
20
21BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
22
23int main()
24{
25    using boost::assign::tuple_list_of;
26    using boost::make_tuple;
27    using boost::geometry::append;
28
29    typedef boost::geometry::model::polygon<boost::tuple<int, int> > polygon;
30
31    polygon poly;
32
33    // Append a range
34    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 >*/
35    // Append a point (in this case the closing point
36    append(poly, make_tuple(0, 0));
37
38    // Create an interior ring (append does not do this automatically)
39    boost::geometry::interior_rings(poly).resize(1);
40
41    // Append a range to the interior ring
42    append(poly, tuple_list_of(2, 2)(2, 5)(6, 6)(5, 2), 0);
43    // Append a point to the first interior ring
44    append(poly, make_tuple(2, 2), 0);
45
46    std::cout << boost::geometry::dsv(poly) << std::endl;
47
48    return 0;
49}
50
51//]
52
53
54//[append_output
55/*`
56Output:
57[pre
58(((0, 0), (0, 10), (11, 11), (10, 0), (0, 0)), ((2, 2), (2, 5), (6, 6), (5, 2), (2, 2)))
59]
60*/
61//]
```