• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // QuickBook Example
3 
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland.
6 
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 //[polygon
12 //` Declaration and use of the Boost.Geometry model::polygon, modelling the Polygon Concept
13 
14 #include <iostream>
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/geometries.hpp>
17 
18 namespace bg = boost::geometry;
19 
main()20 int main()
21 {
22     typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
23     typedef bg::model::polygon<point_t> polygon_t; /*< Default parameters, clockwise, closed polygon. >*/
24 
25     polygon_t poly1; /*< Default-construct a polygon. >*/
26 
27 #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \
28  && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
29 
30     polygon_t polygon2{{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}},
31                        {{1.0, 1.0}, {4.0, 1.0}, {4.0, 4.0}, {1.0, 4.0}, {1.0, 1.0}}}; /*< Construct a polygon containing an exterior and interior ring, using C++11 unified initialization syntax. >*/
32 
33 #endif
34 
35     bg::append(poly1.outer(), point_t(0.0, 0.0)); /*< Append point to the exterior ring. >*/
36     bg::append(poly1.outer(), point_t(0.0, 5.0));
37     bg::append(poly1.outer(), point_t(5.0, 5.0));
38     bg::append(poly1.outer(), point_t(5.0, 0.0));
39     bg::append(poly1.outer(), point_t(0.0, 0.0));
40 
41     poly1.inners().resize(1); /*< Resize a container of interior rings. >*/
42     bg::append(poly1.inners()[0], point_t(1.0, 1.0)); /*< Append point to the interior ring. >*/
43     bg::append(poly1.inners()[0], point_t(4.0, 1.0));
44     bg::append(poly1.inners()[0], point_t(4.0, 4.0));
45     bg::append(poly1.inners()[0], point_t(1.0, 4.0));
46     bg::append(poly1.inners()[0], point_t(1.0, 1.0));
47 
48     double a = bg::area(poly1);
49 
50     std::cout << a << std::endl;
51 
52     return 0;
53 }
54 
55 //]
56 
57 
58 //[polygon_output
59 /*`
60 Output:
61 [pre
62 16
63 ]
64 */
65 //]
66