PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 6ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 67 lines | 29 code | 18 blank | 20 comment | 0 complexity | c45647de9867eb0a5035c897a475288b 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
 8// http://www.boost.org/LICENSE_1_0.txt)
 9
10//[reverse
11//` Shows how to reverse a ring or polygon
12
13#include <iostream>
14
15#include <boost/geometry.hpp>
16#include <boost/geometry/geometries/polygon.hpp>
17#include <boost/geometry/geometries/ring.hpp>
18#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
19
20BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
21
22#include <boost/assign.hpp>
23
24int main()
25{
26    using boost::assign::tuple_list_of;
27
28    typedef boost::tuple<int, int> point;
29    typedef boost::geometry::model::polygon<point> polygon;
30    typedef boost::geometry::model::ring<point> ring;
31
32
33    polygon poly;
34    boost::geometry::exterior_ring(poly) = tuple_list_of(0, 0)(0, 9)(10, 10)(0, 0);
35    boost::geometry::interior_rings(poly).push_back(tuple_list_of(1, 2)(4, 6)(2, 8)(1, 2));
36
37    double area_before = boost::geometry::area(poly);
38    boost::geometry::reverse(poly);
39    double area_after = boost::geometry::area(poly);
40    std::cout << boost::geometry::dsv(poly) << std::endl;
41    std::cout << area_before << " -> " << area_after << std::endl;
42
43    ring r = tuple_list_of(0, 0)(0, 9)(8, 8)(0, 0);
44
45    area_before = boost::geometry::area(r);
46    boost::geometry::reverse(r);
47    area_after = boost::geometry::area(r);
48    std::cout << boost::geometry::dsv(r) << std::endl;
49    std::cout << area_before << " -> " << area_after << std::endl;
50
51    return 0;
52}
53
54//]
55
56
57//[reverse_output
58/*`
59Output:
60[pre
61(((0, 0), (10, 10), (0, 9), (0, 0)), ((1, 2), (2, 8), (4, 6), (1, 2)))
6238 -> -38
63((0, 0), (8, 8), (0, 9), (0, 0))
6436 -> -36
65]
66*/
67//]