• 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 // Copyright (c) 2014 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 //[boost_polygon_polygon
12 //`Shows how to use Boost.Polygon polygon_with_holes_data within Boost.Geometry
13 
14 #include <iostream>
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/adapted/boost_polygon.hpp>
17 
main()18 int main()
19 {
20     typedef boost::polygon::polygon_with_holes_data<int> polygon;
21     typedef boost::polygon::polygon_traits<polygon>::point_type point;
22     typedef boost::polygon::polygon_with_holes_traits<polygon>::hole_type hole;
23 
24     point pts[5] = {
25         boost::polygon::construct<point>(0, 0),
26         boost::polygon::construct<point>(0, 10),
27         boost::polygon::construct<point>(10, 10),
28         boost::polygon::construct<point>(10, 0),
29         boost::polygon::construct<point>(0, 0)
30     };
31     point hole_pts[5] = {
32         boost::polygon::construct<point>(1, 1),
33         boost::polygon::construct<point>(9, 1),
34         boost::polygon::construct<point>(9, 9),
35         boost::polygon::construct<point>(1, 9),
36         boost::polygon::construct<point>(1, 1)
37     };
38 
39     hole hls[1];
40     boost::polygon::set_points(hls[0], hole_pts, hole_pts+5);
41 
42     polygon poly;
43     boost::polygon::set_points(poly, pts, pts+5);
44     boost::polygon::set_holes(poly, hls, hls+1);
45 
46     std::cout << "Area (using Boost.Geometry): "
47         << boost::geometry::area(poly) << std::endl;
48     std::cout << "Area (using Boost.Polygon): "
49         << boost::polygon::area(poly) << std::endl;
50 
51     return 0;
52 }
53 
54 //]
55 
56 //[boost_polygon_polygon_output
57 /*`
58 Output:
59 [pre
60 Area (using Boost.Geometry): 36
61 Area (using Boost.Polygon): 36
62 ]
63 */
64 //]
65