difference.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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 2015, 2016.
  5. // Modifications copyright (c) 2015-2016, Oracle and/or its affiliates.
  6. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <iomanip>
  12. #include <iostream>
  13. #include <sstream>
  14. #include <string>
  15. #include <boost/geometry/algorithms/correct.hpp>
  16. #include <boost/geometry/algorithms/is_valid.hpp>
  17. #include <boost/geometry/io/wkt/wkt.hpp>
  18. #include <boost/geometry/geometries/point_xy.hpp>
  19. #include "test_difference.hpp"
  20. #include <algorithms/test_overlay.hpp>
  21. #include <algorithms/overlay/overlay_cases.hpp>
  22. #include <algorithms/overlay/multi_overlay_cases.hpp>
  23. #ifdef HAVE_TTMATH
  24. # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
  25. #endif
  26. // Convenience macros (points are not checked)
  27. #define TEST_DIFFERENCE(caseid, clips1, area1, clips2, area2, clips3) \
  28. (test_one<polygon, polygon, polygon>) \
  29. ( #caseid, caseid[0], caseid[1], clips1, -1, area1, clips2, -1, area2, \
  30. clips3, -1, area1 + area2)
  31. #define TEST_DIFFERENCE_WITH(caseid, clips1, area1, clips2, area2, clips3) \
  32. (test_one<polygon, polygon, polygon>) \
  33. ( #caseid, caseid[0], caseid[1], clips1, -1, area1, clips2, -1, area2, \
  34. clips3, -1, area1 + area2, settings)
  35. template <typename P>
  36. void test_all()
  37. {
  38. typedef bg::model::polygon<P> polygon;
  39. typedef typename bg::coordinate_type<P>::type ct;
  40. ut_settings sym_settings;
  41. #if ! defined(BOOST_GEOMETRY_USE_RESCALING)
  42. sym_settings.sym_difference = false;
  43. #endif
  44. ut_settings ignore_validity_settings;
  45. ignore_validity_settings.test_validity = false;
  46. test_one<polygon, polygon, polygon>("simplex_normal",
  47. simplex_normal[0], simplex_normal[1],
  48. 3, 12, 2.52636706856656,
  49. 3, 12, 3.52636706856656,
  50. sym_settings);
  51. test_one<polygon, polygon, polygon>("simplex_with_empty",
  52. simplex_normal[0], polygon_empty,
  53. 1, 4, 8.0,
  54. 0, 0, 0.0);
  55. test_one<polygon, polygon, polygon>(
  56. "star_ring", example_star, example_ring,
  57. 5, 22, 1.1901714,
  58. 5, 27, 1.6701714,
  59. sym_settings);
  60. test_one<polygon, polygon, polygon>("two_bends",
  61. two_bends[0], two_bends[1],
  62. 1, 5, 8.0,
  63. 1, 5, 8.0);
  64. test_one<polygon, polygon, polygon>("star_comb_15",
  65. star_comb_15[0], star_comb_15[1],
  66. 30, -1, 227.658275102812,
  67. 30, -1, 480.485775259312,
  68. sym_settings);
  69. test_one<polygon, polygon, polygon>("new_hole",
  70. new_hole[0], new_hole[1],
  71. 1, 9, 7.0,
  72. 1, 13, 14.0);
  73. test_one<polygon, polygon, polygon>("crossed",
  74. crossed[0], crossed[1],
  75. 1, 18, 19.5,
  76. 1, 7, 2.5);
  77. test_one<polygon, polygon, polygon>("disjoint",
  78. disjoint[0], disjoint[1],
  79. 1, 5, 1.0,
  80. 1, 5, 1.0);
  81. // The too small one might be discarded (depending on point-type / compiler)
  82. // We check area only
  83. test_one<polygon, polygon, polygon>("distance_zero",
  84. distance_zero[0], distance_zero[1],
  85. -1, -1, 8.7048386,
  86. -1, -1, 0.0098387,
  87. tolerance(0.001));
  88. test_one<polygon, polygon, polygon>("equal_holes_disjoint",
  89. equal_holes_disjoint[0], equal_holes_disjoint[1],
  90. 1, 5, 9.0,
  91. 1, 5, 9.0);
  92. test_one<polygon, polygon, polygon>("only_hole_intersections1",
  93. only_hole_intersections[0], only_hole_intersections[1],
  94. 2, 10, 1.9090909,
  95. 4, 16, 10.9090909,
  96. sym_settings);
  97. test_one<polygon, polygon, polygon>("only_hole_intersection2",
  98. only_hole_intersections[0], only_hole_intersections[2],
  99. 3, 20, 30.9090909,
  100. 4, 16, 10.9090909,
  101. sym_settings);
  102. test_one<polygon, polygon, polygon>("first_within_second",
  103. first_within_second[1], first_within_second[0],
  104. 1, 10, 24,
  105. 0, 0, 0);
  106. test_one<polygon, polygon, polygon>("fitting",
  107. fitting[0], fitting[1],
  108. 1, 9, 21.0,
  109. 1, 4, 4.0,
  110. 1, 5, 25.0);
  111. test_one<polygon, polygon, polygon>("identical",
  112. identical[0], identical[1],
  113. 0, 0, 0.0,
  114. 0, 0, 0.0);
  115. test_one<polygon, polygon, polygon>("intersect_exterior_and_interiors_winded",
  116. intersect_exterior_and_interiors_winded[0], intersect_exterior_and_interiors_winded[1],
  117. 4, 20, 11.533333,
  118. 5, 26, 29.783333);
  119. test_one<polygon, polygon, polygon>("intersect_holes_intersect_and_disjoint",
  120. intersect_holes_intersect_and_disjoint[0], intersect_holes_intersect_and_disjoint[1],
  121. 2, 16, 15.75,
  122. 3, 17, 6.75,
  123. ignore_validity_settings);
  124. test_one<polygon, polygon, polygon>("intersect_holes_intersect_and_touch",
  125. intersect_holes_intersect_and_touch[0], intersect_holes_intersect_and_touch[1],
  126. 3, 21, 16.25,
  127. 3, 17, 6.25,
  128. ignore_validity_settings);
  129. {
  130. ut_settings settings = sym_settings;
  131. settings.percentage = 0.01;
  132. test_one<polygon, polygon, polygon>("intersect_holes_new_ring",
  133. intersect_holes_new_ring[0], intersect_holes_new_ring[1],
  134. 3, 15, 9.8961,
  135. 4, 25, 121.8961,
  136. settings);
  137. }
  138. test_one<polygon, polygon, polygon>("first_within_hole_of_second",
  139. first_within_hole_of_second[0], first_within_hole_of_second[1],
  140. 1, 5, 1,
  141. 1, 10, 16);
  142. test_one<polygon, polygon, polygon>("intersect_holes_disjoint",
  143. intersect_holes_disjoint[0], intersect_holes_disjoint[1],
  144. 2, 14, 16.0,
  145. 2, 10, 6.0);
  146. test_one<polygon, polygon, polygon>("intersect_holes_intersect",
  147. intersect_holes_intersect[0], intersect_holes_intersect[1],
  148. 2, 16, 15.75,
  149. 2, 12, 5.75,
  150. ignore_validity_settings);
  151. test_one<polygon, polygon, polygon>(
  152. "case4", case_4[0], case_4[1],
  153. 6, 28, 2.77878787878788,
  154. 4, 22, 4.77878787878788,
  155. sym_settings);
  156. test_one<polygon, polygon, polygon>(
  157. "case5", case_5[0], case_5[1],
  158. 8, 36, 2.43452380952381,
  159. 7, 33, 3.18452380952381);
  160. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  161. // Fails with rescaling, a-b is partly generated, b-a does not have any output
  162. // It failed already in 1.59
  163. test_one<polygon, polygon, polygon>("case_58_iet",
  164. case_58[0], case_58[2],
  165. 3, 12, 0.6666666667,
  166. 1, -1, 11.1666666667,
  167. 2, -1, 0.6666666667 + 11.1666666667);
  168. #endif
  169. test_one<polygon, polygon, polygon>("case_80",
  170. case_80[0], case_80[1],
  171. 1, 9, 44.5,
  172. 1, 10, 84.5);
  173. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  174. // Fails without rescaling, holes are not subtracted
  175. test_one<polygon, polygon, polygon>("case_81",
  176. case_81[0], case_81[1],
  177. 1, 8, 80.5,
  178. 1, 8, 83.0,
  179. 1, 12, 80.5 + 83.0);
  180. #endif
  181. test_one<polygon, polygon, polygon>("case_100",
  182. case_100[0], case_100[1],
  183. 1, 7, 3.125,
  184. 1, 7, 16.0,
  185. 1, 13, 16.0 + 3.125);
  186. test_one<polygon, polygon, polygon>("case_101",
  187. case_101[0], case_101[1],
  188. 3, 17, 13.75,
  189. 1, 4, 1.0);
  190. test_one<polygon, polygon, polygon>("case_102",
  191. case_102[0], case_102[1],
  192. 4, 18, 1.5,
  193. 3, 15, 4.0625);
  194. TEST_DIFFERENCE(case_105, 4, 8.0, 1, 16.0, 5);
  195. TEST_DIFFERENCE(case_106, 1, 17.5, 2, 32.5, 3);
  196. TEST_DIFFERENCE(case_107, 2, 18.0, 2, 29.0, 4);
  197. TEST_DIFFERENCE(case_precision_1, 1, 14.0, 1, BG_IF_KRAMER(8.00001, 8.0), 1);
  198. TEST_DIFFERENCE(case_precision_2, 1, 14.0, 1, 8.0, 1);
  199. TEST_DIFFERENCE(case_precision_3, 1, 14.0, 1, 8.0, 1);
  200. TEST_DIFFERENCE(case_precision_4, 1, 14.0, 1, 8.0, 1);
  201. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  202. TEST_DIFFERENCE(case_precision_5, 1, 14.0, 1, 8.0, 1);
  203. TEST_DIFFERENCE(case_precision_6, 0, 0.0, 1, 57.0, 1);
  204. #endif
  205. TEST_DIFFERENCE(case_precision_7, 1, 14.0, 1, 8.0, 1);
  206. TEST_DIFFERENCE(case_precision_8, 0, 0.0, 1, 59.0, 1);
  207. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  208. TEST_DIFFERENCE(case_precision_9, 0, 0.0, 1, 59.0, 1);
  209. TEST_DIFFERENCE(case_precision_10, 0, 0.0, 1, 59.0, 1);
  210. TEST_DIFFERENCE(case_precision_11, 0, 0.0, 1, 59.0, 1);
  211. #endif
  212. TEST_DIFFERENCE(case_precision_12, 1, 12.0, 0, 0.0, 1);
  213. TEST_DIFFERENCE(case_precision_13, 1, BG_IF_KRAMER(12.00002, 12.0), 0, 0.0, 1);
  214. TEST_DIFFERENCE(case_precision_14, 1, 14.0, 1, 8.0, 1);
  215. TEST_DIFFERENCE(case_precision_15, 0, 0.0, 1, 59.0, 1);
  216. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  217. TEST_DIFFERENCE(case_precision_16, 0, 0.0, 1, 59.0, 1);
  218. #endif
  219. TEST_DIFFERENCE(case_precision_17, 0, 0.0, 1, 59.0, 1);
  220. TEST_DIFFERENCE(case_precision_18, 0, 0.0, 1, 59.0, 1);
  221. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  222. TEST_DIFFERENCE(case_precision_19, 1, 0.0, 1, 59.0, 2);
  223. #endif
  224. TEST_DIFFERENCE(case_precision_20, 1, 14.0, 1, 8.0, 1);
  225. TEST_DIFFERENCE(case_precision_21, 1, 14.0, 1, 7.99999, 1);
  226. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  227. TEST_DIFFERENCE(case_precision_22, 0, 0.0, 1, 59.0, 1);
  228. TEST_DIFFERENCE(case_precision_23, 0, 0.0, 1, 59.0, 1);
  229. #endif
  230. TEST_DIFFERENCE(case_precision_24, 1, 14.0, 1, 8.0, 1);
  231. TEST_DIFFERENCE(case_precision_25, 1, 14.0, 1, 7.99999, 1);
  232. #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  233. TEST_DIFFERENCE(case_precision_26, 0, 0.0, 1, 59.0, 1);
  234. #endif
  235. test_one<polygon, polygon, polygon>("winded",
  236. winded[0], winded[1],
  237. 3, 37, 61,
  238. 1, 15, 13);
  239. test_one<polygon, polygon, polygon>("within_holes_disjoint",
  240. within_holes_disjoint[0], within_holes_disjoint[1],
  241. 2, 15, 25,
  242. 1, 5, 1);
  243. test_one<polygon, polygon, polygon>("side_side",
  244. side_side[0], side_side[1],
  245. 1, 5, 1,
  246. 1, 5, 1,
  247. 1, 7, 2);
  248. test_one<polygon, polygon, polygon>("buffer_mp1",
  249. buffer_mp1[0], buffer_mp1[1],
  250. 1, 61, 10.2717,
  251. 1, 61, 10.2717);
  252. if ( BOOST_GEOMETRY_CONDITION((boost::is_same<ct, double>::value)) )
  253. {
  254. test_one<polygon, polygon, polygon>("buffer_mp2",
  255. buffer_mp2[0], buffer_mp2[1],
  256. 1, 91, 12.09857,
  257. 1, 155, 24.19714,
  258. BG_IF_RESCALED(2, 1), -1, 12.09857 + 24.19714);
  259. }
  260. /*** TODO: self-tangencies for difference
  261. test_one<polygon, polygon, polygon>("wrapped_a",
  262. wrapped[0], wrapped[1],
  263. 3, 1, 61,
  264. 1, 0, 13);
  265. test_one<polygon, polygon, polygon>("wrapped_b",
  266. wrapped[0], wrapped[2],
  267. 3, 1, 61,
  268. 1, 0, 13);
  269. ***/
  270. {
  271. ut_settings settings;
  272. settings.percentage = BG_IF_RESCALED(0.001, 0.1);
  273. settings.test_validity = BG_IF_RESCALED(true, false);
  274. settings.sym_difference = BG_IF_RESCALED(true, false);
  275. // Isovist - the # output polygons differ per compiler/pointtype, (very) small
  276. // rings might be discarded. We check area only
  277. // SQL Server gives: 0.279121891701124 and 224.889211358929
  278. // PostGIS gives: 0.279121991127244 and 224.889205853156
  279. // No robustness gives: 0.279121991127106 and 224.825363749290
  280. test_one<polygon, polygon, polygon>("isovist",
  281. isovist1[0], isovist1[1],
  282. -1, -1, 0.279132,
  283. -1, -1, 224.8892,
  284. settings);
  285. }
  286. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
  287. {
  288. ut_settings settings;
  289. settings.percentage = 0.1;
  290. settings.test_validity = false;
  291. // SQL Server gives: 0.28937764436705 and 0.000786406897532288 with 44/35 rings
  292. // PostGIS gives: 0.30859375 and 0.033203125 with 35/35 rings
  293. TEST_DIFFERENCE_WITH(geos_1,
  294. -1, BG_IF_KRAMER(0.29171, 0.20705),
  295. -1, BG_IF_KRAMER(0.00076855, 0.00060440758),
  296. -1);
  297. }
  298. #endif
  299. {
  300. // MSVC 14 expects 138.69214 and 211.85913: increase percentage
  301. ut_settings settings = sym_settings;
  302. settings.percentage = 0.01;
  303. settings.test_validity = false;
  304. // Output polygons for sym difference might be combined
  305. test_one<polygon, polygon, polygon>("geos_2",
  306. geos_2[0], geos_2[1],
  307. 1, -1, 138.6923828,
  308. 1, -1, 211.859375,
  309. BG_IF_RESCALED(2, 1), -1, 138.6923828 + 211.859375,
  310. settings);
  311. }
  312. // Output polygons for sym difference might be combined
  313. test_one<polygon, polygon, polygon>("geos_3",
  314. geos_3[0], geos_3[1],
  315. 1, -1, 16211128.5,
  316. 1, -1, 13180420.0,
  317. BG_IF_RESCALED(1, 2), -1, 16211128.5 + 13180420.0,
  318. sym_settings);
  319. test_one<polygon, polygon, polygon>("geos_4",
  320. geos_4[0], geos_4[1],
  321. 1, -1, 971.9163115,
  322. 1, -1, 1332.4163115,
  323. sym_settings);
  324. test_one<polygon, polygon, polygon>("ggl_list_20110306_javier",
  325. ggl_list_20110306_javier[0], ggl_list_20110306_javier[1],
  326. 1, -1, 71495.3331,
  327. 2, -1, 8960.49049,
  328. 2, -1, 71495.3331 + 8960.49049);
  329. test_one<polygon, polygon, polygon>("ggl_list_20110307_javier",
  330. ggl_list_20110307_javier[0], ggl_list_20110307_javier[1],
  331. 1, if_typed<ct, float>(14, 13), 16815.6,
  332. 1, 4, 3200.4,
  333. tolerance(0.01));
  334. if ( BOOST_GEOMETRY_CONDITION((! boost::is_same<ct, float>::value)) )
  335. {
  336. TEST_DIFFERENCE(ggl_list_20110716_enrico,
  337. 3, 35723.8506317139, // TODO FOR GENERIC, misses one of three outputs
  338. 1, 58456.4964294434,
  339. 1);
  340. }
  341. #if defined(BOOST_GEOMETRY_USE_RESCALING) \
  342. || ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) \
  343. || defined(BOOST_GEOMETRY_TEST_FAILURES)
  344. {
  345. // Symmetric difference should output one polygon
  346. // Using rescaling, it currently outputs two.
  347. ut_settings settings;
  348. settings.test_validity = false;
  349. TEST_DIFFERENCE_WITH(ggl_list_20110820_christophe,
  350. 1, 2.8570121719168924,
  351. 1, 64.498061986388564,
  352. BG_IF_RESCALED(2, 1));
  353. }
  354. #endif
  355. test_one<polygon, polygon, polygon>("ggl_list_20120717_volker",
  356. ggl_list_20120717_volker[0], ggl_list_20120717_volker[1],
  357. 1, 11, 3370866.2295081965,
  358. 1, 5, 384.2295081964694,
  359. tolerance(0.01));
  360. // 2011-07-02 / 2014-06-19
  361. // Interesting FP-precision case.
  362. // sql server gives: 6.62295817619452E-05
  363. // PostGIS gives: 0.0 (no output)
  364. // Boost.Geometry gave results depending on FP-type, and compiler, and operating system.
  365. // With rescaling results are equal w.r.t. compiler/FP type,
  366. // however, some long spikes are still generated in the resulting difference
  367. // Without rescaling there is no output, like PostGIS
  368. test_one<polygon, polygon, polygon>("ggl_list_20110627_phillip",
  369. ggl_list_20110627_phillip[0], ggl_list_20110627_phillip[1],
  370. BG_IF_RESCALED(1, 0), -1,
  371. BG_IF_RESCALED(if_typed_tt<ct>(0.0000000000001105367, 0.000125137888971949), 0),
  372. 1, -1, 3577.40960816756,
  373. tolerance(0.01)
  374. );
  375. {
  376. // With rescaling, difference of output a-b and a sym b is invalid
  377. ut_settings settings;
  378. settings.test_validity = BG_IF_RESCALED(false, true);
  379. TEST_DIFFERENCE_WITH(ggl_list_20190307_matthieu_1,
  380. BG_IF_KRAMER(2, 1), 0.18461532,
  381. BG_IF_KRAMER(2, 1), 0.617978,
  382. BG_IF_KRAMER(4, 2));
  383. TEST_DIFFERENCE_WITH(ggl_list_20190307_matthieu_2, 2, 12.357152, 0, 0.0, 2);
  384. }
  385. // Ticket 8310, one should be completely subtracted from the other.
  386. test_one<polygon, polygon, polygon>("ticket_8310a",
  387. ticket_8310a[0], ticket_8310a[1],
  388. 1, 10, 10.11562724,
  389. 0, 0, 0);
  390. test_one<polygon, polygon, polygon>("ticket_8310b",
  391. ticket_8310b[0], ticket_8310b[1],
  392. 1, 10, 10.12655608,
  393. 0, 0, 0);
  394. test_one<polygon, polygon, polygon>("ticket_8310c",
  395. ticket_8310c[0], ticket_8310c[1],
  396. 1, 10, 10.03103292,
  397. 0, 0, 0);
  398. test_one<polygon, polygon, polygon>("ticket_9081_15",
  399. ticket_9081_15[0], ticket_9081_15[1],
  400. 2, -1, 0.0334529710902111,
  401. BG_IF_RESCALED(1, 0), -1, BG_IF_RESCALED(5.3469555172380723e-010, 0));
  402. test_one<polygon, polygon, polygon>("ticket_9081_314",
  403. ticket_9081_314[0], ticket_9081_314[1],
  404. 2, 12, 0.0451236449624935,
  405. 0, 0, 0);
  406. {
  407. ut_settings settings;
  408. settings.test_validity = BG_IF_RESCALED(true, false);
  409. #if ! defined(BOOST_GEOMETRY_USE_RESCALING) && defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
  410. const int expected_count = 1; // Wrong, considers all consecutive polygons as one
  411. #else
  412. const int expected_count = 6;
  413. #endif
  414. TEST_DIFFERENCE_WITH(ticket_9563,
  415. 0, 0,
  416. expected_count, 20.096189,
  417. expected_count);
  418. }
  419. test_one<polygon, polygon, polygon>("ticket_10108_a",
  420. ticket_10108_a[0], ticket_10108_a[1],
  421. 1, 4, 0.0145037,
  422. 1, 4, 0.029019232,
  423. sym_settings);
  424. test_one<polygon, polygon, polygon>("ticket_10108_b",
  425. ticket_10108_b[0], ticket_10108_b[1],
  426. 1, -1, 1081.68697,
  427. 1, -1, 1342.65795,
  428. BG_IF_RESCALED(2, 1), -1, 1081.68697 + 1342.65795);
  429. test_one<polygon, polygon, polygon>("ticket_11725",
  430. ticket_11725[0], ticket_11725[1],
  431. 1, -1, 3.0,
  432. 1, -1, 4.5,
  433. 1, -1, 7.5);
  434. // From assemble-test, with a u/u case
  435. test_one<polygon, polygon, polygon>("assemble_0210",
  436. "POLYGON((0 0,0 10,10 10,10 0,0 0),(8.5 1,9.5 1,9.5 2,8.5 2,8.5 1))",
  437. "POLYGON((2 0.5,0.5 2,0.5 8,2 9.5,6 9.5,8.5 8,8.5 2,7 0.5,2 0.5),(2 2,7 2,7 8,2 8,2 2))",
  438. 2, 23, 62.25,
  439. 0, 0, 0.0);
  440. #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  441. typedef bg::model::box<P> box;
  442. typedef bg::model::ring<P> ring;
  443. // Other combinations
  444. {
  445. test_one<polygon, polygon, ring>(
  446. "star_ring_ring", example_star, example_ring,
  447. 5, 22, 1.1901714,
  448. 5, 27, 1.6701714,
  449. sym_settings);
  450. test_one<polygon, ring, polygon>(
  451. "ring_star_ring", example_ring, example_star,
  452. 5, 27, 1.6701714,
  453. 5, 22, 1.1901714,
  454. sym_settings);
  455. static std::string const clip = "POLYGON((2.5 0.5,5.5 2.5))";
  456. test_one<polygon, box, ring>("star_box",
  457. clip, example_star,
  458. 4, 20, 2.833333, 4, 16, 0.833333);
  459. test_one<polygon, ring, box>("box_star",
  460. example_star, clip,
  461. 4, 16, 0.833333, 4, 20, 2.833333);
  462. }
  463. // Counter clockwise
  464. {
  465. typedef bg::model::polygon<P, false> polygon_ccw;
  466. test_one<polygon, polygon_ccw, polygon_ccw>(
  467. "star_ring_ccw", example_star, example_ring,
  468. 5, 22, 1.1901714,
  469. 5, 27, 1.6701714,
  470. sym_settings);
  471. test_one<polygon, polygon, polygon_ccw>(
  472. "star_ring_ccw1", example_star, example_ring,
  473. 5, 22, 1.1901714,
  474. 5, 27, 1.6701714,
  475. sym_settings);
  476. test_one<polygon, polygon_ccw, polygon>(
  477. "star_ring_ccw2", example_star, example_ring,
  478. 5, 22, 1.1901714,
  479. 5, 27, 1.6701714,
  480. sym_settings);
  481. }
  482. // Multi/box (should be moved to multi)
  483. {
  484. typedef bg::model::multi_polygon<polygon> mp;
  485. static std::string const clip = "POLYGON((2 2,4 4))";
  486. test_one<polygon, box, mp>("simplex_multi_box_mp",
  487. clip, case_multi_simplex[0],
  488. 2, -1, 0.53333333333, 3, -1, 8.53333333333);
  489. test_one<polygon, mp, box>("simplex_multi_mp_box",
  490. case_multi_simplex[0], clip,
  491. 3, -1, 8.53333333333, 2, -1, 0.53333333333);
  492. }
  493. #endif
  494. // Rescaling generates a very small false polygon
  495. {
  496. ut_settings settings;
  497. #if defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
  498. settings.test_validity = BG_IF_RESCALED(true, false);
  499. #endif
  500. TEST_DIFFERENCE_WITH(issue_566_a, 1, 143.662, BG_IF_RESCALED(1, 0),
  501. BG_IF_RESCALED(1.605078e-6, 0.0),
  502. BG_IF_RESCALED(2, 1));
  503. }
  504. TEST_DIFFERENCE(issue_566_b, 1, 143.662, BG_IF_RESCALED(1, 0),
  505. BG_IF_RESCALED(1.605078e-6, 0.0),
  506. BG_IF_RESCALED(2, 1));
  507. TEST_DIFFERENCE(mysql_21977775, 2, 160.856568913, 2, 92.3565689126, 4);
  508. TEST_DIFFERENCE(mysql_21965285, 1, 92.0, 1, 14.0, 1);
  509. TEST_DIFFERENCE(mysql_23023665_1, 1, 92.0, 1, 142.5, 2);
  510. TEST_DIFFERENCE(mysql_23023665_2, 1, 96.0, 1, 16.0, 2);
  511. TEST_DIFFERENCE(mysql_23023665_3, 1, 225.0, 1, 66.0, 2);
  512. TEST_DIFFERENCE(mysql_23023665_5, 2, 165.23735, 2, 105.73735, 4);
  513. #if defined(BOOST_GEOMETRY_USE_RESCALING) \
  514. || ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) \
  515. || defined(BOOST_GEOMETRY_TEST_FAILURES)
  516. // Testcases going wrong with Kramer's rule and no rescaling
  517. TEST_DIFFERENCE(mysql_23023665_6, 2, 105.68756, 3, 10.18756, 5);
  518. TEST_DIFFERENCE(mysql_23023665_13, 3, 99.74526, 3, 37.74526, 6);
  519. #endif
  520. }
  521. // Test cases for integer coordinates / ccw / open
  522. template <typename Point, bool ClockWise, bool Closed>
  523. void test_specific()
  524. {
  525. typedef bg::model::polygon<Point, ClockWise, Closed> polygon;
  526. test_one<polygon, polygon, polygon>("ggl_list_20120717_volker",
  527. ggl_list_20120717_volker[0], ggl_list_20120717_volker[1],
  528. 1, 11, 3371540,
  529. 1, 4, 385,
  530. 1, 16, 3371540 + 385);
  531. test_one<polygon, polygon, polygon>("ticket_10658",
  532. ticket_10658[0], ticket_10658[1],
  533. 1, 6, 1510434,
  534. 0, 0, 0);
  535. test_one<polygon, polygon, polygon>("ticket_11121",
  536. ticket_11121[0], ticket_11121[1],
  537. 2, 8, 489763.5,
  538. 1, 4, 6731652.0);
  539. // Generates spikes, both a-b and b-a
  540. TEST_DIFFERENCE(ticket_11676, 2, 2537992.5, 2, 294963.5, 3);
  541. }
  542. int test_main(int, char* [])
  543. {
  544. BoostGeometryWriteTestConfiguration();
  545. test_all<bg::model::d2::point_xy<default_test_type> >();
  546. test_specific<bg::model::d2::point_xy<int>, false, false>();
  547. #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  548. test_all<bg::model::d2::point_xy<float> >();
  549. #ifdef HAVE_TTMATH
  550. std::cout << "Testing TTMATH" << std::endl;
  551. test_all<bg::model::d2::point_xy<ttmath_big> >();
  552. #endif
  553. #endif
  554. return 0;
  555. }