]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/robustness/overlay/buffer/multi_point_growth.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / robustness / overlay / buffer / multi_point_growth.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Performance Test
3
4 // Copyright (c) 2012-2015 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 #include <boost/geometry.hpp>
11 #include <boost/geometry/geometries/geometries.hpp>
12
13 #include <boost/foreach.hpp>
14 #include <boost/timer.hpp>
15 #include <fstream>
16
17
18 namespace bg = boost::geometry;
19
20 template
21 <
22 typename GeometryOut,
23 typename Geometry
24 >
25 double test_growth(Geometry const& geometry, int n, int d, double distance)
26 {
27
28 typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
29 typedef typename bg::point_type<Geometry>::type point_type;
30
31 // extern int point_buffer_count;
32 std::ostringstream complete;
33 complete
34 << "point_growth"
35 << "_" << "r"
36 << "_" << n
37 << "_" << d
38 // << "_" << point_buffer_count
39 ;
40
41 //std::cout << complete.str() << std::endl;
42
43 std::ostringstream filename;
44 filename << "buffer_" << complete.str() << ".svg";
45
46 std::ofstream svg(filename.str().c_str());
47
48 #ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
49 bg::svg_mapper<point_type> mapper(svg, 500, 500);
50
51 {
52 bg::model::box<point_type> box;
53 bg::envelope(geometry, box);
54
55 bg::buffer(box, box, distance * 1.01);
56 mapper.add(box);
57 }
58 #endif
59
60 bg::strategy::buffer::join_round join_strategy(100);
61 bg::strategy::buffer::end_flat end_strategy;
62 bg::strategy::buffer::point_circle point_strategy;
63 bg::strategy::buffer::side_straight side_strategy;
64
65 typedef bg::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy_type;
66 distance_strategy_type distance_strategy(distance);
67
68 std::vector<GeometryOut> buffered;
69
70 bg::buffer(geometry, buffered,
71 distance_strategy, side_strategy,
72 join_strategy, end_strategy, point_strategy);
73
74
75 typename bg::default_area_result<GeometryOut>::type area = 0;
76 BOOST_FOREACH(GeometryOut const& polygon, buffered)
77 {
78 area += bg::area(polygon);
79 }
80
81 #ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
82 // Map input geometry in green
83 mapper.map(geometry, "opacity:0.5;fill:rgb(0,128,0);stroke:rgb(0,128,0);stroke-width:10");
84
85 BOOST_FOREACH(GeometryOut const& polygon, buffered)
86 {
87 mapper.map(polygon, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3");
88 }
89 #endif
90
91 return area;
92 }
93
94 template <typename P>
95 void test_growth(int n, int distance_count)
96 {
97 srand(int(time(NULL)));
98 //std::cout << typeid(bg::coordinate_type<P>::type).name() << std::endl;
99 boost::timer t;
100
101 namespace buf = bg::strategy::buffer;
102 typedef bg::model::polygon<P> polygon;
103 typedef bg::model::multi_point<P> multi_point_type;
104
105 multi_point_type multi_point;
106 for (int i = 0; i < n; i++)
107 {
108 P point(rand() % 100, rand() % 100);
109 multi_point.push_back(point);
110 }
111
112 //std::cout << bg::wkt(multi_point) << std::endl;
113
114 double previous_area = 0;
115 double epsilon = 0.1;
116 double distance = 15.0;
117 for (int d = 0; d < distance_count; d++, distance += epsilon)
118 {
119 double area = test_growth<polygon>(multi_point, n, d, distance);
120 if (area < previous_area)
121 {
122 std::cout << "Error: " << area << " < " << previous_area << std::endl
123 << " n=" << n << " distance=" << distance
124 << bg::wkt(multi_point) << std::endl;
125 }
126 previous_area = area;
127 }
128 std::cout << "n=" << n << " time=" << t.elapsed() << std::endl;
129 }
130
131 int main(int, char* [])
132 {
133 for (int i = 5; i <= 50; i++)
134 {
135 test_growth<bg::model::point<double, 2, bg::cs::cartesian> >(i, 20);
136 }
137
138 return 0;
139 }