]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/buffer/buffer_multi_point.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / buffer / buffer_multi_point.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2012-2019 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // This file was modified by Oracle on 2020-2022.
7 // Modifications copyright (c) 2020-2022 Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #include "test_buffer.hpp"
15
16 static std::string const simplex = "MULTIPOINT((5 5),(7 7))";
17 static std::string const three = "MULTIPOINT((5 8),(9 8),(7 11))";
18
19 // Generated error (extra polygon on top of rest) at distance 14.0:
20 static std::string const multipoint_a = "MULTIPOINT((39 44),(38 37),(41 29),(15 33),(58 39))";
21
22 // Just one with holes at distance ~ 15
23 static std::string const multipoint_b = "MULTIPOINT((5 56),(98 67),(20 7),(58 60),(10 4),(75 68),(61 68),(75 62),(92 26),(74 6),(67 54),(20 43),(63 30),(45 7))";
24
25 // Grid, U-form, generates error for square point at 0.54 (top cells to control rescale)
26 static std::string const grid_a = "MULTIPOINT(5 0,6 0,7 0, 5 1,7 1, 0 13,8 13)";
27
28 static std::string const mysql_report_2015_02_25_1 = "MULTIPOINT(-9 19,9 -6,-4 4,16 -14,-3 16,14 9)";
29 static std::string const mysql_report_2015_02_25_2 = "MULTIPOINT(-2 11,-15 3,6 4,-14 0,20 -7,-17 -1)";
30
31 static std::string const mysql_report_3 = "MULTIPOINT(0 0,0 0,0 0,0 0,0 0)";
32
33 template <bool Clockwise, typename P>
34 void test_all()
35 {
36 typedef bg::model::polygon<P, Clockwise> polygon;
37 typedef bg::model::multi_point<P> multi_point_type;
38
39 bg::strategy::buffer::join_round join;
40 bg::strategy::buffer::end_flat end_flat;
41 typedef bg::strategy::buffer::distance_symmetric
42 <
43 typename bg::coordinate_type<P>::type
44 > distance_strategy;
45 bg::strategy::buffer::side_straight side_strategy;
46
47 double const expectation = boost::geometry::math::pi<double>() * 0.99915;
48
49 test_one<multi_point_type, polygon>("simplex1", simplex, join, end_flat, 2.0 * expectation, 1.0);
50 test_one<multi_point_type, polygon>("simplex2", simplex, join, end_flat, 22.8335, 2.0);
51 test_one<multi_point_type, polygon>("simplex3", simplex, join, end_flat, 44.5619, 3.0);
52
53 test_one<multi_point_type, polygon>("three1", three, join, end_flat, 3.0 * expectation, 1.0);
54 #if defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
55 // For no-rescaling, fails in CCW mode
56 test_one<multi_point_type, polygon>("three2", three, join, end_flat, 36.7528, 2.0);
57 #endif
58 test_one<multi_point_type, polygon>("three19", three, join, end_flat, 33.6857, 1.9);
59 test_one<multi_point_type, polygon>("three21", three, join, end_flat, 39.6337, 2.1);
60 test_one<multi_point_type, polygon>("three3", three, join, end_flat, 65.5243, 3.0);
61
62 test_one<multi_point_type, polygon>("multipoint_a", multipoint_a, join, end_flat, 2049.98, 14.0);
63 test_one<multi_point_type, polygon>("multipoint_b", multipoint_b, join, end_flat, 7109.88, 15.0);
64 test_one<multi_point_type, polygon>("multipoint_b1", multipoint_b, join, end_flat, 6911.89, 14.7);
65 test_one<multi_point_type, polygon>("multipoint_b2", multipoint_b, join, end_flat, 7174.79, 15.1);
66
67 // Grid tests
68 {
69 bg::strategy::buffer::point_square point_strategy;
70
71 test_with_custom_strategies<multi_point_type, polygon>("grid_a50",
72 grid_a, join, end_flat,
73 distance_strategy(0.5), side_strategy, point_strategy, 7.0);
74
75 test_with_custom_strategies<multi_point_type, polygon>("grid_a54",
76 grid_a, join, end_flat,
77 distance_strategy(0.54), side_strategy, point_strategy, 7.819);
78 }
79
80 test_with_custom_strategies<multi_point_type, polygon>("mysql_report_2015_02_25_1_800",
81 mysql_report_2015_02_25_1, join, end_flat,
82 distance_strategy(6051788), side_strategy,
83 bg::strategy::buffer::point_circle(800),
84 115057490003226.125, ut_settings(1.0));
85
86 {
87 typename bg::strategies::buffer::services::default_strategy
88 <
89 multi_point_type
90 >::type strategy;
91
92 multi_point_type g;
93 bg::read_wkt(mysql_report_3, g);
94 bg::model::multi_polygon<polygon> buffered;
95 test_buffer<polygon>("mysql_report_3", buffered, g,
96 bg::strategy::buffer::join_round(36),
97 bg::strategy::buffer::end_round(36),
98 distance_strategy(1),
99 side_strategy,
100 bg::strategy::buffer::point_circle(36),
101 strategy,
102 1, 0, 3.12566719800474635, ut_settings(1.0));
103 }
104 }
105
106 template <typename P>
107 void test_many_points_per_circle()
108 {
109 // Tests for large distances / many points in circles.
110 // Before Boost 1.58, this would (seem to) hang. It is solved by using monotonic sections in get_turns for buffer
111 // This is more time consuming, only calculate this for counter clockwise
112 // Reported by MySQL 2015-02-25
113 // SELECT ST_ASTEXT(ST_BUFFER(ST_GEOMFROMTEXT(''), 6051788, ST_BUFFER_STRATEGY('point_circle', 83585)));
114 // SELECT ST_ASTEXT(ST_BUFFER(ST_GEOMFROMTEXT(''), 5666962, ST_BUFFER_STRATEGY('point_circle', 46641))) ;
115
116 typedef bg::model::polygon<P, false> polygon;
117 typedef bg::model::multi_point<P> multi_point_type;
118
119 bg::strategy::buffer::join_round join;
120 bg::strategy::buffer::end_flat end_flat;
121 typedef bg::strategy::buffer::distance_symmetric
122 <
123 typename bg::coordinate_type<P>::type
124 > distance_strategy;
125 bg::strategy::buffer::side_straight side_strategy;
126
127 using bg::strategy::buffer::point_circle;
128
129 #if ! defined(BOOST_GEOMETRY_USE_RESCALING)
130 double const tolerance = 1000.0;
131 #else
132 double const tolerance = 1.0;
133 #endif
134
135 // Area should be somewhat larger (~>) than pi*distance^2
136 // 6051788: area ~> 115058122875258
137
138 // Strategies with many points, which are (very) slow in debug mode
139 test_with_custom_strategies<multi_point_type, polygon>(
140 "mysql_report_2015_02_25_1_8000",
141 mysql_report_2015_02_25_1, join, end_flat,
142 distance_strategy(6051788), side_strategy, point_circle(8000),
143 115058661065242.812, ut_settings(10.0 * tolerance));
144
145 // Expectations:
146 // 115058672785641.031
147 // 115058672785680.281
148 // 115058672785679.922
149 test_with_custom_strategies<multi_point_type, polygon>(
150 "mysql_report_2015_02_25_1",
151 mysql_report_2015_02_25_1, join, end_flat,
152 distance_strategy(6051788), side_strategy, point_circle(83585),
153 115058672785660.0, ut_settings(25.0 * tolerance));
154
155 // Takes about 7 seconds in release mode
156 // Expectations:
157 // 115058672880035.391
158 // 115058672879944.547
159 // 115058672879920.484
160 test_with_custom_strategies<multi_point_type, polygon>(
161 "mysql_report_2015_02_25_1_250k",
162 mysql_report_2015_02_25_1, join, end_flat,
163 distance_strategy(6051788), side_strategy, point_circle(250000),
164 115058672879977.0, ut_settings(150.0 * tolerance));
165
166 #if defined(BOOST_GEOMETRY_BUFFER_INCLUDE_SLOW_TESTS)
167 // Takes about 110 seconds in release mode
168 test_with_custom_strategies<multi_point_type, polygon>(
169 "mysql_report_2015_02_25_1_800k",
170 mysql_report_2015_02_25_1, join, end_flat,
171 distance_strategy(6051788), side_strategy, point_circle(800000),
172 115058672871849.219, ut_settings(tolerance));
173 #endif
174
175 // 5666962: area ~> 100890546298964
176 // Expectations:
177 // 100891031341796.875
178 // 100891031341794.766
179 // 100891031341794.078
180 test_with_custom_strategies<multi_point_type, polygon>(
181 "mysql_report_2015_02_25_2",
182 mysql_report_2015_02_25_2, join, end_flat,
183 distance_strategy(5666962), side_strategy, point_circle(46641),
184 100891031341795.0, ut_settings(200.0 * tolerance));
185
186 // Multipoint b with large distances/many points
187 // Area ~> pi * 10x
188
189 // Expectations:
190 // 3141871558222.398
191 // 3141871558231.5166
192 // 3141871558231.48926
193
194 test_with_custom_strategies<multi_point_type, polygon>(
195 "multipoint_b_50k",
196 multipoint_b, join, end_flat,
197 distance_strategy(1000000), side_strategy, point_circle(50000),
198 3141871558227.0, ut_settings(40.0 * tolerance));
199
200 #if defined(BOOST_GEOMETRY_BUFFER_INCLUDE_SLOW_TESTS)
201 // Tests optimization min/max radius
202 // Takes about 55 seconds in release mode
203 test_with_custom_strategies<multi_point_type, polygon>(
204 "multipoint_b_500k",
205 multipoint_b, join, end_flat,
206 distance_strategy(10000000), side_strategy, point_circle(500000),
207 314162054419515.562, ut_settings((tolerance));
208 #endif
209 }
210
211 int test_main(int, char* [])
212 {
213 BoostGeometryWriteTestConfiguration();
214
215 test_all<true, bg::model::point<default_test_type, 2, bg::cs::cartesian> >();
216
217 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_ORDER)
218 test_all<false, bg::model::point<default_test_type, 2, bg::cs::cartesian> >();
219 #endif
220
221 #if defined(BOOST_GEOMETRY_COMPILER_MODE_RELEASE) && ! defined(BOOST_GEOMETRY_COMPILER_MODE_DEBUG)
222 test_many_points_per_circle<bg::model::point<double, 2, bg::cs::cartesian> >();
223 #else
224 std::cout << "Skipping some tests in debug or unknown mode" << std::endl;
225 #endif
226
227 #if defined(BOOST_GEOMETRY_TEST_FAILURES)
228 BoostGeometryWriteExpectedFailures(BG_NO_FAILURES);
229 #endif
230
231 return 0;
232 }