]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/example/04_boost_example.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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)
11 // Example combining Boost.Geometry with Boost.Assign and Boost.Range and Boost.Tuple
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>
21 #include <boost/assign.hpp>
23 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian
);
28 using namespace boost::geometry
;
29 using namespace boost::assign
;
32 typedef model::d2::point_xy
<double> point
;
33 typedef model::polygon
<point
> polygon
;
34 typedef model::linestring
<point
> linestring
;
36 // Boost.Assign automatically works for linestring, rings, multi-geometries
37 // It works because these are std:: containers
39 // Using Boost.Assign operator +=
42 ls1
+= point(3,4), point(5,6), point(7,8);
43 std::cout
<< dsv(ls1
) << std::endl
;
45 // Using Boost.Assign operator()
47 push_back(ls2
)(point(1, 2))(point(3, 4));
48 std::cout
<< dsv(ls2
) << std::endl
;
50 // Using Boost.Assign list_of
51 linestring ls3
= list_of(point(1,2))(point(3,4));
52 std::cout
<< dsv(ls3
) << std::endl
;
54 // Using Boost.Assign + Boost.Range
56 push_back(ls4
)(point(0, 0)).range(ls2
).range(ls3
);
57 std::cout
<< dsv(ls4
) << std::endl
;
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
63 push_back(exterior_ring(p
))
71 std::cout
<< dsv(p
) << std::endl
;
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
;
79 exterior_ring(p
) = tuple_list_of(0, 0)(0, 5)(5, 5)(5, 0)(0, 0);
81 std::cout
<< dsv(p
) << std::endl
;
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))
89 std::cout
<< "Area of " << dsv(p
) << " is " << area(p
) << std::endl
;