1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2012-2015 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)
10 #include <boost/geometry.hpp>
11 #include <boost/geometry/geometries/geometries.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/timer.hpp>
18 namespace bg
= boost::geometry
;
25 double test_growth(Geometry
const& geometry
, int n
, int d
, double distance
)
28 typedef typename
bg::coordinate_type
<Geometry
>::type coordinate_type
;
29 typedef typename
bg::point_type
<Geometry
>::type point_type
;
31 // extern int point_buffer_count;
32 std::ostringstream complete
;
38 // << "_" << point_buffer_count
41 //std::cout << complete.str() << std::endl;
43 std::ostringstream filename
;
44 filename
<< "buffer_" << complete
.str() << ".svg";
46 std::ofstream
svg(filename
.str().c_str());
48 #ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
49 bg::svg_mapper
<point_type
> mapper(svg
, 500, 500);
52 bg::model::box
<point_type
> box
;
53 bg::envelope(geometry
, box
);
55 bg::buffer(box
, box
, distance
* 1.01);
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
;
65 typedef bg::strategy::buffer::distance_symmetric
<coordinate_type
> distance_strategy_type
;
66 distance_strategy_type
distance_strategy(distance
);
68 std::vector
<GeometryOut
> buffered
;
70 bg::buffer(geometry
, buffered
,
71 distance_strategy
, side_strategy
,
72 join_strategy
, end_strategy
, point_strategy
);
75 typename
bg::default_area_result
<GeometryOut
>::type area
= 0;
76 BOOST_FOREACH(GeometryOut
const& polygon
, buffered
)
78 area
+= bg::area(polygon
);
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");
85 BOOST_FOREACH(GeometryOut
const& polygon
, buffered
)
87 mapper
.map(polygon
, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3");
95 void test_growth(int n
, int distance_count
)
97 srand(int(time(NULL
)));
98 //std::cout << typeid(bg::coordinate_type<P>::type).name() << std::endl;
101 namespace buf
= bg::strategy::buffer
;
102 typedef bg::model::polygon
<P
> polygon
;
103 typedef bg::model::multi_point
<P
> multi_point_type
;
105 multi_point_type multi_point
;
106 for (int i
= 0; i
< n
; i
++)
108 P
point(rand() % 100, rand() % 100);
109 multi_point
.push_back(point
);
112 //std::cout << bg::wkt(multi_point) << std::endl;
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
)
119 double area
= test_growth
<polygon
>(multi_point
, n
, d
, distance
);
120 if (area
< previous_area
)
122 std::cout
<< "Error: " << area
<< " < " << previous_area
<< std::endl
123 << " n=" << n
<< " distance=" << distance
124 << bg::wkt(multi_point
) << std::endl
;
126 previous_area
= area
;
128 std::cout
<< "n=" << n
<< " time=" << t
.elapsed() << std::endl
;
131 int main(int, char* [])
133 for (int i
= 5; i
<= 50; i
++)
135 test_growth
<bg::model::point
<double, 2, bg::cs::cartesian
> >(i
, 20);