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 <test_buffer.hpp>
12 static std::string
const simplex
= "MULTIPOINT((5 5),(7 7))";
13 static std::string
const three
= "MULTIPOINT((5 8),(9 8),(7 11))";
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))";
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))";
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)";
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)";
27 static std::string
const mysql_report_3
= "MULTIPOINT(0 0,0 0,0 0,0 0,0 0)";
29 template <bool Clockwise
, typename P
>
32 typedef bg::model::polygon
<P
, Clockwise
> polygon
;
33 typedef bg::model::multi_point
<P
> multi_point_type
;
35 bg::strategy::buffer::join_round join
;
36 bg::strategy::buffer::end_flat end_flat
;
37 typedef bg::strategy::buffer::distance_symmetric
39 typename
bg::coordinate_type
<P
>::type
41 bg::strategy::buffer::side_straight side_strategy
;
43 double const pi
= boost::geometry::math::pi
<double>();
45 test_one
<multi_point_type
, polygon
>("simplex1", simplex
, join
, end_flat
, 2.0 * pi
, 1.0);
46 test_one
<multi_point_type
, polygon
>("simplex2", simplex
, join
, end_flat
, 22.8372, 2.0);
47 test_one
<multi_point_type
, polygon
>("simplex3", simplex
, join
, end_flat
, 44.5692, 3.0);
49 test_one
<multi_point_type
, polygon
>("three1", three
, join
, end_flat
, 3.0 * pi
, 1.0);
50 #if !defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
51 // For no-rescaling, fails in CCW mode
52 test_one
<multi_point_type
, polygon
>("three2", three
, join
, end_flat
, 36.7592, 2.0);
54 test_one
<multi_point_type
, polygon
>("three19", three
, join
, end_flat
, 33.6914, 1.9);
55 test_one
<multi_point_type
, polygon
>("three21", three
, join
, end_flat
, 39.6394, 2.1);
56 test_one
<multi_point_type
, polygon
>("three3", three
, join
, end_flat
, 65.533, 3.0);
58 test_one
<multi_point_type
, polygon
>("multipoint_a", multipoint_a
, join
, end_flat
, 2049.98, 14.0);
59 test_one
<multi_point_type
, polygon
>("multipoint_b", multipoint_b
, join
, end_flat
, 7109.88, 15.0);
60 test_one
<multi_point_type
, polygon
>("multipoint_b1", multipoint_b
, join
, end_flat
, 6911.89, 14.7);
61 test_one
<multi_point_type
, polygon
>("multipoint_b2", multipoint_b
, join
, end_flat
, 7174.79, 15.1);
65 bg::strategy::buffer::point_square point_strategy
;
67 test_with_custom_strategies
<multi_point_type
, polygon
>("grid_a50",
68 grid_a
, join
, end_flat
,
69 distance_strategy(0.5), side_strategy
, point_strategy
, 7.0);
71 #if defined(BOOST_GEOMETRY_BUFFER_USE_SIDE_OF_INTERSECTION)
72 test_with_custom_strategies
<multi_point_type
, polygon
>("grid_a54",
73 grid_a
, join
, end_flat
,
74 distance_strategy(0.54), side_strategy
, point_strategy
, 7.819);
79 test_with_custom_strategies
<multi_point_type
, polygon
>("mysql_report_2015_02_25_1_800",
80 mysql_report_2015_02_25_1
, join
, end_flat
,
81 distance_strategy(6051788), side_strategy
,
82 bg::strategy::buffer::point_circle(800),
83 115057490003226.125, ut_settings(1.0));
87 bg::read_wkt(mysql_report_3
, g
);
88 test_buffer
<polygon
>("mysql_report_3", g
,
89 bg::strategy::buffer::join_round(36),
90 bg::strategy::buffer::end_round(36),
93 bg::strategy::buffer::point_circle(36),
94 1, 0, 3.12566719800474635, ut_settings(1.0));
99 void test_many_points_per_circle()
101 // Tests for large distances / many points in circles.
102 // Before Boost 1.58, this would (seem to) hang. It is solved by using monotonic sections in get_turns for buffer
103 // This is more time consuming, only calculate this for counter clockwise
104 // Reported by MySQL 2015-02-25
105 // SELECT ST_ASTEXT(ST_BUFFER(ST_GEOMFROMTEXT(''), 6051788, ST_BUFFER_STRATEGY('point_circle', 83585)));
106 // SELECT ST_ASTEXT(ST_BUFFER(ST_GEOMFROMTEXT(''), 5666962, ST_BUFFER_STRATEGY('point_circle', 46641))) ;
108 typedef bg::model::polygon
<P
, false> polygon
;
109 typedef bg::model::multi_point
<P
> multi_point_type
;
111 bg::strategy::buffer::join_round join
;
112 bg::strategy::buffer::end_flat end_flat
;
113 typedef bg::strategy::buffer::distance_symmetric
115 typename
bg::coordinate_type
<P
>::type
117 bg::strategy::buffer::side_straight side_strategy
;
119 using bg::strategy::buffer::point_circle
;
121 #if defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
122 double const tolerance
= 1000.0;
124 double const tolerance
= 1.0;
127 // Area should be somewhat larger (~>) than pi*distance^2
128 // 6051788: area ~> 115058122875258
130 // Strategies with many points, which are (very) slow in debug mode
131 test_with_custom_strategies
<multi_point_type
, polygon
>(
132 "mysql_report_2015_02_25_1_8000",
133 mysql_report_2015_02_25_1
, join
, end_flat
,
134 distance_strategy(6051788), side_strategy
, point_circle(8000),
135 115058661065242.812, ut_settings(10.0 * tolerance
));
138 // 115058672785641.031
139 // 115058672785680.281
140 // 115058672785679.922
141 test_with_custom_strategies
<multi_point_type
, polygon
>(
142 "mysql_report_2015_02_25_1",
143 mysql_report_2015_02_25_1
, join
, end_flat
,
144 distance_strategy(6051788), side_strategy
, point_circle(83585),
145 115058672785660.0, ut_settings(25.0 * tolerance
));
147 // Takes about 7 seconds in release mode
149 // 115058672880035.391
150 // 115058672879944.547
151 // 115058672879920.484
152 test_with_custom_strategies
<multi_point_type
, polygon
>(
153 "mysql_report_2015_02_25_1_250k",
154 mysql_report_2015_02_25_1
, join
, end_flat
,
155 distance_strategy(6051788), side_strategy
, point_circle(250000),
156 115058672879977.0, ut_settings(75.0 * tolerance
));
158 #if defined(BOOST_GEOMETRY_BUFFER_INCLUDE_SLOW_TESTS)
159 // Takes about 110 seconds in release mode
160 test_with_custom_strategies
<multi_point_type
, polygon
>(
161 "mysql_report_2015_02_25_1_800k",
162 mysql_report_2015_02_25_1
, join
, end_flat
,
163 distance_strategy(6051788), side_strategy
, point_circle(800000),
164 115058672871849.219, ut_settings(tolerance
));
167 // 5666962: area ~> 100890546298964
169 // 100891031341796.875
170 // 100891031341794.766
171 // 100891031341794.078
172 test_with_custom_strategies
<multi_point_type
, polygon
>(
173 "mysql_report_2015_02_25_2",
174 mysql_report_2015_02_25_2
, join
, end_flat
,
175 distance_strategy(5666962), side_strategy
, point_circle(46641),
176 100891031341795.0, ut_settings(3.0 * tolerance
));
178 // Multipoint b with large distances/many points
183 // 3141871558231.5166
184 // 3141871558231.48926
186 test_with_custom_strategies
<multi_point_type
, polygon
>(
188 multipoint_b
, join
, end_flat
,
189 distance_strategy(1000000), side_strategy
, point_circle(50000),
190 3141871558227.0, ut_settings(10.0 * tolerance
));
192 #if defined(BOOST_GEOMETRY_BUFFER_INCLUDE_SLOW_TESTS)
193 // Tests optimization min/max radius
194 // Takes about 55 seconds in release mode
195 test_with_custom_strategies
<multi_point_type
, polygon
>(
197 multipoint_b
, join
, end_flat
,
198 distance_strategy(10000000), side_strategy
, point_circle(500000),
199 314162054419515.562, ut_settings((tolerance
));
203 int test_main(int, char* [])
205 test_all
<true, bg::model::point
<double, 2, bg::cs::cartesian
> >();
206 test_all
<false, bg::model::point
<double, 2, bg::cs::cartesian
> >();
208 #if defined(BOOST_GEOMETRY_COMPILER_MODE_RELEASE) && ! defined(BOOST_GEOMETRY_COMPILER_MODE_DEBUG)
209 test_many_points_per_circle
<bg::model::point
<double, 2, bg::cs::cartesian
> >();
211 std::cout
<< "Skipping some tests in debug or unknown mode" << std::endl
;