intersection_areal_areal_linear.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit test
  3. // Copyright (c) 2015, Oracle and/or its affiliates.
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  7. #ifndef BOOST_TEST_MODULE
  8. #define BOOST_TEST_MODULE test_intersection_linear_linear_areal
  9. #endif
  10. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  11. #define BOOST_GEOMETRY_DEBUG_TURNS
  12. #define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
  13. #endif
  14. #include <boost/test/included/unit_test.hpp>
  15. #include <boost/range.hpp>
  16. #include <boost/geometry/geometries/linestring.hpp>
  17. #include <boost/geometry/geometries/multi_linestring.hpp>
  18. #include <boost/geometry/geometries/ring.hpp>
  19. #include <boost/geometry/geometries/polygon.hpp>
  20. #include <boost/geometry/geometries/multi_polygon.hpp>
  21. #include "test_intersection_linear_linear.hpp"
  22. typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
  23. typedef bg::model::multi_linestring
  24. <
  25. bg::model::linestring<point_type>
  26. > multi_linestring_type;
  27. typedef bg::model::ring<point_type, true, false> open_ring_type;
  28. typedef bg::model::polygon<point_type, true, false> open_polygon_type;
  29. typedef bg::model::multi_polygon<open_polygon_type> open_multipolygon_type;
  30. typedef bg::model::ring<point_type> closed_ring_type;
  31. typedef bg::model::polygon<point_type> closed_polygon_type;
  32. typedef bg::model::multi_polygon<closed_polygon_type> closed_multipolygon_type;
  33. template
  34. <
  35. typename OpenAreal1,
  36. typename OpenAreal2,
  37. typename ClosedAreal1,
  38. typename ClosedAreal2,
  39. typename MultiLinestring
  40. >
  41. struct test_intersection_aal
  42. {
  43. static inline void apply(std::string const& case_id,
  44. OpenAreal1 const& open_areal1,
  45. OpenAreal2 const& open_areal2,
  46. MultiLinestring const& expected1,
  47. MultiLinestring const& expected2)
  48. {
  49. typedef test_intersection_of_geometries
  50. <
  51. OpenAreal1, OpenAreal2, MultiLinestring
  52. > tester;
  53. tester::apply(open_areal1, open_areal2, expected1, expected2, case_id);
  54. ClosedAreal1 closed_areal1;
  55. ClosedAreal2 closed_areal2;
  56. bg::convert(open_areal1, closed_areal1);
  57. bg::convert(open_areal2, closed_areal2);
  58. typedef test_intersection_of_geometries
  59. <
  60. ClosedAreal1, ClosedAreal2, MultiLinestring
  61. > tester_of_closed;
  62. std::string case_id_closed = case_id + "-closed";
  63. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  64. std::cout << "testing closed areal geometries..." << std::endl;
  65. #endif
  66. tester_of_closed::apply(closed_areal1, closed_areal2,
  67. expected1, expected2, case_id_closed);
  68. }
  69. static inline void apply(std::string const& case_id,
  70. OpenAreal1 const& open_areal1,
  71. OpenAreal2 const& open_areal2,
  72. MultiLinestring const& expected)
  73. {
  74. apply(case_id, open_areal1, open_areal2, expected, expected);
  75. }
  76. };
  77. BOOST_AUTO_TEST_CASE( test_intersection_ring_ring_linestring )
  78. {
  79. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  80. std::cout << std::endl << std::endl << std::endl;
  81. std::cout << "*** RING / RING / LINEAR INTERSECTION ***" << std::endl;
  82. std::cout << std::endl;
  83. #endif
  84. typedef open_ring_type OG;
  85. typedef closed_ring_type CG;
  86. typedef multi_linestring_type ML;
  87. typedef test_intersection_aal<OG, OG, CG, CG, ML> tester;
  88. tester::apply
  89. ("r-r-01",
  90. from_wkt<OG>("POLYGON((0 0,0 2,2 2,2 0))"),
  91. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  92. from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
  93. from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
  94. );
  95. tester::apply
  96. ("r-r-02",
  97. from_wkt<OG>("POLYGON(())"),
  98. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  99. from_wkt<ML>("MULTILINESTRING()")
  100. );
  101. tester::apply
  102. ("r-r-03",
  103. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  104. from_wkt<OG>("POLYGON(())"),
  105. from_wkt<ML>("MULTILINESTRING()")
  106. );
  107. tester::apply
  108. ("r-r-04",
  109. from_wkt<OG>("POLYGON(())"),
  110. from_wkt<OG>("POLYGON(())"),
  111. from_wkt<ML>("MULTILINESTRING()")
  112. );
  113. }
  114. BOOST_AUTO_TEST_CASE( test_intersection_ring_polygon_linestring )
  115. {
  116. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  117. std::cout << std::endl << std::endl << std::endl;
  118. std::cout << "*** RING / POLYGON / LINEAR INTERSECTION ***" << std::endl;
  119. std::cout << std::endl;
  120. #endif
  121. typedef open_ring_type OG1;
  122. typedef open_polygon_type OG2;
  123. typedef closed_ring_type CG1;
  124. typedef closed_polygon_type CG2;
  125. typedef multi_linestring_type ML;
  126. typedef test_intersection_aal<OG1, OG2, CG1, CG2, ML> tester;
  127. tester::apply
  128. ("r-pg-01",
  129. from_wkt<OG1>("POLYGON((0 0,0 2,2 2,2 0))"),
  130. from_wkt<OG2>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  131. from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
  132. from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
  133. );
  134. }
  135. BOOST_AUTO_TEST_CASE( test_intersection_ring_multipolygon_linestring )
  136. {
  137. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  138. std::cout << std::endl << std::endl << std::endl;
  139. std::cout << "*** RING / MULTIPOLYGON / LINEAR INTERSECTION ***"
  140. << std::endl;
  141. std::cout << std::endl;
  142. #endif
  143. typedef open_ring_type OG1;
  144. typedef open_multipolygon_type OG2;
  145. typedef closed_ring_type CG1;
  146. typedef closed_multipolygon_type CG2;
  147. typedef multi_linestring_type ML;
  148. typedef test_intersection_aal<OG1, OG2, CG1, CG2, ML> tester;
  149. tester::apply
  150. ("r-mpg-01",
  151. from_wkt<OG1>("POLYGON((0 0,0 2,2 2,2 0))"),
  152. from_wkt<OG2>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
  153. from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
  154. from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
  155. );
  156. }
  157. BOOST_AUTO_TEST_CASE( test_intersection_polygon_polygon_linestring )
  158. {
  159. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  160. std::cout << std::endl << std::endl << std::endl;
  161. std::cout << "*** POLYGON / POLYGON / LINEAR INTERSECTION ***" << std::endl;
  162. std::cout << std::endl;
  163. #endif
  164. typedef open_polygon_type OG;
  165. typedef closed_polygon_type CG;
  166. typedef multi_linestring_type ML;
  167. typedef test_intersection_aal<OG, OG, CG, CG, ML> tester;
  168. tester::apply
  169. ("pg-pg-01",
  170. from_wkt<OG>("POLYGON((0 0,0 2,2 2,2 0))"),
  171. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  172. from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
  173. from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
  174. );
  175. tester::apply
  176. ("pg-pg-02",
  177. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  178. from_wkt<OG>("POLYGON((2 2,2 7,7 7,7 2))"),
  179. from_wkt<ML>("MULTILINESTRING((2 2,2 2),(2 2,2 7,7 7,7 2,2 2),(2 2,2 2))"),
  180. from_wkt<ML>("MULTILINESTRING((2 2,2 2),(2 2,7 2,7 7,2 7,2 2),(2 2,2 2))")
  181. );
  182. tester::apply
  183. ("pg-pg-03",
  184. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  185. from_wkt<OG>("POLYGON((2 3,2 6,6 6,6 3))"),
  186. from_wkt<ML>("MULTILINESTRING((2 3,2 6),(2 3,2 3))")
  187. );
  188. tester::apply
  189. ("pg-pg-04",
  190. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  191. from_wkt<OG>("POLYGON((2 3,2 7,6 7,6 3))"),
  192. from_wkt<ML>("MULTILINESTRING((2 3,2 7,6 7),(2 3,2 3))")
  193. );
  194. tester::apply
  195. ("pg-pg-05",
  196. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  197. from_wkt<OG>("POLYGON((2 3,2 7,7 7,7 3))"),
  198. from_wkt<ML>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
  199. );
  200. tester::apply
  201. ("pg-pg-06",
  202. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  203. from_wkt<OG>("POLYGON((2 3,2 7,7 7,7 3))"),
  204. from_wkt<ML>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
  205. );
  206. tester::apply
  207. ("pg-pg-07",
  208. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  209. from_wkt<OG>("POLYGON((2 5,5 7,7 5,5 2))"),
  210. from_wkt<ML>("MULTILINESTRING((2 5,2 5),(5 7,5 7),(7 5,7 5),(5 2,5 2))")
  211. );
  212. tester::apply
  213. ("pg-pg-08",
  214. from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
  215. from_wkt<OG>("POLYGON((2 5,4 7,6 7,7 5,5 2))"),
  216. from_wkt<ML>("MULTILINESTRING((2 5,2 5),(4 7,6 7),(7 5,7 5),(5 2,5 2))")
  217. );
  218. tester::apply
  219. ("pg-pg-09",
  220. from_wkt<OG>("POLYGON(())"),
  221. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  222. from_wkt<ML>("MULTILINESTRING()")
  223. );
  224. tester::apply
  225. ("pg-pg-10",
  226. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
  227. from_wkt<OG>("POLYGON(())"),
  228. from_wkt<ML>("MULTILINESTRING()")
  229. );
  230. tester::apply
  231. ("pg-pg-11",
  232. from_wkt<OG>("POLYGON(())"),
  233. from_wkt<OG>("POLYGON(())"),
  234. from_wkt<ML>("MULTILINESTRING()")
  235. );
  236. tester::apply
  237. ("pg-pg-12",
  238. from_wkt<OG>("POLYGON((),())"),
  239. from_wkt<OG>("POLYGON((),(),())"),
  240. from_wkt<ML>("MULTILINESTRING()")
  241. );
  242. tester::apply
  243. ("pg-pg-13",
  244. from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0),())"),
  245. from_wkt<OG>("POLYGON(())"),
  246. from_wkt<ML>("MULTILINESTRING()")
  247. );
  248. }
  249. BOOST_AUTO_TEST_CASE( test_intersection_polygon_multipolygon_linestring )
  250. {
  251. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  252. std::cout << std::endl << std::endl << std::endl;
  253. std::cout << "*** POLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
  254. << std::endl;
  255. std::cout << std::endl;
  256. #endif
  257. typedef open_polygon_type OG1;
  258. typedef open_multipolygon_type OG2;
  259. typedef closed_polygon_type CG1;
  260. typedef closed_multipolygon_type CG2;
  261. typedef multi_linestring_type ML;
  262. typedef test_intersection_aal<OG1, OG2, CG1, CG2, ML> tester;
  263. tester::apply
  264. ("pg-mpg-01",
  265. from_wkt<OG1>("POLYGON((0 0,0 2,2 2,2 0))"),
  266. from_wkt<OG2>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
  267. from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
  268. from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
  269. );
  270. }
  271. BOOST_AUTO_TEST_CASE( test_intersection_multipolygon_multipolygon_linestring )
  272. {
  273. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  274. std::cout << std::endl << std::endl << std::endl;
  275. std::cout << "*** MULTIPOLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
  276. << std::endl;
  277. std::cout << std::endl;
  278. #endif
  279. typedef open_multipolygon_type OG;
  280. typedef closed_multipolygon_type CG;
  281. typedef multi_linestring_type ML;
  282. typedef test_intersection_aal<OG, OG, CG, CG, ML> tester;
  283. tester::apply
  284. ("mpg-mpg-01",
  285. from_wkt<OG>("MULTIPOLYGON(((0 0,0 2,2 2,2 0)))"),
  286. from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
  287. from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
  288. from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
  289. );
  290. tester::apply
  291. ("mpg-mpg-02",
  292. from_wkt<OG>("MULTIPOLYGON(((0 0,0 10,10 10,10 0),(2 2,8 2,8 8,2 8)))"),
  293. from_wkt<OG>("MULTIPOLYGON(((2 4,2 6,8 6,8 4)))"),
  294. from_wkt<ML>("MULTILINESTRING((2 4,2 4),(2 4,2 6),(8 6,8 4))")
  295. );
  296. tester::apply
  297. ("mpg-mpg-03",
  298. from_wkt<OG>("MULTIPOLYGON()"),
  299. from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
  300. from_wkt<ML>("MULTILINESTRING()")
  301. );
  302. tester::apply
  303. ("mpg-mpg-04",
  304. from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
  305. from_wkt<OG>("MULTIPOLYGON()"),
  306. from_wkt<ML>("MULTILINESTRING()")
  307. );
  308. tester::apply
  309. ("mpg-mpg-05",
  310. from_wkt<OG>("MULTIPOLYGON()"),
  311. from_wkt<OG>("MULTIPOLYGON()"),
  312. from_wkt<ML>("MULTILINESTRING()")
  313. );
  314. tester::apply
  315. ("mpg-mpg-06",
  316. from_wkt<OG>("MULTIPOLYGON((()),((),()))"),
  317. from_wkt<OG>("MULTIPOLYGON()"),
  318. from_wkt<ML>("MULTILINESTRING()")
  319. );
  320. tester::apply
  321. ("mpg-mpg-07",
  322. from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0),(),()))"),
  323. from_wkt<OG>("MULTIPOLYGON()"),
  324. from_wkt<ML>("MULTILINESTRING()")
  325. );
  326. }