• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3 
4 // Copyright (c) 2011-2012 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
8 // http://www.boost.org/LICENSE_1_0.txt)
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/geometry.hpp>
16 #include <boost/geometry/geometries/polygon.hpp>
17 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
18 
19 #include <boost/assign.hpp> /*< At the end to avoid conflicts with Boost.QVM >*/
20 
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)21 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
22 
23 int 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); /*< The last parameter ring_index 0 denotes the first interior ring >*/
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 /*`
56 Output:
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 //]
62