]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | //[convert | |
11 | //` Shows how to convert a geometry into another geometry | |
12 | ||
13 | #include <iostream> | |
14 | ||
15 | #include <boost/geometry.hpp> | |
16 | #include <boost/geometry/geometries/box.hpp> | |
17 | #include <boost/geometry/geometries/point_xy.hpp> | |
18 | #include <boost/geometry/geometries/polygon.hpp> | |
19 | #include <boost/geometry/geometries/adapted/boost_tuple.hpp> | |
20 | ||
21 | BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) | |
22 | ||
23 | int main() | |
24 | { | |
25 | typedef boost::geometry::model::d2::point_xy<double> point; | |
26 | typedef boost::geometry::model::box<point> box; | |
27 | typedef boost::geometry::model::polygon<point> polygon; | |
28 | ||
29 | point p1(1, 1); | |
30 | box bx = boost::geometry::make<box>(1, 1, 2, 2); | |
31 | ||
32 | // Assign a box to a polygon (conversion box->poly) | |
33 | polygon poly; | |
34 | boost::geometry::convert(bx, poly); | |
35 | ||
36 | // Convert a point to another point type (conversion of point-type) | |
37 | boost::tuple<double, double> p2; | |
38 | boost::geometry::convert(p1, p2); // source -> target | |
39 | ||
40 | using boost::geometry::dsv; | |
41 | std::cout | |
42 | << "box: " << dsv(bx) << std::endl | |
43 | << "polygon: " << dsv(poly) << std::endl | |
44 | << "point: " << dsv(p1) << std::endl | |
45 | << "point tuples: " << dsv(p2) << std::endl | |
46 | ; | |
47 | ||
48 | return 0; | |
49 | } | |
50 | ||
51 | //] | |
52 | ||
53 | ||
54 | //[convert_output | |
55 | /*` | |
56 | Output: | |
57 | [pre | |
58 | box: ((1, 1), (2, 2)) | |
59 | polygon: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))) | |
60 | point: (1, 1) | |
61 | point tuples: (1, 1) | |
62 | ] | |
63 | */ | |
64 | //] |