relate_linear_areal.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2018 Adam Wulkiewicz, Lodz, Poland.
  4. // This file was modified by Oracle on 2013, 2014, 2015.
  5. // Modifications copyright (c) 2013-2015 Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include "test_relate.hpp"
  11. #include "nan_cases.hpp"
  12. //TEST
  13. //#include <to_svg.hpp>
  14. template <typename P>
  15. void test_linestring_polygon()
  16. {
  17. typedef bg::model::linestring<P> ls;
  18. typedef bg::model::polygon<P> poly;
  19. typedef bg::model::ring<P> ring;
  20. // LS disjoint
  21. test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1FF0212");
  22. test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1FF0212");
  23. // II BB
  24. test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1FFF0F212");
  25. test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1FFF0F212");
  26. test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1FF0FF212");
  27. // IE
  28. test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1FF0212");
  29. // IE IB0
  30. test_geometry<ls, poly>("LINESTRING(11 1,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1F00212");
  31. // IE IB1
  32. test_geometry<ls, poly>("LINESTRING(11 1,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212");
  33. test_geometry<ls, poly>("LINESTRING(11 1,10 10,0 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212");
  34. test_geometry<ls, poly>("LINESTRING(11 1,10 0,0 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212");
  35. test_geometry<ls, poly>("LINESTRING(0 -1,1 0,2 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212");
  36. // IE IB0 II
  37. test_geometry<ls, poly>("LINESTRING(11 1,10 5,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212");
  38. // IE IB0 lring
  39. test_geometry<ls, poly>("LINESTRING(11 1,10 5,11 5,11 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F01FFF212");
  40. // IE IB1 lring
  41. test_geometry<ls, poly>("LINESTRING(11 1,10 5,10 10,11 5,11 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11FFF212");
  42. // IB1 II
  43. test_geometry<ls, poly>("LINESTRING(0 0,5 0,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11F00F212");
  44. // BI0 II IB1
  45. test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11FF0F212");
  46. // IB1 II IB1
  47. test_geometry<ls, poly>("LINESTRING(1 0,2 0,3 1,4 0,5 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11FF0F212");
  48. // IB1 IE IB1
  49. test_geometry<ls, poly>("LINESTRING(1 0,2 0,3 -1,4 0,5 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F0F212");
  50. // II IB1
  51. test_geometry<ls, poly>("LINESTRING(5 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11F00F212");
  52. // IB1 II
  53. test_geometry<ls, poly>("LINESTRING(10 10,10 5,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11F00F212");
  54. // IE IB1
  55. test_geometry<ls, poly>("LINESTRING(15 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212");
  56. // IB1 IE
  57. test_geometry<ls, poly>("LINESTRING(10 10,10 5,15 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212");
  58. // duplicated points
  59. {
  60. // II IB0 IE
  61. test_geometry<ls, poly>("LINESTRING(5 5,10 5,15 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212");
  62. test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5,10 5,10 5,10 5,15 10,15 10,15 10)",
  63. "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))",
  64. "1010F0212");
  65. test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5,10 0,10 0,10 0,15 10,15 10,15 10)",
  66. "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))",
  67. "1010F0212");
  68. // IE IB0 II
  69. test_geometry<ls, poly>("LINESTRING(15 10,15 10,15 10,10 5,10 5,10 5,5 5,5 5,5 5)",
  70. "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))",
  71. "1010F0212");
  72. test_geometry<ls, poly>("LINESTRING(15 10,15 10,15 10,10 0,10 0,10 0,5 5,5 5,5 5)",
  73. "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))",
  74. "1010F0212");
  75. // TEST
  76. //test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212");
  77. test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5,15 5,15 5,15 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212");
  78. }
  79. // non-simple polygon with hole
  80. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  81. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  82. "10F0FF212");
  83. test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)",
  84. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  85. "F1FF0F212");
  86. test_geometry<ls, poly>("LINESTRING(2 8,10 5,2 2)",
  87. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  88. "F1FF0F212");
  89. test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 2)",
  90. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  91. "F1FF0F212");
  92. test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 8)",
  93. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  94. "F1FF0F212");
  95. // non-simple polygon with hole, linear ring
  96. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
  97. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  98. "10FFFF212");
  99. test_geometry<ls, poly>("LINESTRING(10 5,10 9,11 5,10 1,10 5)",
  100. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  101. "F11FFF212");
  102. test_geometry<ls, poly>("LINESTRING(11 5,10 1,10 5,10 9,11 5)",
  103. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  104. "F11FFF212");
  105. // non-simple polygon with self-touching holes
  106. test_geometry<ls, poly>("LINESTRING(7 1,8 5,7 9)",
  107. "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 1,9 1,9 9,8 9,8 1),(2 2,8 5,2 8,2 2))",
  108. "10F0FF212");
  109. test_geometry<ls, poly>("LINESTRING(8 2,8 5,8 8)",
  110. "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 1,9 1,9 9,8 9,8 1),(2 2,8 5,2 8,2 2))",
  111. "F1FF0F212");
  112. test_geometry<ls, poly>("LINESTRING(2 8,8 5,2 2)",
  113. "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 1,9 1,9 9,8 9,8 1),(2 2,8 5,2 8,2 2))",
  114. "F1FF0F212");
  115. // non-simple polygon self-touching
  116. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  117. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  118. "10F0FF212");
  119. test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)",
  120. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  121. "F1FF0F212");
  122. test_geometry<ls, poly>("LINESTRING(2 8,10 5,2 2)",
  123. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  124. "F1FF0F212");
  125. // non-simple polygon self-touching, linear ring
  126. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
  127. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  128. "10FFFF212");
  129. test_geometry<ls, poly>("LINESTRING(10 5,10 9,11 5,10 1,10 5)",
  130. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  131. "F11FFF212");
  132. test_geometry<ls, poly>("LINESTRING(11 5,10 1,10 5,10 9,11 5)",
  133. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  134. "F11FFF212");
  135. // polygons with some ring equal to the linestring
  136. test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
  137. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  138. "F1FFFF2F2");
  139. test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
  140. "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2))",
  141. "F1FFFF212");
  142. test_geometry<ls, poly>("LINESTRING(2 2,5 5,2 8,2 2)",
  143. "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2))",
  144. "F1FFFF212");
  145. // self-IP going on the boundary then into the exterior and to the boundary again
  146. test_geometry<ls, poly>("LINESTRING(2 10,5 10,5 15,6 15,5 10,8 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  147. "F11F0F212");
  148. // self-IP going on the boundary then into the interior and to the boundary again
  149. test_geometry<ls, poly>("LINESTRING(2 10,5 10,5 5,6 5,5 10,8 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  150. "11FF0F212");
  151. // self-IP with a hole -> B to I to B to E
  152. test_geometry<ls, poly>("LINESTRING(0 0,3 3)", "POLYGON((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0))",
  153. "FF1F00212");
  154. // ccw
  155. {
  156. typedef bg::model::polygon<P, false> ccwpoly;
  157. // IE IB0 II
  158. test_geometry<ls, ccwpoly>("LINESTRING(11 1,10 5,5 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1010F0212");
  159. // IE IB1 II
  160. test_geometry<ls, ccwpoly>("LINESTRING(11 1,10 1,10 5,5 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212");
  161. test_geometry<ls, ccwpoly>("LINESTRING(11 1,10 5,10 1,5 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212");
  162. // II IB0 IE
  163. test_geometry<ls, ccwpoly>("LINESTRING(5 1,10 5,11 1)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1010F0212");
  164. // IE IB1 II
  165. test_geometry<ls, ccwpoly>("LINESTRING(5 5,10 1,10 5,11 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212");
  166. test_geometry<ls, ccwpoly>("LINESTRING(5 5,10 5,10 1,11 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212");
  167. }
  168. {
  169. // SPIKES
  170. test_geometry<ls, poly>("LINESTRING(0 0,2 2,3 3,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  171. test_geometry<ls, poly>("LINESTRING(0 0,3 3,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  172. test_geometry<ls, poly>("LINESTRING(0 0,2 2,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  173. test_geometry<ls, poly>("LINESTRING(1 1,3 3,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  174. test_geometry<ls, poly>("LINESTRING(1 1,2 2,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FFFF212");
  175. test_geometry<ls, poly>("LINESTRING(3 3,1 1,0 0,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  176. test_geometry<ls, poly>("LINESTRING(3 3,0 0,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  177. test_geometry<ls, poly>("LINESTRING(2 2,0 0,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  178. test_geometry<ls, poly>("LINESTRING(3 3,1 1,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212");
  179. test_geometry<ls, poly>("LINESTRING(2 2,1 1,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FFFF212");
  180. test_geometry<ls, poly>("LINESTRING(0 0,2 2,4 4,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F11F0F212");
  181. test_geometry<ls, poly>("LINESTRING(0 1,1 1,0 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FFF212");
  182. test_geometry<ls, poly>("LINESTRING(0 1,3 3,0 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FFF212");
  183. test_geometry<ls, poly>("LINESTRING(0 1,0 0,0 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FFF212");
  184. test_geometry<ls, poly>("LINESTRING(0 1,1 1,-1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FF0212");
  185. }
  186. {
  187. // POLYGON SPIKES
  188. // note that those are invalid Polygons and in general the result is undefined
  189. // MySQL bug 15.12.2014 (assertion for invalid polygon)
  190. test_geometry<ls, poly>("LINESTRING(6 3,9 0)",
  191. "POLYGON((0 0,5 8,6 1,6 3,8 1,5 4,9 6,2 5,7 4,1 7,0 0))",
  192. "F11F00212");
  193. test_geometry<ls, poly>("LINESTRING(9 0,2 7)",
  194. "POLYGON((4 1,3 2,5 9,8 4,4 5,3 6,8 1,6 2,2 4,6 0,4 1))",
  195. "F11FF0212");
  196. test_geometry<ls, poly>("LINESTRING(6 3,9 0)",
  197. "POLYGON((6 1,6 3,8 1,5 4,6 1))",
  198. "F11F00212");
  199. test_geometry<ls, poly>("LINESTRING(6 3,8 1,9 0)",
  200. "POLYGON((6 1,6 3,8 1,5 4,6 1))",
  201. "F11F00212");
  202. // entry-point spikes are not handled
  203. test_geometry<ls, poly>("LINESTRING(9 0,6 3)",
  204. "POLYGON((6 1,6 3,8 1,5 4,6 1))",
  205. "**1*00212");
  206. test_geometry<ls, poly>("LINESTRING(9 0,8 1,6 3)",
  207. "POLYGON((6 1,6 3,8 1,5 4,6 1))",
  208. "F11F00212");
  209. // Ls going out-in on 2 collinear spikes touching each other
  210. // this works partially, other invalid effect is noticeable here,
  211. // the bottom of a spike shouldn't be there so the algorithm
  212. // thinks the linestring is going into the interior
  213. test_geometry<ls, poly>("LINESTRING(2 2,6 6)",
  214. "POLYGON((0 0,0 2,2 2,4 4,3 3,5 3,5 5,4 4,7 7,7 0,0 0))",
  215. "*1FF0F212");
  216. // Ls going out-in on 2 collinear spikes NOT touching each other
  217. // This is not supported, plus the same as above
  218. test_geometry<ls, poly>("LINESTRING(2 2,6 6)",
  219. "POLYGON((0 0,0 2,2 2,3 3,2 2,5 3,5 5,4 4,7 7,7 0,0 0))",
  220. "*1*F0*212");
  221. }
  222. // 21.01.2015
  223. test_geometry<ls, poly>("LINESTRING(3 7, 9 1)",
  224. "POLYGON((0 0,0 10,10 10,10 0,5 5,0 0))",
  225. "11F00F212");
  226. // inspired by the bug for mls/poly
  227. test_geometry<ls, poly>("LINESTRING(0 0, 7 7)",
  228. "POLYGON((5 5,5 15,15 15,15 5,5 5))",
  229. "1010F0212");
  230. // 25.01.2015
  231. test_geometry<ls, poly>("LINESTRING(4 5, 0 6, 5 6)",
  232. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))",
  233. "11FF0F212");
  234. test_geometry<ls, poly>("LINESTRING(2 3, 4 5, 0 6, 5 6)",
  235. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))",
  236. "11F00F212");
  237. test_geometry<ls, poly>("LINESTRING(2 9, 1 1, 10 1, 10 10, 1 10, 0 6, 5 6)",
  238. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,4 6,6 6,6 4,4 4))",
  239. "11F00F212");
  240. }
  241. template <typename P>
  242. void test_linestring_multi_polygon()
  243. {
  244. typedef bg::model::linestring<P> ls;
  245. typedef bg::model::polygon<P> poly;
  246. typedef bg::model::multi_polygon<poly> mpoly;
  247. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
  248. "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)))",
  249. "F1FF0F212");
  250. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
  251. "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0)))",
  252. "F1FF0F212");
  253. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 2)",
  254. "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)))",
  255. "F1FF0F212");
  256. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 2)",
  257. "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0)))",
  258. "11F00F212");
  259. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 2)",
  260. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))",
  261. "F1FF0F212");
  262. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 8)",
  263. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))",
  264. "F1FF0F212");
  265. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,3 3)",
  266. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))",
  267. "F1FF0F212");
  268. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,3 7)",
  269. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))",
  270. "F1FF0F212");
  271. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,5 5)",
  272. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))",
  273. "11F00F212");
  274. test_geometry<ls, mpoly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
  275. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 20,20 0)))",
  276. "F1FFFF212");
  277. // degenerated points
  278. test_geometry<ls, mpoly>("LINESTRING(5 5,10 10,10 10,10 10,15 15)",
  279. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((10 10,10 20,20 20,20 10,10 10)))",
  280. "10F0FF212");
  281. // self-IP polygon with a hole and second polygon with a hole -> B to I to B to B to I to B to E
  282. test_geometry<ls, mpoly>("LINESTRING(0 0,3 3)",
  283. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)),((0 0,2 8,8 8,8 2,0 0),(0 0,7 3,7 7,3 7,0 0)))",
  284. "FF1F00212");
  285. // self-IP polygon with a hole and second polygon -> B to I to B to B to I
  286. test_geometry<ls, mpoly>("LINESTRING(0 0,3 3)",
  287. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)),((0 0,2 8,8 8,8 2,0 0)))",
  288. "1FF00F212");
  289. test_geometry<ls, mpoly>("LINESTRING(0 0,3 3)",
  290. "MULTIPOLYGON(((0 0,2 8,8 8,8 2,0 0)),((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)))",
  291. "1FF00F212");
  292. // MySQL report 18.12.2014 (https://svn.boost.org/trac/boost/ticket/10887)
  293. test_geometry<ls, mpoly>("LINESTRING(5 -2,5 2)",
  294. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  295. "10F0FF212");
  296. test_geometry<ls, mpoly>("LINESTRING(5 -2,5 5)",
  297. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  298. "10F00F212");
  299. test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)",
  300. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  301. "1FF00F212");
  302. // MySQL report 18.12.2014 - extended
  303. test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)",
  304. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))",
  305. "1FF00F212");
  306. test_geometry<ls, mpoly>("LINESTRING(0 0,5 0)",
  307. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))",
  308. "FF1F00212");
  309. // 22.01.2015
  310. test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,10 0)",
  311. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  312. "11F00F212");
  313. test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,0 10)",
  314. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  315. "11F00F212");
  316. // extended
  317. test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,2 1)",
  318. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  319. "10F0FF212");
  320. test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,5 -5)",
  321. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  322. "1010F0212");
  323. test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,5 -5,5 1)",
  324. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  325. "1010FF212");
  326. test_geometry<ls, mpoly>("LINESTRING(-5 5,0 0,5 -5)",
  327. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  328. "F01FF0212");
  329. }
  330. template <typename P>
  331. void test_multi_linestring_polygon()
  332. {
  333. typedef bg::model::linestring<P> ls;
  334. typedef bg::model::multi_linestring<ls> mls;
  335. typedef bg::model::polygon<P> poly;
  336. typedef typename bg::coordinate_type<P>::type coord_t;
  337. test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
  338. "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
  339. "1F10F0212");
  340. test_geometry<mls, poly>("MULTILINESTRING((10 0, 18 12),(2 2,2 1))",
  341. "POLYGON((5 0,0 -5,-5 0,0 5,5 0))",
  342. "1F10F0212");
  343. if ( BOOST_GEOMETRY_CONDITION((
  344. boost::is_same<coord_t, double>::value )) )
  345. {
  346. // assertion failure in 1.57
  347. test_geometry<mls, poly>("MULTILINESTRING((-0.59322033898305082 -8.0508474576271194,-2.882352941176471 -7.7647058823529411,-2.8823529411764706 -7.7647058823529411,-3.7361111111111112 -6.5694444444444446,-3.4404145077720205 -5.766839378238342,-4.1864406779661012 -3.6779661016949152,-7.5252525252525251 -5.5858585858585865,-7.5862068965517242 -5.1896551724137936,-4.47887323943662 -2.859154929577465,-4.5789473684210531 -2.5789473684210527,-3 -1,-2.9310344827586206 -0.86206896551724144,-3.1764705882352944 -0.70588235294117663,-4.7401960784313726 -2.1274509803921577,-5.3255813953488369 -0.48837209302325502,-4.7872340425531918 0.31914893617021284,-5.8571428571428577 1.0000000000000007,-5.3255813953488369 -0.48837209302325502,-5.9473684210526319 -1.4210526315789465,-8 2,-7.7333333333333334 2.1939393939393939,-8.8294573643410867 2.891472868217055,-8.8556701030927822 3.061855670103093,-7.5999999999999996 3.6000000000000001,-7.7999999999999998 3.7999999999999998,-7.75 3.7916666666666665,-7.5471698113207548 3.6226415094339623,-7.3200000000000003 3.7200000000000002,-3.473684210526315 3.0789473684210527,-3.2549019607843133 3.2156862745098036,-2.9999999999999982 3.1428571428571423,-3.1733333333333325 3.2666666666666666,-2.9180327868852456 3.4262295081967209,-2.8723404255319145 3.1063829787234041,-2.1111111111111112 2.8888888888888888,-2.1428571428571428 2.8571428571428572,-1.8433734939759043 2.8072289156626509,-1.8396226415094346 2.8113207547169816,-1.6486486486486487 2.756756756756757,-1.76510067114094 2.8926174496644301,-0.53846153846153855 4.2307692307692308,1.8148148148148147 5.4074074074074074,1.588235294117647 2.2352941176470589,1.819672131147541 2.1967213114754101,2 4,2 2.1666666666666665,2.3538461538461544 2.1076923076923078,2 1.6875000000000004,2 -2,1.2173913043478262 -3.8260869565217392,1.7375886524822697 1.3758865248226959,1.5073170731707317 1.1024390243902444,1.1428571428571428 -4,-0.59322033898305082 -8.0508474576271194),(1.666666666666667 1.5999999999999988,1.5675675675675675 1.8378378378378377,1.4374999999999991 1.8750000000000002,1.0487804878048776 2.3414634146341466,0.46666666666666712 2.6060606060606055,0.086956521739131043 2.2608695652173911,1.4374999999999991 1.8750000000000002,1.666666666666667 1.5999999999999988))",
  348. "POLYGON((-2.333333333333333 -8.6666666666666661,-4.3253012048192767 -8.168674698795181,-4.1194968553459113 -7.6100628930817606,-2.8823529411764706 -7.7647058823529411,-2.882352941176471 -7.7647058823529411,-2.263157894736842 -8.6315789473684212,-2.333333333333333 -8.6666666666666661))",
  349. "*********");
  350. test_geometry<mls, poly>("MULTILINESTRING((-2.333333333333333 -8.6666666666666661,-4.3253012048192767 -8.168674698795181,-4.1194968553459113 -7.6100628930817606,-2.8823529411764706 -7.7647058823529411,-2.882352941176471 -7.7647058823529411,-2.263157894736842 -8.6315789473684212,-2.333333333333333 -8.6666666666666661))",
  351. "POLYGON((-0.59322033898305082 -8.0508474576271194,-2.882352941176471 -7.7647058823529411,-2.8823529411764706 -7.7647058823529411,-3.7361111111111112 -6.5694444444444446,-3.4404145077720205 -5.766839378238342,-4.1864406779661012 -3.6779661016949152,-7.5252525252525251 -5.5858585858585865,-7.5862068965517242 -5.1896551724137936,-4.47887323943662 -2.859154929577465,-4.5789473684210531 -2.5789473684210527,-3 -1,-2.9310344827586206 -0.86206896551724144,-3.1764705882352944 -0.70588235294117663,-4.7401960784313726 -2.1274509803921577,-5.3255813953488369 -0.48837209302325502,-4.7872340425531918 0.31914893617021284,-5.8571428571428577 1.0000000000000007,-5.3255813953488369 -0.48837209302325502,-5.9473684210526319 -1.4210526315789465,-8 2,-7.7333333333333334 2.1939393939393939,-8.8294573643410867 2.891472868217055,-8.8556701030927822 3.061855670103093,-7.5999999999999996 3.6000000000000001,-7.7999999999999998 3.7999999999999998,-7.75 3.7916666666666665,-7.5471698113207548 3.6226415094339623,-7.3200000000000003 3.7200000000000002,-3.473684210526315 3.0789473684210527,-3.2549019607843133 3.2156862745098036,-2.9999999999999982 3.1428571428571423,-3.1733333333333325 3.2666666666666666,-2.9180327868852456 3.4262295081967209,-2.8723404255319145 3.1063829787234041,-2.1111111111111112 2.8888888888888888,-2.1428571428571428 2.8571428571428572,-1.8433734939759043 2.8072289156626509,-1.8396226415094346 2.8113207547169816,-1.6486486486486487 2.756756756756757,-1.76510067114094 2.8926174496644301,-0.53846153846153855 4.2307692307692308,1.8148148148148147 5.4074074074074074,1.588235294117647 2.2352941176470589,1.819672131147541 2.1967213114754101,2 4,2 2.1666666666666665,2.3538461538461544 2.1076923076923078,2 1.6875000000000004,2 -2,1.2173913043478262 -3.8260869565217392,1.7375886524822697 1.3758865248226959,1.5073170731707317 1.1024390243902444,1.1428571428571428 -4,-0.59322033898305082 -8.0508474576271194),(1.666666666666667 1.5999999999999988,1.5675675675675675 1.8378378378378377,1.4374999999999991 1.8750000000000002,1.0487804878048776 2.3414634146341466,0.46666666666666712 2.6060606060606055,0.086956521739131043 2.2608695652173911,1.4374999999999991 1.8750000000000002,1.666666666666667 1.5999999999999988))",
  352. "*********");
  353. }
  354. // 21.01.2015
  355. test_geometry<mls, poly>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
  356. "POLYGON((5 5,5 15,15 15,15 5,5 5))",
  357. "101000212");
  358. test_geometry<mls, poly>("MULTILINESTRING((15 15,6 6),(0 0, 7 7))",
  359. "POLYGON((5 5,5 15,15 15,15 5,5 5))",
  360. "101000212");
  361. // extended
  362. test_geometry<mls, poly>("MULTILINESTRING((15 15,6 6),(4 14,6 16))",
  363. "POLYGON((5 5,5 15,15 15,15 5,5 5))",
  364. "101000212");
  365. // 23.01.2015
  366. test_geometry<mls, poly>("MULTILINESTRING((4 10, 3 10, 10 6),(5 0, 7 5, 9 10))",
  367. "POLYGON((0 0,0 10,10 10,10 0,5 5,0 0))",
  368. "111F00212");
  369. // 23.01.2015
  370. test_geometry<mls, poly>("MULTILINESTRING((3 10, 1 5, 1 10, 3 4, 7 8, 6 10, 10 2))",
  371. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  372. "10FF0F212");
  373. // mysql bug
  374. // assertion failure in relate->boundary_checker->std::equal_range with msvc
  375. if (BOOST_GEOMETRY_CONDITION(is_nan_case_supported<mls>::value))
  376. {
  377. mls g1;
  378. std::string wkt1;
  379. nan_case(g1, wkt1);
  380. std::string wkt2 = "POLYGON((1.1e+308 1.2e+308,-1 -9,1 1e+12,1.1e+308 7.8e+307,1.1e+308 1.2e+308),(3 2,1 1,8e+307 1e+308,3 2),(258 2049,1 -3,1 1,-6 9,258 2049))";
  381. poly g2;
  382. bg::read_wkt(wkt2, g2);
  383. check_geometry(g1, g2, wkt1, wkt2, "*********");
  384. }
  385. }
  386. template <typename P>
  387. void test_multi_linestring_multi_polygon()
  388. {
  389. typedef bg::model::linestring<P> ls;
  390. typedef bg::model::polygon<P> poly;
  391. typedef bg::model::multi_linestring<ls> mls;
  392. typedef bg::model::multi_polygon<poly> mpoly;
  393. // polygons with some ring equal to the linestrings
  394. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(20 20,50 50,20 80,20 20))",
  395. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  396. "F11FFF2F2");
  397. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
  398. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
  399. "F1FFFF2F2");
  400. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0))",
  401. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  402. "F1FFFF2F2");
  403. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0),(20 20,50 50,20 80,20 20))",
  404. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  405. "F11FFF2F2");
  406. // disjoint
  407. test_geometry<mls, mpoly>("MULTILINESTRING((20 20,30 30),(30 30,40 40))",
  408. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  409. "FF1FF0212");
  410. test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 5),(5 5,5 0),(10 10,10 5,5 5,5 10,10 10))",
  411. "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)),((5 5,10 1,10 0,5 5)))",
  412. "F1FF0F212");
  413. test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 5),(5 5,5 0),(0 5,0 0,5 0),(10 10,10 5,5 5,5 10,10 10))",
  414. "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)),((5 5,10 1,10 0,5 5)))",
  415. "F1FFFF212");
  416. test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 0),(5 5,5 0),(10 10,10 5,5 5,5 10,10 10))",
  417. "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)),((5 5,10 1,10 0,5 5)))",
  418. "11FF0F212");
  419. // MySQL report 18.12.2014 - extended
  420. test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
  421. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  422. "10FFFF212");
  423. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 0,0 -1,5 0))",
  424. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  425. "F01FFF212");
  426. test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(6 -2,5 0))",
  427. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  428. "10F0FF212");
  429. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 -1,5 0))",
  430. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  431. "F01FF0212");
  432. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,5 0),(5 -2,5 0))",
  433. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  434. "1010F0212");
  435. test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,5 0),(0 0,5 0))",
  436. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  437. "1010F0212");
  438. // 22.01.2015 - extended
  439. test_geometry<mls, mpoly>("MULTILINESTRING((10 10,0 10),(5 5,0 0,10 0))",
  440. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  441. "11F00F212");
  442. test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 0,5 -5),(0 0,9 1))",
  443. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  444. "101000212");
  445. test_geometry<mls, mpoly>("MULTILINESTRING((5 -5,0 0,5 5),(0 0,5 -1))",
  446. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
  447. "101000212");
  448. }
  449. template <typename P>
  450. void test_all()
  451. {
  452. test_linestring_polygon<P>();
  453. test_linestring_multi_polygon<P>();
  454. test_multi_linestring_polygon<P>();
  455. test_multi_linestring_multi_polygon<P>();
  456. }
  457. int test_main( int , char* [] )
  458. {
  459. test_all<bg::model::d2::point_xy<int> >();
  460. test_all<bg::model::d2::point_xy<double> >();
  461. #if defined(HAVE_TTMATH)
  462. test_all<bg::model::d2::point_xy<ttmath_big> >();
  463. #endif
  464. return 0;
  465. }