• 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 //[correct
11 //` Shows how to correct a polygon with respect to its orientation and closure
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 
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)19 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
20 
21 #include <boost/assign.hpp>
22 
23 int main()
24 {
25     using boost::assign::tuple_list_of;
26 
27     typedef boost::geometry::model::polygon
28         <
29             boost::tuple<int, int>
30         > clockwise_closed_polygon;
31 
32     clockwise_closed_polygon cwcp;
33 
34     // Fill it counterclockwise (so wrongly), forgetting the closing point
35     boost::geometry::exterior_ring(cwcp) = tuple_list_of(0, 0)(10, 10)(0, 9);
36 
37     // Add a counterclockwise closed inner ring (this is correct)
38     boost::geometry::interior_rings(cwcp).push_back(tuple_list_of(1, 2)(4, 6)(2, 8)(1, 2));
39 
40     // Its area should be negative (because of wrong orientation)
41     //     and wrong (because of omitted closing point)
42     double area_before = boost::geometry::area(cwcp);
43 
44     // Correct it!
45     boost::geometry::correct(cwcp);
46 
47     // Check its new area
48     double area_after = boost::geometry::area(cwcp);
49 
50     // And output it
51     std::cout << boost::geometry::dsv(cwcp) << std::endl;
52     std::cout << area_before << " -> " << area_after << std::endl;
53 
54     return 0;
55 }
56 
57 //]
58 
59 
60 //[correct_output
61 /*`
62 Output:
63 [pre
64 (((0, 0), (0, 9), (10, 10), (0, 0)), ((1, 2), (4, 6), (2, 8), (1, 2)))
65 -7 -> 38
66 ]
67 */
68 //]
69