]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/example/01_point_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 // Point Example - showing different type of points
15 #include <boost/geometry/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
18 #include <boost/geometry/geometries/adapted/c_array.hpp>
19 #include <boost/geometry/geometries/adapted/boost_array.hpp>
20 #include <boost/geometry/geometries/adapted/boost_polygon/point.hpp>
22 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian
)
23 BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(cs::cartesian
)
24 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian
)
29 using namespace boost::geometry
;
31 // Boost.Geometry contains several point types:
32 // 1: its own generic type
33 model::point
<double, 2, cs::cartesian
> pt1
;
35 // 2: its own type targetted to Cartesian (x,y) coordinates
36 model::d2::point_xy
<double> pt2
;
38 // 3: it supports Boost tuple's
39 boost::tuple
<double, double> pt3
;
41 // 4: it supports normal arrays
44 // 5: it supports arrays-as-points from Boost.Array
45 boost::array
<double, 2> pt5
;
47 // 6: it supports points from Boost.Polygon
48 boost::polygon::point_data
<double> pt6
;
50 // 7: in the past there was a typedef point_2d
51 // But users are now supposted to do that themselves:
52 typedef model::d2::point_xy
<double> point_2d
;
56 // 7: there are more variants, and you can create your own.
57 // (see therefore the custom_point example)
59 // All these types are handled the same way. We show here
60 // assigning them and calculating distances.
61 assign_values(pt1
, 1, 1);
62 assign_values(pt2
, 2, 2);
63 assign_values(pt3
, 3, 3);
64 assign_values(pt4
, 4, 4);
65 assign_values(pt5
, 5, 5);
66 assign_values(pt6
, 6, 6);
67 assign_values(pt7
, 7, 7);
70 double d1
= distance(pt1
, pt2
);
71 double d2
= distance(pt3
, pt4
);
72 double d3
= distance(pt5
, pt6
);
73 std::cout
<< "Distances: "
74 << d1
<< " and " << d2
<< " and " << d3
<< std::endl
;
76 // (in case you didn't note, distances can be calculated
77 // from points with different point-types)
80 // Several ways of construction and setting point values
81 // 1: default, empty constructor, causing no initialization at all
82 model::d2::point_xy
<double> p1
;
84 // 2: as shown above, assign_values
85 model::d2::point_xy
<double> p2
;
86 assign_values(p2
, 1, 1);
88 // 3: using "set" function
89 // set uses the concepts behind, such that it can be applied for
90 // every point-type (like assign_values)
91 model::d2::point_xy
<double> p3
;
94 // set<2>(p3, 1); //will result in compile-error
97 // 3: for any point type, and other geometry objects:
98 // there is the "make" object generator
99 // (this one requires to specify the point-type).
100 model::d2::point_xy
<double> p4
= make
<model::d2::point_xy
<double> >(1,1);
103 // 5: for the d2::point_xy<...> type only: constructor with two values
104 model::d2::point_xy
<double> p5(1,1);
106 // 6: for boost tuples you can of course use make_tuple
109 // Some ways of getting point values
111 // 1: using the "get" function following the concepts behind
112 std::cout
<< get
<0>(p2
) << "," << get
<1>(p2
) << std::endl
;
114 // 2: for point_xy only
115 std::cout
<< p2
.x() << "," << p2
.y() << std::endl
;
117 // 3: using boost-tuples you of course can boost-tuple-methods
118 std::cout
<< pt3
.get
<0>() << "," << pt3
.get
<1>() << std::endl
;
120 // 4: Boost.Geometry supports various output formats, e.g. DSV
121 // (delimiter separated values)
122 std::cout
<< dsv(pt3
) << std::endl
;
125 std::cout
<< wkt(p4
) << (equals(p4
, p5
) ? " equals " : " don't equals ") << wkt(p5
) << std::endl
;
127 // There are 3-dimensional points too
128 model::point
<double, 3, cs::cartesian
> d3a
, d3b
;
129 assign_values(d3a
, 1, 2, 3);
130 assign_values(d3b
, 4, 5, 6);
131 d3
= distance(d3a
, d3b
);
135 // Other examples show other types of points, geometries and more algorithms