]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/doc/doxy/doxygen_input/sourcecode/doxygen_2.cpp
3 // Boost.Geometry (aka GGL, Generic Geometry Library)
5 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
6 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
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 // Doxygen Examples, for main page
13 #include <boost/tuple/tuple.hpp>
16 // We deliberately mix float/double's here so turn off warning
17 //#pragma warning( disable : 4244 )
18 #endif // defined(_MSC_VER)
20 #include <boost/geometry/geometry.hpp>
21 #include <boost/geometry/algorithms/overlaps.hpp>
22 #include <boost/geometry/geometries/geometries.hpp>
23 #include <boost/geometry/geometries/point_xy.hpp>
24 #include <boost/geometry/geometries/register/point.hpp>
27 // Small QRect simulations following http://doc.trolltech.com/4.4/qrect.html
28 // Todo: once work the traits out further, would be nice if there is a real example of this.
29 // However for the example it makes no difference, it will work any way.
33 // In Qt these are methods but for example below it makes no difference
38 int x
, y
, width
, height
;
39 QRect(int _x
, int _y
, int w
, int h
)
40 : x(_x
), y(_y
), width(w
), height(h
)
42 // In Qt these are methods but that will work as well, requires changing traits below
46 // Would be get/set with x(),y(),setX(),setY()
47 BOOST_GEOMETRY_REGISTER_POINT_2D(QPoint
, int, cs::cartesian
, x
, y
)
50 // Register the QT rectangle. The macro(s) does not offer (yet) enough flexibility to do this in one line,
51 // but the traits classes do their job perfectly.
52 namespace boost
{ namespace geometry
{ namespace traits
55 template <> struct tag
<QRect
> { typedef box_tag type
; };
56 template <> struct point_type
<QRect
> { typedef QPoint type
; };
58 template <size_t C
, size_t D
>
59 struct indexed_access
<QRect
, C
, D
>
61 static inline int get(const QRect
& qr
)
63 // Would be: x(), y(), width(), height()
64 return C
== min_corner
&& D
== 0 ? qr
.x
65 : C
== min_corner
&& D
== 1 ? qr
.y
66 : C
== max_corner
&& D
== 0 ? qr
.x
+ qr
.width
67 : C
== max_corner
&& D
== 1 ? qr
.y
+ qr
.height
71 static inline void set(QRect
& qr
, const int& value
)
73 // Would be: setX, setY, setWidth, setHeight
74 if (C
== min_corner
&& D
== 0) qr
.x
= value
;
75 else if (C
== min_corner
&& D
== 1) qr
.y
= value
;
76 else if (C
== max_corner
&& D
== 0) qr
.width
= value
- qr
.x
;
77 else if (C
== max_corner
&& D
== 1) qr
.height
= value
- qr
.y
;
85 void example_for_main_page()
87 using namespace boost::geometry
;
91 double d
= distance(a
, b
);
92 std::cout
<< "Distance a-b is:" << d
<< std::endl
;
95 double points
[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}};
97 boost::tuple
<double, double> p
= boost::make_tuple(3.7, 2.0);
98 std::cout
<< "Point p is in polygon? " << (within(p
, poly
) ? "YES" : "NO") << std::endl
;
100 std::cout
<< "Area: " << area(poly
) << std::endl
;
102 double d2
= distance(a
, p
);
103 std::cout
<< "Distance a-p is:" << d2
<< std::endl
;
107 point_ll_deg amsterdam, paris;
108 parse(amsterdam, "52 22 23 N", "4 53 32 E");
109 parse(paris, "48 52 0 N", "2 19 59 E");
110 std::cout << "Distance A'dam-Paris: " << distance(amsterdam, paris) / 1000.0 << " kilometers " << std::endl;
113 QRect
r1(100, 200, 15, 15);
114 QRect
r2(110, 210, 20, 20);
115 if (overlaps(r1
, r2
))
117 assign(r2
, 200, 300, 220, 320);
122 void example_for_transform()
124 using namespace boost::geometry
;
126 typedef point
<double, 3, cs::cartesian
> XYZ
;
127 typedef point
<double, 3, cs::spherical
<degree
> > SPH
;
131 assign(sph1
, 12.5, 41.90, 1.0);
132 // Go from spherical to Cartesian-3D:
134 // Go back from Cartesian 3D to spherical:
137 std::cout
<< dsv(p
) << " <-> " << dsv(sph2
) << std::endl
;
139 typedef point_xy
<double> XY
;
140 typedef point_xy
<int> PIXEL
;
142 strategy::transform::map_transformer
<XY
, PIXEL
, false> map(0, 0, 100, 100, 1024, 768);
144 transform(xy
, pix
, map
);
145 std::cout
<< pix
.x() << "," << pix
.y() << std::endl
;
152 example_for_main_page();
153 example_for_transform();