]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/buffer/buffer_multi_point.cpp
add subtree-ish sources for 12.0.3
[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-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 <test_buffer.hpp>
11
12 static std::string const simplex = "MULTIPOINT((5 5),(7 7))";
13 static std::string const three = "MULTIPOINT((5 8),(9 8),(7 11))";
14
15 // Generated error (extra polygon on top of rest) at distance 14.0:
16 static std::string const multipoint_a = "MULTIPOINT((39 44),(38 37),(41 29),(15 33),(58 39))";
17
18 // Just one with holes at distance ~ 15
19 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))";
20
21 // Grid, U-form, generates error for square point at 0.54 (top cells to control rescale)
22 static std::string const grid_a = "MULTIPOINT(5 0,6 0,7 0, 5 1,7 1, 0 13,8 13)";
23
24 static std::string const mysql_report_2015_02_25_1 = "MULTIPOINT(-9 19,9 -6,-4 4,16 -14,-3 16,14 9)";
25 static std::string const mysql_report_2015_02_25_2 = "MULTIPOINT(-2 11,-15 3,6 4,-14 0,20 -7,-17 -1)";
26
27 template <bool Clockwise, typename P>
28 void test_all()
29 {
30 typedef bg::model::polygon<P, Clockwise> polygon;
31 typedef bg::model::multi_point<P> multi_point_type;
32
33 bg::strategy::buffer::join_round join;
34 bg::strategy::buffer::end_flat end_flat;
35 typedef bg::strategy::buffer::distance_symmetric
36 <
37 typename bg::coordinate_type<P>::type
38 > distance_strategy;
39 bg::strategy::buffer::side_straight side_strategy;
40
41 double const pi = boost::geometry::math::pi<double>();
42
43 test_one<multi_point_type, polygon>("simplex1", simplex, join, end_flat, 2.0 * pi, 1.0, 1.0);
44 test_one<multi_point_type, polygon>("simplex2", simplex, join, end_flat, 22.8372, 2.0, 2.0);
45 test_one<multi_point_type, polygon>("simplex3", simplex, join, end_flat, 44.5692, 3.0, 3.0);
46
47 test_one<multi_point_type, polygon>("three1", three, join, end_flat, 3.0 * pi, 1.0, 1.0);
48 #if !defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
49 // For no-rescaling, fails in CCW mode
50 test_one<multi_point_type, polygon>("three2", three, join, end_flat, 36.7592, 2.0, 2.0);
51 #endif
52 test_one<multi_point_type, polygon>("three19", three, join, end_flat, 33.6914, 1.9, 1.9);
53 test_one<multi_point_type, polygon>("three21", three, join, end_flat, 39.6394, 2.1, 2.1);
54 test_one<multi_point_type, polygon>("three3", three, join, end_flat, 65.533, 3.0, 3.0);
55
56 test_one<multi_point_type, polygon>("multipoint_a", multipoint_a, join, end_flat, 2049.98, 14.0, 14.0);
57 test_one<multi_point_type, polygon>("multipoint_b", multipoint_b, join, end_flat, 7109.88, 15.0, 15.0);
58 test_one<multi_point_type, polygon>("multipoint_b1", multipoint_b, join, end_flat, 6911.89, 14.7, 14.7);
59 test_one<multi_point_type, polygon>("multipoint_b2", multipoint_b, join, end_flat, 7174.79, 15.1, 15.1);
60
61 // Grid tests
62 {
63 bg::strategy::buffer::point_square point_strategy;
64
65 test_with_custom_strategies<multi_point_type, polygon>("grid_a50",
66 grid_a, join, end_flat,
67 distance_strategy(0.5), side_strategy, point_strategy, 7.0);
68
69 #if defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
70 test_with_custom_strategies<multi_point_type, polygon>("grid_a54",
71 grid_a, join, end_flat,
72 distance_strategy(0.54), side_strategy, point_strategy, 7.819);
73 #endif
74
75 }
76
77 test_with_custom_strategies<multi_point_type, polygon>("mysql_report_2015_02_25_1_800",
78 mysql_report_2015_02_25_1, join, end_flat,
79 distance_strategy(6051788), side_strategy,
80 bg::strategy::buffer::point_circle(800), 115057490003226.125, 1.0);
81 }
82
83 template <typename P>
84 void test_many_points_per_circle()
85 {
86 // Tests for large distances / many points in circles.
87 // Before Boost 1.58, this would (seem to) hang. It is solved by using monotonic sections in get_turns for buffer
88 // This is more time consuming, only calculate this for counter clockwise
89 // Reported by MySQL 2015-02-25
90 // SELECT ST_ASTEXT(ST_BUFFER(ST_GEOMFROMTEXT(''), 6051788, ST_BUFFER_STRATEGY('point_circle', 83585)));
91 // SELECT ST_ASTEXT(ST_BUFFER(ST_GEOMFROMTEXT(''), 5666962, ST_BUFFER_STRATEGY('point_circle', 46641))) ;
92
93 typedef bg::model::polygon<P, false> polygon;
94 typedef bg::model::multi_point<P> multi_point_type;
95
96 bg::strategy::buffer::join_round join;
97 bg::strategy::buffer::end_flat end_flat;
98 typedef bg::strategy::buffer::distance_symmetric
99 <
100 typename bg::coordinate_type<P>::type
101 > distance_strategy;
102 bg::strategy::buffer::side_straight side_strategy;
103
104 using bg::strategy::buffer::point_circle;
105
106 double const tolerance = 1.0;
107 #if defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
108 double const tolerance_multiplier = 1000.0;
109 #else
110 double const tolerance_multiplier = 1.0;
111 #endif
112
113 // Area should be somewhat larger (~>) than pi*distance^2
114 // 6051788: area ~> 115058122875258
115
116 // Strategies with many points, which are (very) slow in debug mode
117 test_with_custom_strategies<multi_point_type, polygon>(
118 "mysql_report_2015_02_25_1_8000",
119 mysql_report_2015_02_25_1, join, end_flat,
120 distance_strategy(6051788), side_strategy, point_circle(8000),
121 115058661065242.812, tolerance);
122
123 // Expectations:
124 // 115058672785641.031
125 // 115058672785680.281
126 // 115058672785679.922
127 test_with_custom_strategies<multi_point_type, polygon>(
128 "mysql_report_2015_02_25_1",
129 mysql_report_2015_02_25_1, join, end_flat,
130 distance_strategy(6051788), side_strategy, point_circle(83585),
131 115058672785660, 25.0 * tolerance_multiplier);
132
133 // Takes about 7 seconds in release mode
134 // Expectations:
135 // 115058672880035.391
136 // 115058672879944.547
137 // 115058672879920.484
138 test_with_custom_strategies<multi_point_type, polygon>(
139 "mysql_report_2015_02_25_1_250k",
140 mysql_report_2015_02_25_1, join, end_flat,
141 distance_strategy(6051788), side_strategy, point_circle(250000),
142 115058672879977, 75.0 * tolerance_multiplier);
143
144 #if defined(BOOST_GEOMETRY_BUFFER_INCLUDE_SLOW_TESTS)
145 // Takes about 110 seconds in release mode
146 test_with_custom_strategies<multi_point_type, polygon>(
147 "mysql_report_2015_02_25_1_800k",
148 mysql_report_2015_02_25_1, join, end_flat,
149 distance_strategy(6051788), side_strategy, point_circle(800000),
150 115058672871849.219, tolerance);
151 #endif
152
153 // 5666962: area ~> 100890546298964
154 // Expectations:
155 // 100891031341796.875
156 // 100891031341794.766
157 // 100891031341794.078
158 test_with_custom_strategies<multi_point_type, polygon>(
159 "mysql_report_2015_02_25_2",
160 mysql_report_2015_02_25_2, join, end_flat,
161 distance_strategy(5666962), side_strategy, point_circle(46641),
162 100891031341795, 3.0 * tolerance_multiplier);
163
164 // Multipoint b with large distances/many points
165 // Area ~> pi * 10x
166
167 // Expectations:
168 // 3141871558222.398
169 // 3141871558231.5166
170 // 3141871558231.48926
171
172 test_with_custom_strategies<multi_point_type, polygon>(
173 "multipoint_b_50k",
174 multipoint_b, join, end_flat,
175 distance_strategy(1000000), side_strategy, point_circle(50000),
176 3141871558227, 10.0 * tolerance_multiplier);
177
178 #if defined(BOOST_GEOMETRY_BUFFER_INCLUDE_SLOW_TESTS)
179 // Tests optimization min/max radius
180 // Takes about 55 seconds in release mode
181 test_with_custom_strategies<multi_point_type, polygon>(
182 "multipoint_b_500k",
183 multipoint_b, join, end_flat,
184 distance_strategy(10000000), side_strategy, point_circle(500000),
185 314162054419515.562, tolerance);
186 #endif
187 }
188
189 int test_main(int, char* [])
190 {
191 test_all<true, bg::model::point<double, 2, bg::cs::cartesian> >();
192 test_all<false, bg::model::point<double, 2, bg::cs::cartesian> >();
193
194 #if defined(BOOST_GEOMETRY_COMPILER_MODE_RELEASE) && ! defined(BOOST_GEOMETRY_COMPILER_MODE_DEBUG)
195 test_many_points_per_circle<bg::model::point<double, 2, bg::cs::cartesian> >();
196 #else
197 std::cout << "Skipping some tests in debug or unknown mode" << std::endl;
198 #endif
199
200 return 0;
201 }