is_valid_failure.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2015-2018, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Licensed under the Boost Software License version 1.0.
  7. // http://www.boost.org/users/license.html
  8. #ifndef BOOST_TEST_MODULE
  9. #define BOOST_TEST_MODULE test_is_valid_failure
  10. #endif
  11. #include <iostream>
  12. #include <string>
  13. #include <boost/variant/variant.hpp>
  14. #include <boost/test/included/unit_test.hpp>
  15. #include <boost/geometry/core/cs.hpp>
  16. #include <boost/geometry/geometries/geometries.hpp>
  17. #include <boost/geometry/algorithms/is_valid.hpp>
  18. #include <boost/geometry/algorithms/reverse.hpp>
  19. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  20. #include <boost/geometry/io/wkt/wkt.hpp>
  21. #include <boost/geometry/strategies/strategies.hpp>
  22. #include <from_wkt.hpp>
  23. namespace bg = ::boost::geometry;
  24. typedef bg::validity_failure_type failure_type;
  25. typedef bg::model::point<double, 2, bg::cs::cartesian> point_type;
  26. typedef bg::model::segment<point_type> segment_type;
  27. typedef bg::model::box<point_type> box_type;
  28. typedef bg::model::linestring<point_type> linestring_type;
  29. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  30. typedef bg::model::multi_point<point_type> multi_point_type;
  31. char const* to_string(failure_type failure)
  32. {
  33. switch (failure)
  34. {
  35. case bg::no_failure:
  36. return "no_failure";
  37. case bg::failure_few_points:
  38. return "failure_few_points";
  39. case bg::failure_wrong_topological_dimension:
  40. return "failure_wrong_topological_dimension";
  41. case bg::failure_spikes:
  42. return "failure_spikes";
  43. case bg::failure_duplicate_points:
  44. return "failure_duplicate_points";
  45. case bg::failure_not_closed:
  46. return "failure_not_closed";
  47. case bg::failure_self_intersections:
  48. return "failure_self_intersections";
  49. case bg::failure_wrong_orientation:
  50. return "failure_wrong_orientation";
  51. case bg::failure_interior_rings_outside:
  52. return "failure_interior_rings_outside";
  53. case bg::failure_nested_interior_rings:
  54. return "failure_nested_interior_rings";
  55. case bg::failure_disconnected_interior:
  56. return "failure_disconnected_interior";
  57. case bg::failure_intersecting_interiors:
  58. return "failure_intersecting_interiors";
  59. case bg::failure_wrong_corner_order:
  60. return "failure_wrong_corner_order";
  61. default:
  62. return ""; // to avoid warnings (-Wreturn-type)
  63. }
  64. }
  65. template <typename Geometry>
  66. struct test_failure
  67. {
  68. static inline void apply(std::string const& case_id,
  69. Geometry const& geometry,
  70. failure_type expected)
  71. {
  72. failure_type detected;
  73. bg::is_valid(geometry, detected);
  74. std::string expected_msg = bg::validity_failure_type_message(expected);
  75. std::string detected_msg;
  76. bg::is_valid(geometry, detected_msg);
  77. std::string detected_msg_short
  78. = detected_msg.substr(0, expected_msg.length());
  79. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  80. std::cout << "----------------------" << std::endl;
  81. std::cout << "case id: " << case_id << std::endl;
  82. std::cout << "Geometry: " << bg::wkt(geometry) << std::endl;
  83. std::cout << "Expected reason: " << expected_msg << std::endl;
  84. std::cout << "Detected reason: " << detected_msg << std::endl;
  85. std::cout << "Expected: " << to_string(expected) << std::endl;
  86. std::cout << "Detected: " << to_string(detected) << std::endl;
  87. std::cout << std::endl;
  88. #endif
  89. BOOST_CHECK_MESSAGE(expected == detected,
  90. "case id: " << case_id
  91. << ", Geometry: " << bg::wkt(geometry)
  92. << ", expected: " << to_string(expected)
  93. << ", detected: " << to_string(detected));
  94. BOOST_CHECK(detected_msg_short == expected_msg);
  95. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  96. std::cout << "----------------------" << std::endl;
  97. std::cout << std::endl << std::endl;
  98. #endif
  99. }
  100. static inline void apply(std::string const& case_id,
  101. std::string const& wkt,
  102. failure_type expected)
  103. {
  104. Geometry geometry = from_wkt<Geometry>(wkt);
  105. apply(case_id, geometry, expected);
  106. }
  107. };
  108. BOOST_AUTO_TEST_CASE( test_failure_point )
  109. {
  110. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  111. std::cout << std::endl << std::endl;
  112. std::cout << "************************************" << std::endl;
  113. std::cout << " is_valid_failure: POINT " << std::endl;
  114. std::cout << "************************************" << std::endl;
  115. #endif
  116. typedef point_type G;
  117. typedef test_failure<G> test;
  118. test::apply("p01", "POINT(0 0)", bg::no_failure);
  119. }
  120. BOOST_AUTO_TEST_CASE( test_failure_multipoint )
  121. {
  122. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  123. std::cout << std::endl << std::endl;
  124. std::cout << "************************************" << std::endl;
  125. std::cout << " is_valid_failure: MULTIPOINT " << std::endl;
  126. std::cout << "************************************" << std::endl;
  127. #endif
  128. typedef multi_point_type G;
  129. typedef test_failure<G> test;
  130. test::apply("mp01", "MULTIPOINT()", bg::no_failure);
  131. test::apply("mp02", "MULTIPOINT(0 0,0 0)", bg::no_failure);
  132. test::apply("mp03", "MULTIPOINT(0 0,1 0,1 1,0 1)", bg::no_failure);
  133. test::apply("mp04", "MULTIPOINT(0 0,1 0,1 1,1 0,0 1)", bg::no_failure);
  134. }
  135. BOOST_AUTO_TEST_CASE( test_failure_segment )
  136. {
  137. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  138. std::cout << std::endl << std::endl;
  139. std::cout << "************************************" << std::endl;
  140. std::cout << " is_valid_failure: SEGMENT " << std::endl;
  141. std::cout << "************************************" << std::endl;
  142. #endif
  143. typedef segment_type G;
  144. typedef test_failure<G> test;
  145. test::apply("s01",
  146. "SEGMENT(0 0,0 0)",
  147. bg::failure_wrong_topological_dimension);
  148. test::apply("s02", "SEGMENT(0 0,1 0)", bg::no_failure);
  149. }
  150. BOOST_AUTO_TEST_CASE( test_failure_box )
  151. {
  152. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  153. std::cout << std::endl << std::endl;
  154. std::cout << "************************************" << std::endl;
  155. std::cout << " is_valid_failure: BOX " << std::endl;
  156. std::cout << "************************************" << std::endl;
  157. #endif
  158. typedef box_type G;
  159. typedef test_failure<G> test;
  160. // boxes where the max corner and below and/or to the left of min corner
  161. test::apply("b01",
  162. "BOX(0 0,-1 0)",
  163. bg::failure_wrong_topological_dimension);
  164. test::apply("b02", "BOX(0 0,0 -1)", bg::failure_wrong_corner_order);
  165. test::apply("b03", "BOX(0 0,-1 -1)", bg::failure_wrong_corner_order);
  166. // boxes of zero area; they are not 2-dimensional, so invalid
  167. test::apply("b04", "BOX(0 0,0 0)", bg::failure_wrong_topological_dimension);
  168. test::apply("b05", "BOX(0 0,1 0)", bg::failure_wrong_topological_dimension);
  169. test::apply("b06", "BOX(0 0,0 1)", bg::failure_wrong_topological_dimension);
  170. test::apply("b07", "BOX(0 0,1 1)", bg::no_failure);
  171. }
  172. BOOST_AUTO_TEST_CASE( test_failure_linestring )
  173. {
  174. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  175. std::cout << std::endl << std::endl;
  176. std::cout << "************************************" << std::endl;
  177. std::cout << " is_valid_failure: LINESTRING " << std::endl;
  178. std::cout << "************************************" << std::endl;
  179. #endif
  180. typedef linestring_type G;
  181. typedef test_failure<G> test;
  182. // empty linestring
  183. test::apply("l01", "LINESTRING()", bg::failure_few_points);
  184. // 1-point linestrings
  185. test::apply("l02", "LINESTRING(0 0)", bg::failure_few_points);
  186. test::apply("l03",
  187. "LINESTRING(0 0,0 0)",
  188. bg::failure_wrong_topological_dimension);
  189. test::apply("l04",
  190. "LINESTRING(0 0,0 0,0 0)",
  191. bg::failure_wrong_topological_dimension);
  192. // 2-point linestrings
  193. test::apply("l05", "LINESTRING(0 0,1 2)", bg::no_failure);
  194. test::apply("l06", "LINESTRING(0 0,1 2,1 2)", bg::no_failure);
  195. test::apply("l07", "LINESTRING(0 0,0 0,1 2,1 2)", bg::no_failure);
  196. test::apply("l08", "LINESTRING(0 0,0 0,0 0,1 2,1 2)", bg::no_failure);
  197. // 3-point linestring
  198. test::apply("l09", "LINESTRING(0 0,1 0,2 10)", bg::no_failure);
  199. // linestrings with spikes
  200. test::apply("l10", "LINESTRING(0 0,1 2,0 0)", bg::no_failure);
  201. }
  202. BOOST_AUTO_TEST_CASE( test_failure_multilinestring )
  203. {
  204. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  205. std::cout << std::endl << std::endl;
  206. std::cout << "************************************" << std::endl;
  207. std::cout << " is_valid_failure: MULTILINESTRING " << std::endl;
  208. std::cout << "************************************" << std::endl;
  209. #endif
  210. typedef multi_linestring_type G;
  211. typedef test_failure<G> test;
  212. // empty multilinestring
  213. test::apply("mls01", "MULTILINESTRING()", bg::no_failure);
  214. // multilinestring with empty linestring(s)
  215. test::apply("mls02", "MULTILINESTRING(())", bg::failure_few_points);
  216. test::apply("mls03", "MULTILINESTRING((),(),())", bg::failure_few_points);
  217. test::apply("mls04",
  218. "MULTILINESTRING((),(0 1,1 0))",
  219. bg::failure_few_points);
  220. // multilinestring with invalid linestrings
  221. test::apply("mls05",
  222. "MULTILINESTRING((0 0),(0 1,1 0))",
  223. bg::failure_few_points);
  224. test::apply("mls06",
  225. "MULTILINESTRING((0 0,0 0),(0 1,1 0))",
  226. bg::failure_wrong_topological_dimension);
  227. test::apply("mls07", "MULTILINESTRING((0 0),(1 0))",
  228. bg::failure_few_points);
  229. test::apply("mls08",
  230. "MULTILINESTRING((0 0,0 0),(1 0,1 0))",
  231. bg::failure_wrong_topological_dimension);
  232. test::apply("mls09",
  233. "MULTILINESTRING((0 0),(0 0))",
  234. bg::failure_few_points);
  235. test::apply("mls10",
  236. "MULTILINESTRING((0 0,1 0,0 0),(5 0))",
  237. bg::failure_few_points);
  238. // multilinstring that has linestrings with spikes
  239. test::apply("mls11",
  240. "MULTILINESTRING((0 0,1 0,0 0),(5 0,1 0,4 1))",
  241. bg::no_failure);
  242. test::apply("mls12",
  243. "MULTILINESTRING((0 0,1 0,0 0),(1 0,2 0))",
  244. bg::no_failure);
  245. // valid multilinestrings
  246. test::apply("mls13",
  247. "MULTILINESTRING((0 0,1 0,2 0),(5 0,1 0,4 1))",
  248. bg::no_failure);
  249. test::apply("mls14",
  250. "MULTILINESTRING((0 0,1 0,2 0),(1 0,2 0))",
  251. bg::no_failure);
  252. test::apply("mls15",
  253. "MULTILINESTRING((0 0,1 1),(0 1,1 0))",
  254. bg::no_failure);
  255. test::apply("mls16",
  256. "MULTILINESTRING((0 0,1 1,2 2),(0 1,1 0,2 2))",
  257. bg::no_failure);
  258. }
  259. template <typename Point>
  260. inline void test_open_rings()
  261. {
  262. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  263. std::cout << std::endl << std::endl;
  264. std::cout << "************************************" << std::endl;
  265. std::cout << " is_valid_failure: RING (open) " << std::endl;
  266. std::cout << "************************************" << std::endl;
  267. #endif
  268. typedef bg::model::ring<Point, false, false> G; // ccw, open ring
  269. typedef test_failure<G> test;
  270. // not enough points
  271. test::apply("r01", "POLYGON(())", bg::failure_few_points);
  272. test::apply("r02", "POLYGON((0 0))", bg::failure_few_points);
  273. test::apply("r03", "POLYGON((0 0,1 0))", bg::failure_few_points);
  274. // duplicate points
  275. test::apply("r04",
  276. "POLYGON((0 0,0 0,0 0))",
  277. bg::failure_wrong_topological_dimension);
  278. test::apply("r05",
  279. "POLYGON((0 0,1 0,1 0))",
  280. bg::failure_wrong_topological_dimension);
  281. test::apply("r06",
  282. "POLYGON((0 0,1 0,0 0))",
  283. bg::failure_wrong_topological_dimension);
  284. test::apply("r07", "POLYGON((0 0,1 0,1 1,0 0,0 0))", bg::no_failure);
  285. test::apply("r08", "POLYGON((0 0,1 0,1 0,1 1))", bg::no_failure);
  286. test::apply("r09", "POLYGON((0 0,1 0,1 0,1 1,0 0))", bg::no_failure);
  287. // with spikes
  288. test::apply("r10", "POLYGON((0 0,2 0,2 2,0 2,1 2))", bg::failure_spikes);
  289. test::apply("r11", "POLYGON((0 0,2 0,1 0,2 2))", bg::failure_spikes);
  290. test::apply("r12",
  291. "POLYGON((0 0,1 0,2 0,1 0,4 0,4 4))",
  292. bg::failure_spikes);
  293. test::apply("r13", "POLYGON((0 0,2 0,2 2,1 0))", bg::failure_spikes);
  294. test::apply("r14", "POLYGON((0 0,2 0,1 0))", bg::failure_spikes);
  295. test::apply("r15",
  296. "POLYGON((0 0,5 0,5 5,4 4,5 5,0 5))",
  297. bg::failure_spikes);
  298. test::apply("r16",
  299. "POLYGON((0 0,5 0,5 5,4 4,3 3,5 5,0 5))",
  300. bg::failure_spikes);
  301. // with spikes and duplicate points
  302. test::apply("r17",
  303. "POLYGON((0 0,0 0,2 0,2 0,1 0,1 0))",
  304. bg::failure_spikes);
  305. // with self-crossings
  306. test::apply("r18",
  307. "POLYGON((0 0,5 0,5 5,3 -1,0 5))",
  308. bg::failure_self_intersections);
  309. // with self-crossings and duplicate points
  310. test::apply("r19",
  311. "POLYGON((0 0,5 0,5 5,5 5,3 -1,0 5,0 5))",
  312. bg::failure_self_intersections);
  313. // with self-intersections
  314. test::apply("r20",
  315. "POLYGON((0 0,5 0,5 5,3 5,3 0,2 0,2 5,0 5))",
  316. bg::failure_self_intersections);
  317. test::apply("r21",
  318. "POLYGON((0 0,5 0,5 5,3 5,3 0,2 5,0 5))",
  319. bg::failure_self_intersections);
  320. test::apply("r22",
  321. "POLYGON((0 0,5 0,5 1,1 1,1 2,2 2,3 1,4 2,5 2,5 5,0 5))",
  322. bg::failure_self_intersections);
  323. // with self-intersections and duplicate points
  324. test::apply("r23",
  325. "POLYGON((0 0,5 0,5 5,3 5,3 5,3 0,3 0,2 0,2 0,2 5,2 5,0 5))",
  326. bg::failure_self_intersections);
  327. // next two suggested by Adam Wulkiewicz
  328. test::apply("r24",
  329. "POLYGON((0 0,5 0,5 5,0 5,4 4,2 2,0 5))",
  330. bg::failure_self_intersections);
  331. test::apply("r25",
  332. "POLYGON((0 0,5 0,5 5,1 4,4 4,4 1,0 5))",
  333. bg::failure_self_intersections);
  334. // and a few more
  335. test::apply("r26",
  336. "POLYGON((0 0,5 0,5 5,4 4,1 4,1 1,4 1,4 4,0 5))",
  337. bg::failure_self_intersections);
  338. test::apply("r27",
  339. "POLYGON((0 0,5 0,5 5,4 4,4 1,1 1,1 4,4 4,0 5))",
  340. bg::failure_self_intersections);
  341. // valid rings
  342. test::apply("r28", "POLYGON((0 0,1 0,1 1))", bg::no_failure);
  343. test::apply("r29", "POLYGON((1 0,1 1,0 0))", bg::no_failure);
  344. test::apply("r30", "POLYGON((0 0,1 0,1 1,0 1))", bg::no_failure);
  345. test::apply("r31", "POLYGON((1 0,1 1,0 1,0 0))", bg::no_failure);
  346. // test cases coming from buffer
  347. test::apply("r32",
  348. "POLYGON((1.1713032141645456 -0.9370425713316364,\
  349. 5.1713032141645456 4.0629574286683638,\
  350. 4.7808688094430307 4.3753049524455756,\
  351. 4.7808688094430307 4.3753049524455756,\
  352. 0.7808688094430304 -0.6246950475544243,\
  353. 0.7808688094430304 -0.6246950475544243))",
  354. bg::no_failure);
  355. // wrong orientation
  356. test::apply("r33",
  357. "POLYGON((0 0,0 1,1 1,0 0))",
  358. bg::failure_wrong_orientation);
  359. }
  360. template <typename Point>
  361. void test_closed_rings()
  362. {
  363. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  364. std::cout << std::endl << std::endl;
  365. std::cout << "************************************" << std::endl;
  366. std::cout << " is_valid_failure: RING (closed) " << std::endl;
  367. std::cout << "************************************" << std::endl;
  368. #endif
  369. typedef bg::model::ring<Point, false, true> G; // ccw, closed ring
  370. typedef test_failure<G> test;
  371. // not enough points
  372. test::apply("r01c", "POLYGON(())", bg::failure_few_points);
  373. test::apply("r02c", "POLYGON((0 0))", bg::failure_few_points);
  374. test::apply("r03c", "POLYGON((0 0,0 0))", bg::failure_few_points);
  375. test::apply("r04c", "POLYGON((0 0,1 0))", bg::failure_few_points);
  376. test::apply("r05c", "POLYGON((0 0,1 0,1 0))", bg::failure_few_points);
  377. test::apply("r06c", "POLYGON((0 0,1 0,2 0))", bg::failure_few_points);
  378. test::apply("r07c",
  379. "POLYGON((0 0,1 0,1 0,2 0))",
  380. bg::failure_wrong_topological_dimension);
  381. test::apply("r08c",
  382. "POLYGON((0 0,1 0,2 0,2 0))",
  383. bg::failure_wrong_topological_dimension);
  384. // boundary not closed
  385. test::apply("r09c", "POLYGON((0 0,1 0,1 1,1 2))", bg::failure_not_closed);
  386. test::apply("r10c",
  387. "POLYGON((0 0,1 0,1 0,1 1,1 1,1 2))",
  388. bg::failure_not_closed);
  389. // with spikes
  390. test::apply("r11c", "POLYGON((0 0,1 0,1 0,2 0,0 0))", bg::failure_spikes);
  391. test::apply("r12c",
  392. "POLYGON((0 0,1 0,1 1,2 2,0.5 0.5,0 1,0 0))",
  393. bg::failure_spikes);
  394. // wrong orientation
  395. test::apply("r13c",
  396. "POLYGON((0 0,0 1,1 1,2 0,0 0))",
  397. bg::failure_wrong_orientation);
  398. }
  399. BOOST_AUTO_TEST_CASE( test_failure_ring )
  400. {
  401. test_open_rings<point_type>();
  402. test_closed_rings<point_type>();
  403. }
  404. template <typename Point>
  405. void test_open_polygons()
  406. {
  407. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  408. std::cout << std::endl << std::endl;
  409. std::cout << "************************************" << std::endl;
  410. std::cout << " is_valid_failure: POLYGON (open) " << std::endl;
  411. std::cout << "************************************" << std::endl;
  412. #endif
  413. typedef bg::model::polygon<Point, false, false> G; // ccw, open
  414. typedef test_failure<G> test;
  415. // not enough points in exterior ring
  416. test::apply("pg001", "POLYGON(())", bg::failure_few_points);
  417. test::apply("pg002", "POLYGON((0 0))", bg::failure_few_points);
  418. test::apply("pg003", "POLYGON((0 0,1 0))", bg::failure_few_points);
  419. // not enough points in interior ring
  420. test::apply("pg004",
  421. "POLYGON((0 0,10 0,10 10,0 10),())",
  422. bg::failure_few_points);
  423. test::apply("pg005",
  424. "POLYGON((0 0,10 0,10 10,0 10),(1 1))",
  425. bg::failure_few_points);
  426. test::apply("pg006",
  427. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 2))",
  428. bg::failure_few_points);
  429. // duplicate points in exterior ring
  430. test::apply("pg007",
  431. "POLYGON((0 0,0 0,0 0))",
  432. bg::failure_wrong_topological_dimension);
  433. test::apply("pg008",
  434. "POLYGON((0 0,1 0,1 0))",
  435. bg::failure_wrong_topological_dimension);
  436. test::apply("pg009",
  437. "POLYGON((0 0,1 0,0 0))",
  438. bg::failure_wrong_topological_dimension);
  439. test::apply("pg010", "POLYGON((0 0,1 0,1 1,0 0,0 0))", bg::no_failure);
  440. test::apply("pg011", "POLYGON((0 0,1 0,1 0,1 1))", bg::no_failure);
  441. test::apply("pg012", "POLYGON((0 0,1 0,1 0,1 1,0 0))", bg::no_failure);
  442. test::apply("pg013",
  443. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 1,1 1))",
  444. bg::failure_wrong_topological_dimension);
  445. test::apply("pg014",
  446. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 1,2 1))",
  447. bg::failure_wrong_topological_dimension);
  448. test::apply("pg015",
  449. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 1,1 1))",
  450. bg::failure_wrong_topological_dimension);
  451. test::apply("pg016",
  452. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 2,2 1,1 1,1 1))",
  453. bg::no_failure);
  454. test::apply("pg017",
  455. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 2,2 2,2 1))",
  456. bg::no_failure);
  457. test::apply("pg018",
  458. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 2,2 1,2 1,1 1))",
  459. bg::no_failure);
  460. // with spikes in exterior ring
  461. test::apply("pg019", "POLYGON((0 0,2 0,2 2,0 2,1 2))", bg::failure_spikes);
  462. test::apply("pg020", "POLYGON((0 0,2 0,1 0,2 2))", bg::failure_spikes);
  463. test::apply("pg021",
  464. "POLYGON((0 0,1 0,2 0,1 0,4 0,4 4))",
  465. bg::failure_spikes);
  466. test::apply("pg022", "POLYGON((0 0,2 0,2 2,1 0))", bg::failure_spikes);
  467. test::apply("pg023", "POLYGON((0 0,2 0,1 0))", bg::failure_spikes);
  468. test::apply("pg024",
  469. "POLYGON((0 0,5 0,5 5,4 4,5 5,0 5))",
  470. bg::failure_spikes);
  471. test::apply("pg025",
  472. "POLYGON((0 0,5 0,5 5,4 4,3 3,5 5,0 5))",
  473. bg::failure_spikes);
  474. // with spikes in interior ring
  475. test::apply("pg026",
  476. "POLYGON((0 0,10 0,10 10,0 10),(1 1,3 1,3 3,1 3,2 3))",
  477. bg::failure_spikes);
  478. test::apply("pg027",
  479. "POLYGON((0 0,10 0,10 10,0 10),(1 1,3 1,2 1,3 3))",
  480. bg::failure_spikes);
  481. test::apply("pg028",
  482. "POLYGON((0 0,10 0,10 10,0 10),(1 1,2 1,3 1,2 1,4 1,4 4))",
  483. bg::failure_spikes);
  484. test::apply("pg029",
  485. "POLYGON((0 0,10 0,10 10,0 10),(1 1,3 1,3 3,2 1))",
  486. bg::failure_spikes);
  487. test::apply("pg030",
  488. "POLYGON((0 0,10 0,10 10,0 10),(1 1,3 1,2 1))",
  489. bg::failure_spikes);
  490. // with self-crossings in exterior ring
  491. test::apply("pg031",
  492. "POLYGON((0 0,5 0,5 5,3 -1,0 5))",
  493. bg::failure_self_intersections);
  494. // example from Norvald Ryeng
  495. test::apply("pg032",
  496. "POLYGON((100 1300,140 1300,140 170,100 1700))",
  497. bg::failure_wrong_orientation);
  498. // and with point order reversed
  499. test::apply("pg033",
  500. "POLYGON((100 1300,100 1700,140 170,140 1300))",
  501. bg::failure_self_intersections);
  502. // with self-crossings in interior ring
  503. // the self-crossing causes the area of the interior ring to have
  504. // the wrong sign, hence the "wrong orientation" failure
  505. test::apply("pg034",
  506. "POLYGON((0 0,10 0,10 10,0 10),(3 3,3 7,4 6,2 6))",
  507. bg::failure_wrong_orientation);
  508. // with self-crossings between rings
  509. test::apply("pg035",
  510. "POLYGON((0 0,5 0,5 5,0 5),(1 1,2 1,1 -1))",
  511. bg::failure_self_intersections);
  512. // with self-intersections in exterior ring
  513. test::apply("pg036",
  514. "POLYGON((0 0,5 0,5 5,3 5,3 0,2 0,2 5,0 5))",
  515. bg::failure_self_intersections);
  516. test::apply("pg037",
  517. "POLYGON((0 0,5 0,5 5,3 5,3 0,2 5,0 5))",
  518. bg::failure_self_intersections);
  519. test::apply("pg038",
  520. "POLYGON((0 0,5 0,5 1,1 1,1 2,2 2,3 1,4 2,5 2,5 5,0 5))",
  521. bg::failure_self_intersections);
  522. // next two suggested by Adam Wulkiewicz
  523. test::apply("pg039",
  524. "POLYGON((0 0,5 0,5 5,0 5,4 4,2 2,0 5))",
  525. bg::failure_self_intersections);
  526. test::apply("pg040",
  527. "POLYGON((0 0,5 0,5 5,1 4,4 4,4 1,0 5))",
  528. bg::failure_self_intersections);
  529. test::apply("pg041",
  530. "POLYGON((0 0,5 0,5 5,4 4,1 4,1 1,4 1,4 4,0 5))",
  531. bg::failure_self_intersections);
  532. test::apply("pg042",
  533. "POLYGON((0 0,5 0,5 5,4 4,4 1,1 1,1 4,4 4,0 5))",
  534. bg::failure_self_intersections);
  535. // with self-intersections in interior ring
  536. // same comment as for pg034
  537. test::apply("pg043",
  538. "POLYGON((-10 -10,10 -10,10 10,-10 10),(0 0,5 0,5 5,3 5,3 0,2 0,2 5,0 5))",
  539. bg::failure_wrong_orientation);
  540. // same comment as for pg034
  541. test::apply("pg044",
  542. "POLYGON((-10 -10,10 -10,10 10,-10 10),(0 0,5 0,5 5,3 5,3 0,2 5,0 5))",
  543. bg::failure_wrong_orientation);
  544. // same comment as for pg034
  545. test::apply("pg045",
  546. "POLYGON((-10 -10,10 -10,10 10,-10 10),(0 0,5 0,5 1,1 1,1 2,2 2,3 1,4 2,5 2,5 5,0 5))",
  547. bg::failure_wrong_orientation);
  548. // with self-intersections between rings
  549. // hole has common segment with exterior ring
  550. test::apply("pg046",
  551. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 10,2 10,2 1))",
  552. bg::failure_self_intersections);
  553. test::apply("pg047",
  554. "POLYGON((0 0,0 0,10 0,10 10,0 10,0 10),(1 1,1 10,1 10,2 10,2 10,2 1))",
  555. bg::failure_self_intersections);
  556. // hole touches exterior ring at one point
  557. test::apply("pg048",
  558. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 10,2 1))",
  559. bg::no_failure);
  560. // "hole" is outside the exterior ring, but touches it
  561. // TODO: return the failure value failure_interior_rings_outside
  562. test::apply("pg049",
  563. "POLYGON((0 0,10 0,10 10,0 10),(5 10,4 11,6 11))",
  564. bg::failure_self_intersections);
  565. // hole touches exterior ring at vertex
  566. test::apply("pg050",
  567. "POLYGON((0 0,10 0,10 10,0 10),(0 0,1 4,4 1))",
  568. bg::no_failure);
  569. // "hole" is completely outside the exterior ring
  570. test::apply("pg051",
  571. "POLYGON((0 0,10 0,10 10,0 10),(20 20,20 21,21 21,21 20))",
  572. bg::failure_interior_rings_outside);
  573. // two "holes" completely outside the exterior ring, that touch
  574. // each other
  575. test::apply("pg052",
  576. "POLYGON((0 0,10 0,10 10,0 10),(20 0,25 10,21 0),(30 0,25 10,31 0))",
  577. bg::failure_interior_rings_outside);
  578. // example from Norvald Ryeng
  579. test::apply("pg053",
  580. "POLYGON((58 31,56.57 30,62 33),(35 9,28 14,31 16),(23 11,29 5,26 4))",
  581. bg::failure_interior_rings_outside);
  582. // and with points reversed
  583. test::apply("pg054",
  584. "POLYGON((58 31,62 33,56.57 30),(35 9,31 16,28 14),(23 11,26 4,29 5))",
  585. bg::failure_wrong_orientation);
  586. // "hole" is completely inside another "hole"
  587. test::apply("pg055",
  588. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,2 8,8 8,8 2))",
  589. bg::failure_nested_interior_rings);
  590. test::apply("pg056",
  591. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,8 2,8 8,2 8))",
  592. bg::failure_wrong_orientation);
  593. // "hole" is inside another "hole" (touching)
  594. // TODO: return the failure value failure_nested_interior_rings
  595. test::apply("pg057",
  596. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,2 8,8 8,9 6,8 2))",
  597. bg::failure_self_intersections);
  598. // TODO: return the failure value failure_nested_interior_rings
  599. test::apply("pg058",
  600. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,2 8,8 8,9 6,8 2))",
  601. bg::failure_self_intersections);
  602. test::apply("pg058a",
  603. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,8 2,9 6,8 8,2 8))",
  604. bg::failure_wrong_orientation);
  605. // TODO: return the failure value failure_nested_interior_rings
  606. test::apply("pg059",
  607. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,2 8,8 8,9 6,8 2))",
  608. bg::failure_self_intersections);
  609. test::apply("pg059a",
  610. "POLYGON((0 0,10 0,10 10,0 10),(1 1,9 1,9 9,1 9),(2 2,2 8,8 8,9 6,8 2))",
  611. bg::failure_wrong_orientation);
  612. // TODO: return the failure value failure_nested_interior_rings
  613. test::apply("pg060",
  614. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 1),(2 2,2 8,8 8,9 6,8 2))",
  615. bg::failure_self_intersections);
  616. test::apply("pg060a",
  617. "POLYGON((0 0,10 0,10 10,0 10),(1 1,9 1,9 9,1 9),(2 2,8 2,9 6,8 8,2 8))",
  618. bg::failure_wrong_orientation);
  619. // hole touches exterior ring at two points
  620. test::apply("pg061",
  621. "POLYGON((0 0,10 0,10 10,0 10),(5 0,0 5,5 5))",
  622. bg::failure_disconnected_interior);
  623. // cases with more holes
  624. // two holes, touching the exterior at the same point
  625. test::apply("pg062",
  626. "POLYGON((0 0,10 0,10 10,0 10),(0 0,1 9,2 9),(0 0,9 2,9 1))",
  627. bg::no_failure);
  628. test::apply("pg063",
  629. "POLYGON((0 0,0 0,10 0,10 10,0 10,0 0),(0 0,0 0,1 9,2 9),(0 0,0 0,9 2,9 1))",
  630. bg::no_failure);
  631. test::apply("pg063",
  632. "POLYGON((0 10,0 0,0 0,0 0,10 0,10 10),(2 9,0 0,0 0,1 9),(9 1,0 0,0 0,9 2))",
  633. bg::no_failure);
  634. // two holes, one inside the other
  635. // TODO: return the failure value failure_nested_interior_rings
  636. test::apply("pg064",
  637. "POLYGON((0 0,10 0,10 10,0 10),(0 0,1 9,9 1),(0 0,4 5,5 4))",
  638. bg::failure_self_intersections);
  639. // 1st hole touches has common segment with 2nd hole
  640. test::apply("pg066",
  641. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 5,5 5,5 1),(5 4,5 8,8 8,8 4))",
  642. bg::failure_self_intersections);
  643. // 1st hole touches 2nd hole at two points
  644. test::apply("pg067",
  645. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,9 9,9 8,2 8,2 1),(2 5,5 8,5 5))",
  646. bg::failure_disconnected_interior);
  647. // polygon with many holes, where the last two touch at two points
  648. test::apply("pg068",
  649. "POLYGON((0 0,20 0,20 20,0 20),(1 18,1 19,2 19,2 18),(3 18,3 19,4 19,4 18),(5 18,5 19,6 19,6 18),(7 18,7 19,8 19,8 18),(9 18,9 19,10 19,10 18),(11 18,11 19,12 19,12 18),(13 18,13 19,14 19,14 18),(15 18,15 19,16 19,16 18),(17 18,17 19,18 19,18 18),(1 1,1 9,9 9,9 8,2 8,2 1),(2 5,5 8,5 5))",
  650. bg::failure_disconnected_interior);
  651. // two holes completely inside exterior ring but touching each
  652. // other at a point
  653. test::apply("pg069",
  654. "POLYGON((0 0,10 0,10 10,0 10),(1 1,1 9,2 9),(1 1,9 2,9 1))",
  655. bg::no_failure);
  656. // four holes, each two touching at different points
  657. test::apply("pg070",
  658. "POLYGON((0 0,10 0,10 10,0 10),(0 10,2 1,1 1),(0 10,4 1,3 1),(10 10,9 1,8 1),(10 10,7 1,6 1))",
  659. bg::no_failure);
  660. // five holes, with two pairs touching each at some point, and
  661. // fifth hole creating a disconnected component for the interior
  662. test::apply("pg071",
  663. "POLYGON((0 0,10 0,10 10,0 10),(0 10,2 1,1 1),(0 10,4 1,3 1),(10 10,9 1,8 1),(10 10,7 1,6 1),(4 1,4 4,6 4,6 1))",
  664. bg::failure_disconnected_interior);
  665. // five holes, with two pairs touching each at some point, and
  666. // fifth hole creating three disconnected components for the interior
  667. test::apply("pg072",
  668. "POLYGON((0 0,10 0,10 10,0 10),(0 10,2 1,1 1),(0 10,4 1,3 1),(10 10,9 1,8 1),(10 10,7 1,6 1),(4 1,4 4,6 4,6 1,5 0))",
  669. bg::failure_disconnected_interior);
  670. // both examples: a polygon with one hole, where the hole contains
  671. // the exterior ring
  672. test::apply("pg073",
  673. "POLYGON((0 0,1 0,1 1,0 1),(-10 -10,-10 10,10 10,10 -10))",
  674. bg::failure_interior_rings_outside);
  675. // TODO: return the failure value failure_interior_rings_outside
  676. test::apply("pg074",
  677. "POLYGON((-10 -10,1 0,1 1,0 1),(-10 -10,-10 10,10 10,10 -10))",
  678. bg::failure_self_intersections);
  679. }
  680. template <typename Point>
  681. inline void test_doc_example_polygon()
  682. {
  683. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  684. std::cout << std::endl << std::endl;
  685. std::cout << "************************************" << std::endl;
  686. std::cout << " is_valid_failure: doc example polygon " << std::endl;
  687. std::cout << "************************************" << std::endl;
  688. #endif
  689. typedef bg::model::polygon<Point> CCW_CG;
  690. typedef test_failure<CCW_CG> test;
  691. test::apply("pg-doc",
  692. "POLYGON((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 2,0 0),(0 0,2 9,1 9,0 0),(2 9,9 2,9 9,2 9))",
  693. bg::failure_disconnected_interior);
  694. }
  695. BOOST_AUTO_TEST_CASE( test_failure_polygon )
  696. {
  697. test_open_polygons<point_type>();
  698. test_doc_example_polygon<point_type>();
  699. }
  700. template <typename Point>
  701. void test_open_multipolygons()
  702. {
  703. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  704. std::cout << std::endl << std::endl;
  705. std::cout << "************************************" << std::endl;
  706. std::cout << " is_valid_failure: MULTIPOLYGON (open) " << std::endl;
  707. std::cout << "************************************" << std::endl;
  708. #endif
  709. typedef bg::model::polygon<point_type,false,false> ccw_open_polygon_type;
  710. typedef bg::model::multi_polygon<ccw_open_polygon_type> G;
  711. typedef test_failure<G> test;
  712. // not enough points
  713. test::apply("mpg01", "MULTIPOLYGON()", bg::no_failure);
  714. test::apply("mpg02", "MULTIPOLYGON((()))", bg::failure_few_points);
  715. test::apply("mpg03", "MULTIPOLYGON(((0 0)),(()))", bg::failure_few_points);
  716. test::apply("mpg04", "MULTIPOLYGON(((0 0,1 0)))", bg::failure_few_points);
  717. // two disjoint polygons
  718. test::apply("mpg05",
  719. "MULTIPOLYGON(((0 0,1 0,1 1,0 1)),((2 2,3 2,3 3,2 3)))",
  720. bg::no_failure);
  721. // two disjoint polygons with multiple points
  722. test::apply("mpg06",
  723. "MULTIPOLYGON(((0 0,1 0,1 0,1 1,0 1)),((2 2,3 2,3 3,3 3,2 3)))",
  724. bg::no_failure);
  725. // two polygons touch at a point
  726. test::apply("mpg07",
  727. "MULTIPOLYGON(((0 0,1 0,1 1,0 1)),((1 1,2 1,2 2,1 2)))",
  728. bg::no_failure);
  729. // two polygons share a segment at a point
  730. test::apply("mpg08",
  731. "MULTIPOLYGON(((0 0,1.5 0,1.5 1,0 1)),((1 1,2 1,2 2,1 2)))",
  732. bg::failure_self_intersections);
  733. // one polygon inside another and boundaries touching
  734. test::apply("mpg09",
  735. "MULTIPOLYGON(((0 0,10 0,10 10,0 10)),((0 0,9 1,9 2)))",
  736. bg::failure_intersecting_interiors);
  737. test::apply("mpg09_2",
  738. "MULTIPOLYGON(((0 0,5 1,10 0,10 10,0 10)),((1 1,9 1,9 2)))",
  739. bg::failure_intersecting_interiors);
  740. // one polygon inside another and boundaries not touching
  741. test::apply("mpg10",
  742. "MULTIPOLYGON(((0 0,10 0,10 10,0 10)),((1 1,9 1,9 2)))",
  743. bg::failure_intersecting_interiors);
  744. // free space is disconnected
  745. test::apply("mpg11",
  746. "MULTIPOLYGON(((0 0,1 0,1 1,0 1)),((1 1,2 1,2 2,1 2)),((0 1,0 2,-1 2,-1 -1)),((1 2,1 3,0 3,0 2)))",
  747. bg::no_failure);
  748. // multi-polygon with a polygon inside the hole of another polygon
  749. test::apply("mpg12",
  750. "MULTIPOLYGON(((0 0,100 0,100 100,0 100),(1 1,1 99,99 99,99 1)),((2 2,98 2,98 98,2 98)))",
  751. bg::no_failure);
  752. test::apply("mpg13",
  753. "MULTIPOLYGON(((0 0,100 0,100 100,0 100),(1 1,1 99,99 99,99 1)),((1 1,98 2,98 98,2 98)))",
  754. bg::no_failure);
  755. // test case suggested by Barend Gehrels: take two valid polygons P1 and
  756. // P2 with holes H1 and H2, respectively, and consider P2 to be
  757. // fully inside H1; now invalidate the multi-polygon by
  758. // considering H2 as a hole of P1 and H1 as a hole of P2; this
  759. // should be invalid
  760. //
  761. // first the valid case:
  762. test::apply("mpg14",
  763. "MULTIPOLYGON(((0 0,100 0,100 100,0 100),(1 1,1 99,99 99,99 1)),((2 2,98 2,98 98,2 98),(3 3,3 97,97 97,97 3)))",
  764. bg::no_failure);
  765. // and the invalid case:
  766. test::apply("mpg15",
  767. "MULTIPOLYGON(((0 0,100 0,100 100,0 100),(3 3,3 97,97 97,97 3)),((2 2,98 2,98 98,2 98),(1 1,1 99,99 99,99 1)))",
  768. bg::failure_interior_rings_outside);
  769. test::apply
  770. ("mpg16",
  771. "MULTIPOLYGON(((-1 4,8 -10,-10 10,7 -6,8 -2,\
  772. -10 10,-10 1,-3 -4,4 1,-1 2,4 3,-8 10,-5 -9,-1 6,-5 0)),\
  773. ((-10 -3,-8 1,2 -8,-2 6,-4 0,8 -5,-1 5,8 2)),\
  774. ((-6 -10,1 10,4 -8,-7 -2,2 0,-4 3,-10 9)),\
  775. ((10 -1,-2 8,-7 3,-6 8,-9 -7,7 -5)),\
  776. ((7 7,-4 -4,9 -8,-10 -6)))",
  777. bg::failure_wrong_orientation);
  778. test::apply
  779. ("mpg17",
  780. "MULTIPOLYGON(((-1 4,8 -10,-10 10,7 -6,8 -2,\
  781. -10 10,-10 1,-3 -4,4 1,-1 2,4 3,-8 10,-5 -9,-1 6,-5 0)),\
  782. ((-10 -3,-8 1,2 -8,-2 6,-4 0,8 -5,-1 5,8 2)),\
  783. ((-6 -10,-10 9,-4 3,2 0,-7 -2,4 -8,1 10)),\
  784. ((10 -1,-2 8,-7 3,-6 8,-9 -7,7 -5)),\
  785. ((7 7,-10 -6,9 -8,-4 -4)))",
  786. bg::failure_spikes);
  787. // test cases coming from buffer
  788. {
  789. std::string wkt = "MULTIPOLYGON(((1.1713032141645456 -0.9370425713316364,5.1713032141645456 4.0629574286683638,4.7808688094430307 4.3753049524455756,4.7808688094430307 4.3753049524455756,0.7808688094430304 -0.6246950475544243,0.7808688094430304 -0.6246950475544243,1.1713032141645456 -0.9370425713316364)))";
  790. G open_mpgn = from_wkt<G>(wkt);
  791. bg::reverse(open_mpgn);
  792. test::apply("mpg18", open_mpgn, bg::failure_wrong_orientation);
  793. }
  794. {
  795. std::string wkt = "MULTIPOLYGON(((5.2811206375710933 9.9800205994776228,5.2446420208654896 10.0415020265598844,5.1807360092909640 10.1691699739962242,5.1261005500004773 10.3010716408018013,5.0810140527710059 10.4365348863171388,5.0457062680576819 10.5748694208940446,5.0203571162381344 10.7153703234534277,5.0050957707794934 10.8573216336015328,5.0000000000000000 10.9999999999999964,5.0050957707794925 11.1426783663984619,5.0203571162381344 11.2846296765465670,5.0457062680576801 11.4251305791059501,5.0810140527710042 11.5634651136828559,5.1261005500004755 11.6989283591981934,5.1807360092909622 11.8308300260037704,5.2446420208654869 11.9584979734401102,5.3174929343376363 12.0812816349111927,5.3989175181512774 12.1985553330226910,5.4885008512914810 12.3097214678905669,5.5857864376269024 12.4142135623730923,5.6902785321094269 12.5114991487085145,5.8014446669773028 12.6010824818487190,5.9187183650888020 12.6825070656623602,6.0415020265598844 12.7553579791345104,6.1691699739962260 12.8192639907090360,6.3010716408018030 12.8738994499995236,6.4365348863171405 12.9189859472289950,6.5748694208940472 12.9542937319423199,6.7153703234534312 12.9796428837618656,6.8573216336015381 12.9949042292205075,7.0000000000000036 13.0000000000000000,7.1426783663984690 12.9949042292205075,7.2846296765465750 12.9796428837618656,7.4251305791059590 12.9542937319423181,7.5634651136828657 12.9189859472289932,7.6989283591982032 12.8738994499995201,7.8308300260037802 12.8192639907090324,7.9584979734401209 12.7553579791345069,8.0812816349112033 12.6825070656623566,8.1985553330227017 12.6010824818487137,8.3097214678905793 12.5114991487085092,8.4142135623731029 12.4142135623730869,8.5114991487085252 12.3097214678905598,8.6010824818487297 12.1985553330226821,8.6825070656623708 12.0812816349111838,8.7553579791345193 11.9584979734400996,8.8192639907090431 11.8308300260037580,8.8738994499995290 11.6989283591981810,8.9189859472290003 11.5634651136828417,8.9542937319423235 11.4251305791059359,8.9796428837618691 11.2846296765465510,8.9949042292205093 11.1426783663984441,9.0000000000000000 11.0000000000000000,8.9949042292205075 10.8573216336015346,8.9796428837618656 10.7153703234534294,8.9542937319423181 10.5748694208940464,8.9189859472289950 10.4365348863171405,8.8738994499995236 10.3010716408018030,8.8192639907090360 10.1691699739962278,8.7553579791345122 10.0415020265598862,8.7188787869375428 9.9800200826281831,8.8573216336015381 9.9949042292205075,9.0000000000000036 10.0000000000000000,9.1426783663984690 9.9949042292205075,9.2846296765465759 9.9796428837618656,9.4251305791059590 9.9542937319423181,9.5634651136828648 9.9189859472289932,9.6989283591982041 9.8738994499995201,9.8308300260037793 9.8192639907090324,9.9584979734401209 9.7553579791345069,10.0812816349112033 9.6825070656623566,10.1985553330227017 9.6010824818487137,10.3097214678905793 9.5114991487085092,10.4142135623731029 9.4142135623730869,10.5114991487085252 9.3097214678905598,10.6010824818487297 9.1985553330226821,10.6825070656623708 9.0812816349111838,10.7553579791345193 8.9584979734400996,10.8192639907090431 8.8308300260037580,10.8738994499995290 8.6989283591981810,10.9189859472290003 8.5634651136828417,10.9542937319423235 8.4251305791059359,10.9796428837618691 8.2846296765465510,10.9949042292205093 8.1426783663984441,11.0000000000000000 8.0000000000000000,10.9949042292205075 7.8573216336015355,10.9796428837618656 7.7153703234534294,10.9542937319423181 7.5748694208940464,10.9189859472289950 7.4365348863171405,10.8738994499995236 7.3010716408018030,10.8192639907090360 7.1691699739962269,10.7553579791345122 7.0415020265598862,10.6825070656623620 6.9187183650888047,10.6010824818487208 6.8014446669773063,10.5114991487085163 6.6902785321094296,10.4142135623730958 6.5857864376269051,10.3097214678905704 6.4885008512914837,10.1985553330226946 6.3989175181512792,10.0812816349111962 6.3174929343376380,9.9584979734401138 6.2446420208654887,9.8308300260037740 6.1807360092909640,9.6989283591981970 6.1261005500004764,9.5634651136828595 6.0810140527710050,9.4251305791059536 6.0457062680576810,9.2846296765465706 6.0203571162381344,9.1426783663984654 6.0050957707794925,9.0000000000000018 6.0000000000000000,8.8573216336015363 6.0050957707794925,8.7153703234534312 6.0203571162381344,8.5748694208940481 6.0457062680576810,8.4365348863171423 6.0810140527710050,8.3010716408018048 6.1261005500004764,8.1691699739962278 6.1807360092909622,8.0415020265598880 6.2446420208654878,7.9187183650888064 6.3174929343376363,7.8014446669773072 6.3989175181512783,7.6902785321094314 6.4885008512914819,7.5857864376269060 6.5857864376269033,7.4885008512914846 6.6902785321094278,7.3989175181512810 6.8014446669773045,7.3174929343376389 6.9187183650888029,7.2446420208654896 7.0415020265598844,7.1807360092909640 7.1691699739962251,7.1261005500004773 7.3010716408018013,7.0810140527710059 7.4365348863171379,7.0457062680576819 7.5748694208940437,7.0203571162381344 7.7153703234534268,7.0050957707794934 7.8573216336015328,7.0000000000000000 7.9999999999999973,7.0050957707794925 8.1426783663984619,7.0203571162381344 8.2846296765465670,7.0457062680576801 8.4251305791059501,7.0810140527710042 8.5634651136828559,7.1261005500004755 8.6989283591981934,7.1807360092909622 8.8308300260037704,7.2446420208654869 8.9584979734401102,7.2811219724467575 9.0199799990140797,7.1426783663984654 9.0050957707794925,7.0000000000000009 9.0000000000000000,6.8573216336015363 9.0050957707794925,6.7188786030357956 9.0199806804111571,6.7553579791345184 8.9584979734400996,6.8192639907090431 8.8308300260037580,6.8738994499995290 8.6989283591981810,6.9189859472290003 8.5634651136828417,6.9542937319423235 8.4251305791059359,6.9796428837618683 8.2846296765465510,6.9949042292205084 8.1426783663984441,7.0000000000000000 8.0000000000000000,6.9949042292205075 7.8573216336015355,6.9796428837618656 7.7153703234534294,6.9542937319423190 7.5748694208940464,6.9189859472289950 7.4365348863171405,6.8738994499995236 7.3010716408018030,6.8192639907090369 7.1691699739962269,6.7553579791345113 7.0415020265598862,6.6825070656623620 6.9187183650888047,6.6010824818487208 6.8014446669773063,6.5114991487085163 6.6902785321094296,6.4142135623730949 6.5857864376269051,6.3097214678905704 6.4885008512914837,6.1985553330226946 6.3989175181512792,6.0812816349111953 6.3174929343376380,5.9584979734401138 6.2446420208654887,5.8308300260037731 6.1807360092909640,5.6989283591981970 6.1261005500004764,5.5634651136828603 6.0810140527710050,5.4251305791059536 6.0457062680576810,5.2846296765465715 6.0203571162381344,5.1426783663984654 6.0050957707794925,5.0000000000000009 6.0000000000000000,4.8573216336015363 6.0050957707794925,4.7153703234534312 6.0203571162381344,4.5748694208940481 6.0457062680576810,4.4365348863171423 6.0810140527710050,4.3010716408018048 6.1261005500004764,4.1691699739962287 6.1807360092909622,4.0415020265598880 6.2446420208654878,3.9187183650888064 6.3174929343376363,3.8014446669773077 6.3989175181512783,3.6902785321094314 6.4885008512914819,3.5857864376269064 6.5857864376269033,3.4885008512914846 6.6902785321094278,3.3989175181512805 6.8014446669773045,3.3174929343376389 6.9187183650888029,3.2446420208654896 7.0415020265598844,3.1807360092909640 7.1691699739962251,3.1261005500004773 7.3010716408018013,3.0810140527710059 7.4365348863171379,3.0457062680576819 7.5748694208940437,3.0203571162381349 7.7153703234534268,3.0050957707794934 7.8573216336015328,3.0000000000000000 7.9999999999999973,3.0050957707794925 8.1426783663984619,3.0203571162381344 8.2846296765465670,3.0457062680576801 8.4251305791059501,3.0810140527710042 8.5634651136828559,3.1261005500004755 8.6989283591981934,3.1807360092909618 8.8308300260037704,3.2446420208654869 8.9584979734401102,3.3174929343376358 9.0812816349111927,3.3989175181512770 9.1985553330226910,3.4885008512914810 9.3097214678905669,3.5857864376269024 9.4142135623730923,3.6902785321094269 9.5114991487085145,3.8014446669773028 9.6010824818487190,3.9187183650888020 9.6825070656623602,4.0415020265598844 9.7553579791345104,4.1691699739962260 9.8192639907090360,4.3010716408018030 9.8738994499995236,4.4365348863171405 9.9189859472289950,4.5748694208940472 9.9542937319423199,4.7153703234534312 9.9796428837618656,4.8573216336015381 9.9949042292205075,5.0000000000000036 10.0000000000000000,5.1426783663984690 9.9949042292205075)))";
  796. G open_mpgn = from_wkt<G>(wkt);
  797. bg::reverse(open_mpgn);
  798. // polygon has a self-touching point
  799. test::apply("mpg19", open_mpgn, bg::failure_self_intersections);
  800. }
  801. {
  802. std::string wkt = "MULTIPOLYGON(((-1.1713032141645421 0.9370425713316406,-1.2278293047051545 0.8616467945203863,-1.2795097139219473 0.7828504914601357,-1.3261404828502752 0.7009646351604617,-1.3675375811487496 0.6163123916860891,-1.4035376333829217 0.5292278447680804,-1.4339985637934827 0.4400546773279756,-1.4588001570043776 0.3491448151183161,-1.4778445324579732 0.2568570378324778,-1.4910565307049013 0.1635555631651331,-1.4983840100240693 0.0696086094114048,-1.4997980522022116 -0.0246130577225216,-1.4952930766608652 -0.1187375883622537,-1.4848868624803642 -0.2123935159867641,-1.4686204782339323 -0.3052112234370423,-1.4465581199087858 -0.3968244016261590,-1.4187868575539013 -0.4868714951938814,-1.3854162916543107 -0.5749971294005020,-1.3465781205880585 -0.6608535126285795,-1.3024256208728704 -0.7441018089575634,-1.2531330422537639 -0.8244134753943718,-1.1988949200189114 -0.9014715584824893,-1.1399253072577331 -0.9749719451724563,-1.0764569300911435 -1.0446245630171400,-1.0087402692078766 -1.1101545249551616,-0.9370425713316382 -1.1713032141645441,-0.8616467945203836 -1.2278293047051563,-0.7828504914601331 -1.2795097139219491,-0.7009646351604588 -1.3261404828502767,-0.6163123916860862 -1.3675375811487509,-0.5292278447680773 -1.4035376333829228,-0.4400546773279725 -1.4339985637934838,-0.3491448151183129 -1.4588001570043785,-0.2568570378324746 -1.4778445324579736,-0.1635555631651299 -1.4910565307049017,-0.0696086094114016 -1.4983840100240695,0.0246130577225248 -1.4997980522022114,0.1187375883622569 -1.4952930766608650,0.2123935159867673 -1.4848868624803639,0.3052112234370455 -1.4686204782339316,0.3968244016261621 -1.4465581199087849,0.4868714951938845 -1.4187868575539002,0.5749971294005050 -1.3854162916543096,0.6608535126285824 -1.3465781205880569,0.7441018089575662 -1.3024256208728686,0.8244134753943745 -1.2531330422537621,0.9014715584824917 -1.1988949200189096,0.9749719451724583 -1.1399253072577313,1.0446245630171418 -1.0764569300911420,1.1101545249551634 -1.0087402692078746,1.1713032141645456 -0.9370425713316364,5.1713032141645456 4.0629574286683638,5.1713032141645439 4.0629574286683621,5.2278293047051561 4.1383532054796159,5.2795097139219491 4.2171495085398671,5.3261404828502767 4.2990353648395407,5.3675375811487509 4.3836876083139131,5.4035376333829230 4.4707721552319217,5.4339985637934838 4.5599453226720268,5.4588001570043785 4.6508551848816859,5.4778445324579739 4.7431429621675241,5.4910565307049017 4.8364444368348689,5.4983840100240693 4.9303913905885972,5.4997980522022116 5.0246130577225232,5.4952930766608645 5.1187375883622552,5.4848868624803639 5.2123935159867658,5.4686204782339320 5.3052112234370439,5.4465581199087856 5.3968244016261604,5.4187868575539007 5.4868714951938822,5.3854162916543107 5.5749971294005025,5.3465781205880578 5.6608535126285799,5.3024256208728699 5.7441018089575637,5.2531330422537632 5.8244134753943726,5.1988949200189110 5.9014715584824895,5.1399253072577329 5.9749719451724559,5.0764569300911440 6.0446245630171394,5.0087402692078768 6.1101545249551616,4.9370425713316379 6.1713032141645439,4.8616467945203841 6.2278293047051561,4.7828504914601337 6.2795097139219482,4.7009646351604593 6.3261404828502759,4.6163123916860869 6.3675375811487509,4.5292278447680783 6.4035376333829230,4.4400546773279732 6.4339985637934838,4.3491448151183141 6.4588001570043785,4.2568570378324750 6.4778445324579739,4.1635555631651311 6.4910565307049017,4.0696086094114028 6.4983840100240693,3.9753869422774759 6.4997980522022116,3.8812624116377439 6.4952930766608645,3.7876064840132333 6.4848868624803639,3.6947887765629552 6.4686204782339320,3.6031755983738387 6.4465581199087847,3.5131285048061165 6.4187868575539007,3.4250028705994957 6.3854162916543098,3.3391464873714183 6.3465781205880578,3.2558981910424345 6.3024256208728691,3.1755865246056261 6.2531330422537623,3.0985284415175087 6.1988949200189101,3.0250280548275423 6.1399253072577320,2.9553754369828584 6.0764569300911422,2.8898454750448366 6.0087402692078751,2.8286967858354544 5.9370425713316362,-1.1713032141645456 0.9370425713316364,-1.1713032141645421 0.9370425713316406)))";
  803. G open_mpgn = from_wkt<G>(wkt);
  804. bg::reverse(open_mpgn);
  805. // polygon contains a spike
  806. test::apply("mpg20", open_mpgn, bg::failure_spikes);
  807. }
  808. }
  809. BOOST_AUTO_TEST_CASE( test_failure_multipolygon )
  810. {
  811. test_open_multipolygons<point_type>();
  812. }
  813. BOOST_AUTO_TEST_CASE( test_failure_variant )
  814. {
  815. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  816. std::cout << std::endl << std::endl;
  817. std::cout << "************************************" << std::endl;
  818. std::cout << " is_valid_failure: variant support" << std::endl;
  819. std::cout << "************************************" << std::endl;
  820. #endif
  821. typedef bg::model::polygon<point_type> polygon_type; // cw, closed
  822. typedef boost::variant
  823. <
  824. linestring_type, multi_linestring_type, polygon_type
  825. > variant_geometry;
  826. typedef test_failure<variant_geometry> test;
  827. variant_geometry vg;
  828. linestring_type valid_linestring =
  829. from_wkt<linestring_type>("LINESTRING(0 0,1 0)");
  830. multi_linestring_type invalid_multi_linestring =
  831. from_wkt<multi_linestring_type>("MULTILINESTRING((0 0,1 0),(0 0))");
  832. polygon_type valid_polygon =
  833. from_wkt<polygon_type>("POLYGON((0 0,1 1,1 0,0 0))");
  834. polygon_type invalid_polygon =
  835. from_wkt<polygon_type>("POLYGON((0 0,2 2,2 0,1 0))");
  836. vg = valid_linestring;
  837. test::apply("v01", vg, bg::no_failure);
  838. vg = invalid_multi_linestring;
  839. test::apply("v02", vg, bg::failure_few_points);
  840. vg = valid_polygon;
  841. test::apply("v03", vg, bg::no_failure);
  842. vg = invalid_polygon;
  843. test::apply("v04", vg, bg::failure_not_closed);
  844. }