buffer_multi_point.cpp 9.1 KB

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