]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/buffer/buffer_with_strategies.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / buffer / buffer_with_strategies.cpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 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 <geometry_test_common.hpp>
11
12#include <boost/geometry/algorithms/buffer.hpp>
13
14#include <boost/geometry/strategies/strategies.hpp>
15
16#include <boost/geometry/geometries/geometries.hpp>
17
18// For test
19#include <boost/geometry/algorithms/area.hpp>
20#include <boost/geometry/algorithms/correct.hpp>
21#include <boost/geometry/algorithms/num_points.hpp>
22
23
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)
27
28// SVG's are not created (they are in detailed tests)
29
30static std::string const polygon_simplex = "POLYGON ((0 0,1 5,6 1,0 0))";
31static std::string const polygon_empty = "POLYGON()";
32static std::string const multi_polygon_empty = "MULTIPOLYGON()";
33static std::string const multi_polygon_simplex
34 = "MULTIPOLYGON(((0 1,2 5,5 3,0 1)),((1 1,5 2,5 0,1 1)))";
35
36
37template
38<
39 typename Geometry,
40 typename GeometryOut,
41 typename JoinStrategy,
42 typename EndStrategy,
43 typename SideStrategy,
44 typename PointStrategy,
45 typename DistanceStrategy
46>
47void 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,
54 double expected_area,
55 std::size_t expected_numpoints,
56 double tolerance = 0.01)
57{
58 namespace bg = boost::geometry;
59 Geometry g;
60 bg::read_wkt(wkt, g);
61 bg::correct(g);
62
63 GeometryOut result;
64
65 bg::buffer(g, result,
66 distance_strategy, side_strategy,
67 join_strategy, end_strategy, point_strategy);
68
69 BOOST_CHECK_MESSAGE
70 (
71 bg::num_points(result) == expected_numpoints,
72 "Buffer " << caseid
73 << " numpoints expected: " << expected_numpoints
74 << " detected: " << bg::num_points(result)
75 );
76
77 double const area = bg::area(result);
78 double const difference = area - expected_area;
79
80 BOOST_CHECK_MESSAGE
81 (
82 bg::math::abs(difference) < tolerance,
83 "Buffer " << caseid
84 << std::setprecision(12)
85 << " area expected: " << expected_area
86 << " detected: " << area
87 );
88}
89
90
91template <bool Clockwise, typename Point>
92void test_all()
93{
94 typedef bg::model::polygon<Point, Clockwise> polygon;
95 typedef bg::model::multi_polygon<polygon> multi_polygon;
96
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;
101
102 typedef bg::strategy::buffer::distance_symmetric
103 <
104 typename bg::coordinate_type<Point>::type
105 > distance;
106
107 test_with_strategies<multi_polygon, multi_polygon>(
108 "multi_polygon_empty", multi_polygon_empty,
109 join, end, side, circle, distance(1.0),
110 0.0, 0);
111
112
113 // PostGIS: 34.2550669294223 216 (40 / qcircle)
b32b8144 114 // SQL Server: 34.2550419903829 220 (default options)
7c673cae
FG
115 test_with_strategies<multi_polygon, multi_polygon>(
116 "multi_polygon_simplex", multi_polygon_simplex,
117 join, end, side, circle, distance(1.0),
118 34.2551, 219);
119
120 test_with_strategies<polygon, multi_polygon>(
121 "polygon_empty", polygon_empty,
122 join, end, side, circle, distance(1.0),
123 0.0, 0);
124
125 //
126 // PostGIS: 35.2256914798762 164 (40 / qcircle)
b32b8144 127 // SQL Server: 35.2252355201605 153 (default options)
7c673cae
FG
128 test_with_strategies<polygon, multi_polygon>(
129 "polygon_simplex", polygon_simplex,
130 join, end, side, circle, distance(1.0),
131 35.2257, 166);
132}
133
134int test_main(int, char* [])
135{
136 test_all<true, bg::model::point<double, 2, bg::cs::cartesian> >();
137 return 0;
138}