]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/doc/src/examples/algorithms/for_each_point.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
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)
11 //` Convenient usage of for_each_point, rounding all points of a geometry
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/polygon.hpp>
21 template <typename Point
>
22 class round_coordinates
25 typedef typename
boost::geometry::coordinate_type
<Point
>::type coordinate_type
;
26 coordinate_type factor
;
28 inline coordinate_type
round(coordinate_type value
)
30 return floor(0.5 + (value
/ factor
)) * factor
;
34 round_coordinates(coordinate_type f
)
38 inline void operator()(Point
& p
)
40 using boost::geometry::get
;
41 using boost::geometry::set
;
42 set
<0>(p
, round(get
<0>(p
)));
43 set
<1>(p
, round(get
<1>(p
)));
50 typedef boost::geometry::model::d2::point_xy
<double> point
;
51 boost::geometry::model::polygon
<point
> poly
;
52 boost::geometry::read_wkt("POLYGON((0 0,1.123 9.987,8.876 2.234,0 0),(3.345 4.456,7.654 8.765,9.123 5.432,3.345 4.456))", poly
);
53 boost::geometry::for_each_point(poly
, round_coordinates
<point
>(0.1));
54 std::cout
<< "Rounded: " << boost::geometry::wkt(poly
) << std::endl
;
61 //[for_each_point_output
65 Rounded: POLYGON((0 0,1.1 10,8.9 2.2,0 0),(3.3 4.5,7.7 8.8,9.1 5.4,3.3 4.5))