]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/example/04_boost_example.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / example / 04_boost_example.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
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 // Example combining Boost.Geometry with Boost.Assign and Boost.Range and Boost.Tuple
12
13 #include <iostream>
14
15 #include <boost/geometry/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/linestring.hpp>
18 #include <boost/geometry/geometries/polygon.hpp>
19 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
20
21 #include <boost/assign.hpp>
22
23 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian);
24
25
26 int main(void)
27 {
28 using namespace boost::geometry;
29 using namespace boost::assign;
30
31 {
32 typedef model::d2::point_xy<double> point;
33 typedef model::polygon<point> polygon;
34 typedef model::linestring<point> linestring;
35
36 // Boost.Assign automatically works for linestring, rings, multi-geometries
37 // It works because these are std:: containers
38
39 // Using Boost.Assign operator +=
40 linestring ls1;
41 ls1 += point(1,2);
42 ls1 += point(3,4), point(5,6), point(7,8);
43 std::cout << dsv(ls1) << std::endl;
44
45 // Using Boost.Assign operator()
46 linestring ls2;
47 push_back(ls2)(point(1, 2))(point(3, 4));
48 std::cout << dsv(ls2) << std::endl;
49
50 // Using Boost.Assign list_of
51 linestring ls3 = list_of(point(1,2))(point(3,4));
52 std::cout << dsv(ls3) << std::endl;
53
54 // Using Boost.Assign + Boost.Range
55 linestring ls4;
56 push_back(ls4)(point(0, 0)).range(ls2).range(ls3);
57 std::cout << dsv(ls4) << std::endl;
58
59 // For a ring, it is similar to a linestring.
60 // For a multi-point or multi-linestring, it is also similar
61 // For a polygon, take the exterior ring or one of the interiors
62 polygon p;
63 push_back(exterior_ring(p))
64 (point(0, 0))
65 (point(0, 2))
66 (point(2, 2))
67 (point(2, 0))
68 (point(0, 0))
69 ;
70
71 std::cout << dsv(p) << std::endl;
72 }
73
74 {
75 // It is convenient to combine Boost.Assign on a geometry (e.g. polygon) with tuples.
76 typedef model::polygon<boost::tuple<double,double> > polygon;
77
78 polygon p;
79 exterior_ring(p) = tuple_list_of(0, 0)(0, 5)(5, 5)(5, 0)(0, 0);
80
81 std::cout << dsv(p) << std::endl;
82
83 // And let it work on the interior_rings as well
84 push_back(interior_rings(p))
85 (tuple_list_of(1, 1)(2, 1)(2, 2)(1, 2)(1, 1))
86 (tuple_list_of(3, 3)(4, 3)(4, 4)(3, 4)(3, 3))
87 ;
88
89 std::cout << "Area of " << dsv(p) << " is " << area(p) << std::endl;
90 }
91
92
93 return 0;
94 }