1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 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 <geometry_test_common.hpp>
12 #include <boost/geometry/algorithms/buffer.hpp>
14 #include <boost/geometry/strategies/strategies.hpp>
16 #include <boost/geometry/geometries/geometries.hpp>
19 #include <boost/geometry/algorithms/area.hpp>
20 #include <boost/geometry/algorithms/correct.hpp>
21 #include <boost/geometry/algorithms/num_points.hpp>
24 // This unit test tests boost::geometry::buffer (overload with strategies)
25 // More detailed tests are, per geometry type, available in buffer_<TYPE>.cpp
26 // (testing boost::geometry::buffer_inserter)
28 // SVG's are not created (they are in detailed tests)
30 static std::string
const polygon_simplex
= "POLYGON ((0 0,1 5,6 1,0 0))";
31 static std::string
const polygon_empty
= "POLYGON()";
32 static std::string
const multi_polygon_empty
= "MULTIPOLYGON()";
33 static std::string
const multi_polygon_simplex
34 = "MULTIPOLYGON(((0 1,2 5,5 3,0 1)),((1 1,5 2,5 0,1 1)))";
41 typename JoinStrategy
,
43 typename SideStrategy
,
44 typename PointStrategy
,
45 typename DistanceStrategy
47 void test_with_strategies(std::string
const& caseid
,
48 std::string
const& wkt
,
49 JoinStrategy
const& join_strategy
,
50 EndStrategy
const& end_strategy
,
51 SideStrategy
const& side_strategy
,
52 PointStrategy
const& point_strategy
,
53 DistanceStrategy
const& distance_strategy
,
55 std::size_t expected_numpoints
,
56 double tolerance
= 0.01)
58 namespace bg
= boost::geometry
;
66 distance_strategy
, side_strategy
,
67 join_strategy
, end_strategy
, point_strategy
);
71 bg::num_points(result
) == expected_numpoints
,
73 << " numpoints expected: " << expected_numpoints
74 << " detected: " << bg::num_points(result
)
77 double const area
= bg::area(result
);
78 double const difference
= area
- expected_area
;
82 bg::math::abs(difference
) < tolerance
,
84 << std::setprecision(12)
85 << " area expected: " << expected_area
86 << " detected: " << area
91 template <bool Clockwise
, typename Point
>
94 typedef bg::model::polygon
<Point
, Clockwise
> polygon
;
95 typedef bg::model::multi_polygon
<polygon
> multi_polygon
;
97 bg::strategy::buffer::join_round
join(160);
98 bg::strategy::buffer::end_round
end(160);
99 bg::strategy::buffer::point_circle
circle(160);
100 bg::strategy::buffer::side_straight side
;
102 typedef bg::strategy::buffer::distance_symmetric
104 typename
bg::coordinate_type
<Point
>::type
107 test_with_strategies
<multi_polygon
, multi_polygon
>(
108 "multi_polygon_empty", multi_polygon_empty
,
109 join
, end
, side
, circle
, distance(1.0),
113 // PostGIS: 34.2550669294223 216 (40 / qcircle)
114 // SQL Server: 34.2550419903829 220 (default options)
115 test_with_strategies
<multi_polygon
, multi_polygon
>(
116 "multi_polygon_simplex", multi_polygon_simplex
,
117 join
, end
, side
, circle
, distance(1.0),
120 test_with_strategies
<polygon
, multi_polygon
>(
121 "polygon_empty", polygon_empty
,
122 join
, end
, side
, circle
, distance(1.0),
126 // PostGIS: 35.2256914798762 164 (40 / qcircle)
127 // SQL Server: 35.2252355201605 153 (default options)
128 test_with_strategies
<polygon
, multi_polygon
>(
129 "polygon_simplex", polygon_simplex
,
130 join
, end
, side
, circle
, distance(1.0),
134 int test_main(int, char* [])
136 test_all
<true, bg::model::point
<double, 2, bg::cs::cartesian
> >();