intersection_multi.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2010-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2016.
  5. // Modifications copyright (c) 2016, Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include <iostream>
  11. #include <string>
  12. #include "test_intersection.hpp"
  13. #include <algorithms/test_overlay.hpp>
  14. #include <algorithms/overlay/multi_overlay_cases.hpp>
  15. #include <boost/geometry/algorithms/correct.hpp>
  16. #include <boost/geometry/algorithms/intersection.hpp>
  17. #include <boost/geometry/geometries/point_xy.hpp>
  18. #include <boost/geometry/geometries/multi_point.hpp>
  19. #include <boost/geometry/geometries/multi_linestring.hpp>
  20. #include <boost/geometry/geometries/multi_polygon.hpp>
  21. #include <boost/geometry/io/wkt/read.hpp>
  22. #define TEST_INTERSECTION(caseid, clips, points, area) \
  23. (test_one<Polygon, MultiPolygon, MultiPolygon>) \
  24. ( #caseid, caseid[0], caseid[1], clips, points, area)
  25. #define TEST_INTERSECTION_REV(caseid, clips, points, area) \
  26. (test_one<Polygon, MultiPolygon, MultiPolygon>) \
  27. ( #caseid "_rev", caseid[1], caseid[0], clips, points, area)
  28. #define TEST_INTERSECTION_IGNORE(caseid, clips, points, area) \
  29. { ut_settings ignore_validity; ignore_validity.test_validity = false; \
  30. (test_one<Polygon, MultiPolygon, MultiPolygon>) \
  31. ( #caseid, caseid[0], caseid[1], clips, points, area, ignore_validity); }
  32. template <typename Ring, typename Polygon, typename MultiPolygon>
  33. void test_areal()
  34. {
  35. test_one<Polygon, MultiPolygon, MultiPolygon>("simplex_multi",
  36. case_multi_simplex[0], case_multi_simplex[1],
  37. 2, 12, 6.42);
  38. test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_no_ip",
  39. case_multi_no_ip[0], case_multi_no_ip[1],
  40. 2, 8, 8.5);
  41. test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_2",
  42. case_multi_2[0], case_multi_2[1],
  43. 3, 12, 5.9);
  44. test_one<Polygon, MultiPolygon, Polygon>("simplex_multi_mp_p",
  45. case_multi_simplex[0], case_single_simplex,
  46. 2, 12, 6.42);
  47. test_one<Polygon, Ring, MultiPolygon>("simplex_multi_r_mp",
  48. case_single_simplex, case_multi_simplex[0],
  49. 2, 12, 6.42);
  50. test_one<Ring, MultiPolygon, Polygon>("simplex_multi_mp_r",
  51. case_multi_simplex[0], case_single_simplex,
  52. 2, 12, 6.42);
  53. test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_a",
  54. case_58_multi[0], case_58_multi[3],
  55. 3, 12, 0.666666667);
  56. test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b",
  57. case_58_multi[1], case_58_multi[2],
  58. 1, 19, 11.16666666667);
  59. test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b4",
  60. case_58_multi[4], case_58_multi[2],
  61. 1, 13, 12.66666666);
  62. test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b5",
  63. case_58_multi[5], case_58_multi[2],
  64. 1, 13, 13.25);
  65. test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b6",
  66. case_58_multi[6], case_58_multi[2],
  67. 1, 13, 13.25);
  68. test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b7",
  69. case_58_multi[7], case_58_multi[2],
  70. 1, 16, 12.5);
  71. // Constructed cases for multi/touch/equal/etc
  72. test_one<Polygon, MultiPolygon, MultiPolygon>("case_61_multi",
  73. case_61_multi[0], case_61_multi[1],
  74. 0, 0, 0.0);
  75. test_one<Polygon, MultiPolygon, MultiPolygon>("case_62_multi",
  76. case_62_multi[0], case_62_multi[1],
  77. 1, 5, 1.0);
  78. test_one<Polygon, MultiPolygon, MultiPolygon>("case_63_multi",
  79. case_63_multi[0], case_63_multi[1],
  80. 1, 5, 1.0);
  81. test_one<Polygon, MultiPolygon, MultiPolygon>("case_64_multi",
  82. case_64_multi[0], case_64_multi[1],
  83. 1, 5, 1.0);
  84. test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi",
  85. case_65_multi[0], case_65_multi[1],
  86. 1, 5, 1.0);
  87. test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi_inv_a",
  88. case_65_multi[0], case_65_multi[3],
  89. 0, 0, 0.0);
  90. test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi_inv_b",
  91. case_65_multi[1], case_65_multi[2],
  92. 2, 10, 3.0);
  93. test_one<Polygon, MultiPolygon, MultiPolygon>("case_72_multi",
  94. case_72_multi[0], case_72_multi[1],
  95. 3, 14, 2.85);
  96. test_one<Polygon, MultiPolygon, MultiPolygon>("case_72_multi_inv_b",
  97. case_72_multi[1], case_72_multi[2],
  98. 3, 16, 6.15);
  99. test_one<Polygon, MultiPolygon, MultiPolygon>("case_77_multi",
  100. case_77_multi[0], case_77_multi[1],
  101. 5, 27, 9.0);
  102. test_one<Polygon, MultiPolygon, MultiPolygon>("case_78_multi",
  103. case_78_multi[0], case_78_multi[1],
  104. 1, 16, 22.0);
  105. test_one<Polygon, MultiPolygon, MultiPolygon>("case_101_multi",
  106. case_101_multi[0], case_101_multi[1],
  107. 4, 22, 4.75);
  108. test_one<Polygon, MultiPolygon, MultiPolygon>("case_102_multi",
  109. case_102_multi[0], case_102_multi[1],
  110. 3, 26, 19.75);
  111. test_one<Polygon, MultiPolygon, MultiPolygon>("case_102_multi_inv_b",
  112. case_102_multi[1], case_102_multi[2],
  113. 6, 25, 3.75);
  114. test_one<Polygon, MultiPolygon, MultiPolygon>("case_107_multi",
  115. case_107_multi[0], case_107_multi[1],
  116. 2, 10, 1.5);
  117. test_one<Polygon, MultiPolygon, MultiPolygon>("case_107_multi_inv_b",
  118. case_107_multi[1], case_107_multi[2],
  119. 3, 13, 3.0);
  120. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  121. {
  122. // Rescaling misses one intersection
  123. test_one<Polygon, MultiPolygon, MultiPolygon>("case_108_multi",
  124. case_108_multi[0], case_108_multi[1],
  125. 7, -1, 7.5);
  126. }
  127. #endif
  128. TEST_INTERSECTION(case_123_multi, 3, 13, 1.875);
  129. TEST_INTERSECTION(case_124_multi, 2, 13, 2.0625);
  130. TEST_INTERSECTION(case_125_multi, 3, 17, 2.1);
  131. TEST_INTERSECTION(case_126_multi, 5, 27, 9.0);
  132. TEST_INTERSECTION(case_127_multi, 3, 19, 24.0);
  133. TEST_INTERSECTION(case_128_multi, 2, 26, 75.5);
  134. TEST_INTERSECTION(case_129_multi, 1, 20, 20.5);
  135. TEST_INTERSECTION(case_130_multi, 2, 30, 39.0);
  136. TEST_INTERSECTION(case_133_multi, 2, 23, 40.625);
  137. TEST_INTERSECTION(case_134_multi, 1, 23, 42.0);
  138. TEST_INTERSECTION(case_135_multi, 1, 12, 7.0);
  139. TEST_INTERSECTION(case_136_multi, 1, 12, 6.5);
  140. TEST_INTERSECTION(case_137_multi, 1, 12, 6.5);
  141. TEST_INTERSECTION(case_138_multi, 2, 23, 40.4);
  142. TEST_INTERSECTION(case_139_multi, 2, 23, 40.546875);
  143. TEST_INTERSECTION(case_140_multi, 2, 23, 40.546875);
  144. TEST_INTERSECTION(case_141_multi, 3, -1, 74.5);
  145. TEST_INTERSECTION(case_recursive_boxes_1, 10, 89, 47.0);
  146. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_2",
  147. case_recursive_boxes_2[0], case_recursive_boxes_2[1],
  148. 1, 50, 90.0); // Area from SQL Server
  149. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_3",
  150. case_recursive_boxes_3[0], case_recursive_boxes_3[1],
  151. 19, 84, 12.5); // Area from SQL Server
  152. TEST_INTERSECTION_IGNORE(case_recursive_boxes_4, 13, 158, 67.0);
  153. // Fixed by replacing handle_tangencies in less_by_segment_ratio sort order
  154. // Should contain 6 output polygons
  155. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_6",
  156. case_recursive_boxes_6[0], case_recursive_boxes_6[1],
  157. 6, 42, 19.0);
  158. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_7",
  159. case_recursive_boxes_7[0], case_recursive_boxes_7[1],
  160. 2, 9, 1.5);
  161. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_8",
  162. case_recursive_boxes_8[0], case_recursive_boxes_8[1],
  163. 3, 19, 3.75);
  164. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_9",
  165. case_recursive_boxes_9[0], case_recursive_boxes_9[1],
  166. 5, 27, 4.25);
  167. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_10",
  168. case_recursive_boxes_10[0], case_recursive_boxes_10[1],
  169. 2, 8, 0.75);
  170. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_11",
  171. case_recursive_boxes_11[0], case_recursive_boxes_11[1],
  172. 2, 8, 1.0);
  173. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_12",
  174. case_recursive_boxes_12[0], case_recursive_boxes_12[1],
  175. 1, 4, 0.5);
  176. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_13",
  177. case_recursive_boxes_13[0], case_recursive_boxes_13[1],
  178. 0, 0, 0.0);
  179. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_14",
  180. case_recursive_boxes_14[0], case_recursive_boxes_14[1],
  181. 0, 0, 0.0);
  182. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_15",
  183. case_recursive_boxes_15[0], case_recursive_boxes_15[1],
  184. 1, 4, 0.5);
  185. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_16",
  186. case_recursive_boxes_16[0], case_recursive_boxes_16[1],
  187. 9, 43, 10.0);
  188. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_17",
  189. case_recursive_boxes_17[0], case_recursive_boxes_17[1],
  190. 7, -1, 7.75);
  191. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_18",
  192. case_recursive_boxes_18[0], case_recursive_boxes_18[1],
  193. 0, 0, 0.0);
  194. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_19",
  195. case_recursive_boxes_19[0], case_recursive_boxes_19[1],
  196. 0, 0, 0.0);
  197. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_20",
  198. case_recursive_boxes_20[0], case_recursive_boxes_20[1],
  199. 2, 0, 1.0);
  200. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_21",
  201. case_recursive_boxes_21[0], case_recursive_boxes_21[1],
  202. 1, 0, 0.5);
  203. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_22",
  204. case_recursive_boxes_22[0], case_recursive_boxes_22[1],
  205. 0, 0, 0.0);
  206. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_23",
  207. case_recursive_boxes_23[0], case_recursive_boxes_23[1],
  208. 1, 0, 0.5);
  209. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_24",
  210. case_recursive_boxes_24[0], case_recursive_boxes_24[1],
  211. 1, 0, 0.5);
  212. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_25",
  213. case_recursive_boxes_25[0], case_recursive_boxes_25[1],
  214. 1, 0, 0.5);
  215. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_26",
  216. case_recursive_boxes_26[0], case_recursive_boxes_26[1],
  217. 1, 0, 2.5);
  218. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_27",
  219. case_recursive_boxes_27[0], case_recursive_boxes_27[1],
  220. 1, 0, 0.5);
  221. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_28",
  222. case_recursive_boxes_28[0], case_recursive_boxes_28[1],
  223. 2, 0, 1.0);
  224. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_29",
  225. case_recursive_boxes_29[0], case_recursive_boxes_29[1],
  226. 5, 0, 3.75);
  227. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_30",
  228. case_recursive_boxes_30[0], case_recursive_boxes_30[1],
  229. 4, 0, 6.0);
  230. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_31",
  231. case_recursive_boxes_31[0], case_recursive_boxes_31[1],
  232. 2, 0, 2.5);
  233. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_32",
  234. case_recursive_boxes_32[0], case_recursive_boxes_32[1],
  235. 2, 0, 1.75);
  236. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_33",
  237. case_recursive_boxes_33[0], case_recursive_boxes_33[1],
  238. 3, 0, 2.0);
  239. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_34",
  240. case_recursive_boxes_34[0], case_recursive_boxes_34[1],
  241. 2, 0, 17.25);
  242. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_35",
  243. case_recursive_boxes_35[0], case_recursive_boxes_35[1],
  244. 2, 0, 20.0);
  245. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_36",
  246. case_recursive_boxes_36[0], case_recursive_boxes_36[1],
  247. 1, 0, 0.5);
  248. test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_37",
  249. case_recursive_boxes_37[0], case_recursive_boxes_37[1],
  250. 2, 0, 1.0);
  251. TEST_INTERSECTION(case_recursive_boxes_39, 3, 0, 3.0);
  252. TEST_INTERSECTION(case_recursive_boxes_40, 1, 0, 1.0);
  253. TEST_INTERSECTION(case_recursive_boxes_41, 1, 0, 23.5);
  254. TEST_INTERSECTION(case_recursive_boxes_42, 1, 29, 95.0);
  255. TEST_INTERSECTION(case_recursive_boxes_43, 2, 0, 22.5);
  256. TEST_INTERSECTION(case_recursive_boxes_44, 2, 0, 3.0);
  257. TEST_INTERSECTION(case_recursive_boxes_45, 7, 0, 12.0);
  258. TEST_INTERSECTION(case_recursive_boxes_46, 6, -1, 7.0);
  259. TEST_INTERSECTION(case_recursive_boxes_47, 1, 5, 1.0);
  260. TEST_INTERSECTION(case_recursive_boxes_48, 1, 5, 1.0);
  261. TEST_INTERSECTION(case_recursive_boxes_49, 7, 57, 20.0);
  262. TEST_INTERSECTION(case_recursive_boxes_50, 9, 62, 26.0);
  263. TEST_INTERSECTION(case_recursive_boxes_51, 14, 74, 19.0);
  264. TEST_INTERSECTION(case_recursive_boxes_52, 8, -1, 22.0);
  265. TEST_INTERSECTION(case_recursive_boxes_53, 1, -1, 19.75);
  266. TEST_INTERSECTION(case_recursive_boxes_54, 3, -1, 10.0);
  267. TEST_INTERSECTION(case_recursive_boxes_55, 5, -1, 2.25);
  268. TEST_INTERSECTION(case_recursive_boxes_56, 1, -1, 0.5);
  269. TEST_INTERSECTION(case_recursive_boxes_57, 10, -1, 9.5);
  270. TEST_INTERSECTION(case_recursive_boxes_58, 1, -1, 0.25);
  271. TEST_INTERSECTION(case_recursive_boxes_59, 8, -1, 8.25);
  272. TEST_INTERSECTION(case_recursive_boxes_60, 8, -1, 10.0);
  273. TEST_INTERSECTION(case_recursive_boxes_61, 2, -1, 20.0);
  274. TEST_INTERSECTION(case_recursive_boxes_62, 9, -1, 10.5);
  275. TEST_INTERSECTION(case_recursive_boxes_63, 11, -1, 5.75);
  276. TEST_INTERSECTION(case_recursive_boxes_64, 5, -1, 17.25);
  277. TEST_INTERSECTION(case_recursive_boxes_65, 3, -1, 17.25);
  278. TEST_INTERSECTION(case_recursive_boxes_66, 4, -1, 16.0);
  279. TEST_INTERSECTION(case_recursive_boxes_67, 5, -1, 2.5);
  280. TEST_INTERSECTION(case_recursive_boxes_68, 8, -1, 9.5);
  281. TEST_INTERSECTION(case_recursive_boxes_69, 6, -1, 3.25);
  282. TEST_INTERSECTION(case_recursive_boxes_70, 6, -1, 18.5);
  283. TEST_INTERSECTION(case_recursive_boxes_71, 3, -1, 1.75);
  284. TEST_INTERSECTION(case_recursive_boxes_72, 8, -1, 4.5);
  285. TEST_INTERSECTION(case_recursive_boxes_73, 3, -1, 18.5);
  286. TEST_INTERSECTION(case_recursive_boxes_74, 3, -1, 20.25);
  287. TEST_INTERSECTION(case_recursive_boxes_75, 5, -1, 16.75);
  288. TEST_INTERSECTION(case_recursive_boxes_76, 2, -1, 18.25);
  289. TEST_INTERSECTION(case_recursive_boxes_77, 5, -1, 3.5);
  290. TEST_INTERSECTION(case_recursive_boxes_78, 9, -1, 8.0);
  291. TEST_INTERSECTION(case_recursive_boxes_79, 5, -1, 9.0);
  292. TEST_INTERSECTION(case_recursive_boxes_80, 1, -1, 0.25);
  293. TEST_INTERSECTION(case_recursive_boxes_81, 5, -1, 3.75);
  294. TEST_INTERSECTION(case_recursive_boxes_82, 5, -1, 8.5);
  295. TEST_INTERSECTION(case_recursive_boxes_83, 5, -1, 10.25);
  296. TEST_INTERSECTION(case_recursive_boxes_84, 1, -1, 0.5);
  297. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  298. TEST_INTERSECTION(case_recursive_boxes_85, 1, -1, 0.25);
  299. #endif
  300. TEST_INTERSECTION(case_recursive_boxes_86, 0, -1, 0.0);
  301. TEST_INTERSECTION(case_recursive_boxes_87, 0, -1, 0.0);
  302. TEST_INTERSECTION(case_recursive_boxes_88, 4, -1, 3.5);
  303. #if ! defined(BOOST_GEOMETRY_USE_RESCALING)
  304. TEST_INTERSECTION(case_precision_m1, 1, -1, 14.0);
  305. TEST_INTERSECTION(case_precision_m2, 2, -1, 15.25);
  306. TEST_INTERSECTION_REV(case_precision_m1, 1, -1, 14.0);
  307. TEST_INTERSECTION_REV(case_precision_m2, 2, -1, 15.25);
  308. #else
  309. // Validity: false positives (very small triangles looking like a line)
  310. TEST_INTERSECTION_IGNORE(case_precision_m1, 1, -1, 14.0);
  311. TEST_INTERSECTION_IGNORE(case_precision_m2, 2, -1, 15.25);
  312. #endif
  313. test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_a",
  314. ggl_list_20120915_h2[0], ggl_list_20120915_h2[1],
  315. 2, 10, 6.0); // Area from SQL Server
  316. test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_b",
  317. ggl_list_20120915_h2[0], ggl_list_20120915_h2[2],
  318. 2, 10, 6.0); // Area from SQL Server
  319. test_one<Polygon, MultiPolygon, MultiPolygon>("ticket_9081",
  320. ticket_9081[0], ticket_9081[1],
  321. 2, 10, 0.0019812556);
  322. // Should generate output, even for <float>
  323. test_one<Polygon, MultiPolygon, MultiPolygon>("mail_2019_01_21_johan",
  324. mail_2019_01_21_johan[2], mail_2019_01_21_johan[3],
  325. 2, -1, 0.0005889587);
  326. // Very small slice is generated.
  327. // qcc-arm reports 1.7791215549400884e-14
  328. // With rescaling, generates very small triangle
  329. test_one<Polygon, MultiPolygon, MultiPolygon>("ticket_11018",
  330. ticket_11018[0], ticket_11018[1],
  331. BG_IF_RESCALED(1, 0), 0,
  332. 1.0e-8, ut_settings(-1)
  333. );
  334. TEST_INTERSECTION(ticket_12503, 2, 13, 17.375);
  335. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  336. // Result is wrong with rescaling
  337. TEST_INTERSECTION(issue_630_a, 1, -1, 0.1770);
  338. #endif
  339. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  340. // Two cases produce either too large, or no output if Kramer rule is used
  341. TEST_INTERSECTION(issue_630_b, 1, -1, BG_IF_KRAMER(0.1714, 0.1713911));
  342. TEST_INTERSECTION(issue_630_c, 1, -1, 0.1770);
  343. #endif
  344. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  345. // Result is missing with rescaling
  346. TEST_INTERSECTION(issue_643, 1, -1, 3.4615);
  347. #endif
  348. test_one<Polygon, MultiPolygon, MultiPolygon>("mysql_23023665_7",
  349. mysql_23023665_7[0], mysql_23023665_7[1],
  350. 2, 11, 9.80505786783);
  351. TEST_INTERSECTION(mysql_23023665_12, 2, 0, 11.812440191387557);
  352. TEST_INTERSECTION(mysql_regression_1_65_2017_08_31, 2, -1, 29.9022122);
  353. }
  354. template <typename Polygon, typename MultiPolygon, typename Box>
  355. void test_areal_clip()
  356. {
  357. static std::string const clip = "POLYGON((1 1,4 4))";
  358. test_one<Polygon, Box, MultiPolygon>("simplex_multi_mp_b", clip, case_multi_simplex[0],
  359. 2, 11, 6.791666);
  360. test_one<Polygon, MultiPolygon, Box>("simplex_multi_b_mp", case_multi_simplex[0], clip,
  361. 2, 11, 6.791666);
  362. }
  363. template <typename LineString, typename MultiLineString, typename Box>
  364. void test_linear()
  365. {
  366. typedef typename bg::point_type<MultiLineString>::type point;
  367. test_one<point, MultiLineString, MultiLineString>("case_multi_ml_ml_1",
  368. "MULTILINESTRING((0 0,1 1))", "MULTILINESTRING((0 1,1 0))",
  369. 1, 1, 0.0);
  370. test_one<point, MultiLineString, MultiLineString>("case_multi_ml_ml_2",
  371. "MULTILINESTRING((0 0,1 1),(0.5 0,1.5 1))", "MULTILINESTRING((0 1,1 0),(0.5 1,1.5 0))",
  372. 4, 4, 0.0);
  373. test_one<point, LineString, MultiLineString>("case_multi_l_ml",
  374. "LINESTRING(0 0,1 1)", "MULTILINESTRING((0 1,1 0),(0.5 1,1.5 0))",
  375. 2, 2, 0.0);
  376. test_one<point, MultiLineString, LineString>("case_multi_ml_l",
  377. "MULTILINESTRING((0 1,1 0),(0.5 1,1.5 0))", "LINESTRING(0 0,1 1)",
  378. 2, 2, 0.0);
  379. test_one<LineString, MultiLineString, Box>("case_multi_ml_b",
  380. "MULTILINESTRING((0 0,3 3)(1 0,4 3))", "POLYGON((1 1,3 2))",
  381. 2, 4, 2.0 * std::sqrt(2.0));
  382. test_one<LineString, Box, MultiLineString>("case_multi_b_ml",
  383. "POLYGON((1 1,3 2))", "MULTILINESTRING((0 0,3 3)(1 0,4 3))",
  384. 2, 4, 2.0 * std::sqrt(2.0));
  385. }
  386. template <typename P>
  387. void test_point_output()
  388. {
  389. typedef bg::model::box<P> box;
  390. typedef bg::model::linestring<P> linestring;
  391. typedef bg::model::polygon<P> polygon;
  392. typedef bg::model::multi_polygon<polygon> multi_polygon;
  393. test_point_output<multi_polygon, multi_polygon>(case_multi_simplex[0], case_multi_simplex[1], 10);
  394. test_point_output<linestring, multi_polygon>("linestring(4 0,0 4)", case_multi_simplex[0], 4);
  395. test_point_output<box, multi_polygon>("box(3 0,4 6)", case_multi_simplex[0], 8);
  396. }
  397. template <typename MultiPolygon, typename MultiLineString>
  398. void test_areal_linear()
  399. {
  400. typedef typename boost::range_value<MultiPolygon>::type Polygon;
  401. typedef typename boost::range_value<MultiLineString>::type LineString;
  402. typedef typename bg::point_type<Polygon>::type Point;
  403. typedef bg::model::ring<Point> Ring;
  404. test_one_lp<LineString, MultiPolygon, LineString>("case_mp_ls_1", case_multi_simplex[0], "LINESTRING(2 0,2 5)", 2, 4, 3.70);
  405. test_one_lp<LineString, Polygon, MultiLineString>("case_p_mls_1", case_single_simplex, "MULTILINESTRING((2 0,2 5),(3 0,3 5))", 2, 4, 7.5);
  406. test_one_lp<LineString, MultiPolygon, MultiLineString>("case_mp_mls_1", case_multi_simplex[0], "MULTILINESTRING((2 0,2 5),(3 0,3 5))", 4, 8, 6.8333333);
  407. test_one_lp<LineString, Ring, MultiLineString>("case_r_mls_1", case_single_simplex, "MULTILINESTRING((2 0,2 5),(3 0,3 5))", 2, 4, 7.5);
  408. }
  409. template <typename P>
  410. void test_all()
  411. {
  412. typedef bg::model::ring<P> ring;
  413. typedef bg::model::polygon<P> polygon;
  414. typedef bg::model::multi_polygon<polygon> multi_polygon;
  415. test_areal<ring, polygon, multi_polygon>();
  416. #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  417. typedef bg::model::ring<P, false> ring_ccw;
  418. typedef bg::model::polygon<P, false> polygon_ccw;
  419. typedef bg::model::multi_polygon<polygon_ccw> multi_polygon_ccw;
  420. test_areal<ring_ccw, polygon_ccw, multi_polygon_ccw>();
  421. typedef bg::model::ring<P, true, false> ring_open;
  422. typedef bg::model::polygon<P, true, false> polygon_open;
  423. typedef bg::model::multi_polygon<polygon_open> multi_polygon_open;
  424. test_areal<ring_open, polygon_open, multi_polygon_open>();
  425. typedef bg::model::ring<P, false, false> ring_open_ccw;
  426. typedef bg::model::polygon<P, false, false> polygon_open_ccw;
  427. typedef bg::model::multi_polygon<polygon_open_ccw> multi_polygon_open_ccw;
  428. test_areal<ring_open_ccw, polygon_open_ccw, multi_polygon_open_ccw>();
  429. typedef bg::model::box<P> box;
  430. test_areal_clip<polygon, multi_polygon, box>();
  431. test_areal_clip<polygon_ccw, multi_polygon_ccw, box>();
  432. typedef bg::model::linestring<P> linestring;
  433. typedef bg::model::multi_linestring<linestring> multi_linestring;
  434. test_linear<linestring, multi_linestring, box>();
  435. test_areal_linear<multi_polygon, multi_linestring>();
  436. #endif
  437. test_point_output<P>();
  438. // linear
  439. }
  440. int test_main(int, char* [])
  441. {
  442. BoostGeometryWriteTestConfiguration();
  443. test_all<bg::model::d2::point_xy<default_test_type> >();
  444. #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  445. test_all<bg::model::d2::point_xy<float> >();
  446. #if defined(HAVE_TTMATH)
  447. std::cout << "Testing TTMATH" << std::endl;
  448. test_all<bg::model::d2::point_xy<ttmath_big> >();
  449. #endif
  450. #endif
  451. return 0;
  452. }