disjoint_sph.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. // Boost.Geometry
  2. // Copyright (c) 2016, 2019 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include "test_disjoint.hpp"
  8. #include <algorithms/overlay/overlay_cases.hpp>
  9. #include <algorithms/overlay/multi_overlay_cases.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/strategies/strategies.hpp>
  12. template <typename P>
  13. void test_polygon_polygon()
  14. {
  15. typedef bg::model::polygon<P> poly;
  16. typedef bg::model::ring<P> ring;
  17. test_geometry<ring, ring>(case_1[0], case_1[1],
  18. false);
  19. test_geometry<ring, poly>(case_1[0], case_1[1],
  20. false);
  21. test_geometry<poly, poly>(case_1[0], case_1[1],
  22. false);
  23. test_geometry<poly, poly>(case_2[0], case_2[1],
  24. false);
  25. test_geometry<poly, poly>(case_3_sph[0], case_3_sph[1],
  26. false);
  27. test_geometry<poly, poly>(case_3_2_sph[0], case_3_2_sph[1],
  28. false);
  29. test_geometry<poly, poly>(case_4[0], case_4[1],
  30. false);
  31. test_geometry<poly, poly>(case_5[0], case_5[1],
  32. false);
  33. test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1],
  34. false);
  35. test_geometry<poly, poly>(case_7[0], case_7[1],
  36. false);
  37. test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1],
  38. false);
  39. test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1],
  40. false);
  41. test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1],
  42. false);
  43. test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1],
  44. false);
  45. test_geometry<poly, poly>(case_12[0], case_12[1],
  46. false);
  47. test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1],
  48. false);
  49. test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1],
  50. false);
  51. test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1],
  52. false);
  53. test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1],
  54. false);
  55. test_geometry<poly, poly>(case_17_sph[0], case_17_sph[1],
  56. false);
  57. test_geometry<poly, poly>(case_17_sph[1], case_17_sph[0],
  58. false);
  59. test_geometry<poly, poly>(case_18_sph[0], case_18_sph[1],
  60. false);
  61. test_geometry<poly, poly>(case_18_sph[1], case_18_sph[0],
  62. false);
  63. }
  64. template <typename P>
  65. void test_polygon_multi_polygon()
  66. {
  67. typedef bg::model::polygon<P> poly;
  68. typedef bg::model::ring<P> ring;
  69. typedef bg::model::multi_polygon<poly> mpoly;
  70. test_geometry<ring, mpoly>(case_1[0], case_multi_2[0],
  71. false);
  72. test_geometry<poly, mpoly>(case_2[0], case_multi_2[0],
  73. false);
  74. }
  75. template <typename P>
  76. void test_multi_polygon_multi_polygon()
  77. {
  78. typedef bg::model::polygon<P> poly;
  79. typedef bg::model::multi_polygon<poly> mpoly;
  80. test_geometry<mpoly, mpoly>(case_multi_2[0], case_multi_2[1],
  81. false);
  82. }
  83. template <typename P>
  84. void test_linestring_polygon()
  85. {
  86. typedef bg::model::linestring<P> ls;
  87. typedef bg::model::polygon<P> poly;
  88. typedef bg::model::polygon<P> ring;
  89. test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
  90. test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
  91. test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  92. test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  93. test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  94. test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
  95. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  96. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  97. false);
  98. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
  99. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  100. false);
  101. test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
  102. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  103. false);
  104. }
  105. template <typename P>
  106. void test_linestring_multi_polygon()
  107. {
  108. typedef bg::model::linestring<P> ls;
  109. typedef bg::model::polygon<P> poly;
  110. typedef bg::model::multi_polygon<poly> mpoly;
  111. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
  112. "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)))",
  113. false);
  114. }
  115. template <typename P>
  116. void test_multi_linestring_polygon()
  117. {
  118. typedef bg::model::linestring<P> ls;
  119. typedef bg::model::polygon<P> poly;
  120. typedef bg::model::ring<P> ring;
  121. typedef bg::model::multi_linestring<ls> mls;
  122. test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
  123. "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
  124. false);
  125. test_geometry<mls, ring>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
  126. "POLYGON((5 5,5 15,15 15,15 5,5 5))",
  127. false);
  128. test_geometry<mls, poly>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))",
  129. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  130. false);
  131. }
  132. template <typename P>
  133. void test_multi_linestring_multi_polygon()
  134. {
  135. typedef bg::model::linestring<P> ls;
  136. typedef bg::model::polygon<P> poly;
  137. typedef bg::model::multi_linestring<ls> mls;
  138. typedef bg::model::multi_polygon<poly> mpoly;
  139. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
  140. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
  141. false);
  142. 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))",
  143. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  144. false);
  145. test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
  146. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  147. false);
  148. }
  149. template <typename P>
  150. void test_linestring_linestring()
  151. {
  152. typedef bg::model::linestring<P> ls;
  153. test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", false);
  154. test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", false);
  155. }
  156. //https://svn.boost.org/trac10/ticket/13057
  157. template <typename P>
  158. void test_linestring_linestring_radians()
  159. {
  160. typedef bg::model::linestring<P> ls;
  161. test_geometry<ls, ls>("LINESTRING(0 -0.31415926535897897853,\
  162. 0.26179938779914918578 0,\
  163. -0.034906585039886556254 0.13962634015954622502,\
  164. -0.12217304763960294689 0.12217304763960294689)",\
  165. "LINESTRING(-0.034906585039886556254 0.13962634015954622502,\
  166. -0.26179938779914918578 0)", false);
  167. }
  168. template <typename P>
  169. void test_linestring_multi_linestring()
  170. {
  171. typedef bg::model::linestring<P> ls;
  172. typedef bg::model::multi_linestring<ls> mls;
  173. test_geometry<ls, mls>("LINESTRING(0 0,10 0)",
  174. "MULTILINESTRING((1 0,2 0),(1 1,2 1))",
  175. false);
  176. test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)",
  177. "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))",
  178. false);
  179. }
  180. template <typename P>
  181. void test_multi_linestring_multi_linestring()
  182. {
  183. typedef bg::model::linestring<P> ls;
  184. typedef bg::model::multi_linestring<ls> mls;
  185. test_geometry<mls, mls>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))",
  186. "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))",
  187. false);
  188. }
  189. template <typename P>
  190. void test_point_polygon()
  191. {
  192. typedef bg::model::polygon<P> poly;
  193. // https://svn.boost.org/trac/boost/ticket/9162
  194. test_geometry<P, poly>("POINT(0 90)",
  195. "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
  196. false);
  197. test_geometry<P, poly>("POINT(-120 21)",
  198. "POLYGON((30 0,30 30,90 30, 90 0, 30 0))",
  199. true);
  200. // extended
  201. test_geometry<P, poly>("POINT(0 -90)",
  202. "POLYGON((0 -80,90 -80, -180 -80, -90 -80, 0 -80))",
  203. false);
  204. test_geometry<P, poly>("POINT(0 89)",
  205. "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
  206. false);
  207. test_geometry<P, poly>("POINT(-180 89)",
  208. "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
  209. false);
  210. }
  211. template <typename P>
  212. void test_box_polygon()
  213. {
  214. typedef bg::model::box<P> box;
  215. typedef bg::model::polygon<P> poly;
  216. // https://github.com/boostorg/geometry/issues/466
  217. test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
  218. "POLYGON((2.4 48.90205, 2.4 48.89, 2.3 48.89, 2.3 48.90205, 2.4 48.90205))",
  219. false);
  220. test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
  221. "POLYGON((2.4 48.9021, 2.4 48.89, 2.3 48.89, 2.3 48.9021, 2.4 48.9021))",
  222. false);
  223. test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
  224. "POLYGON((2.4 48.90215, 2.4 48.89, 2.3 48.89, 2.3 48.90215, 2.4 48.90215))",
  225. false);
  226. // extended
  227. test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
  228. "POLYGON((2.4 48.9022, 2.4 48.89, 2.3 48.89, 2.3 48.9022, 2.4 48.9022))",
  229. false);
  230. // box within poly
  231. test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
  232. "POLYGON((2.6 48.9021, 2.6 48.8, 2.1 48.8, 2.1 48.9021, 2.6 48.9021))",
  233. false);
  234. test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
  235. "POLYGON((2.6 48.9022, 2.6 48.8, 2.1 48.8, 2.1 48.9022, 2.6 48.9022))",
  236. false);
  237. // related to https://github.com/boostorg/geometry/issues/579
  238. test_geometry<box, poly>("BOX(10 10,20 20)",
  239. "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0),"
  240. "(12 1,11 1,12 2,12 1))",
  241. true);
  242. }
  243. template <typename P>
  244. void test_all()
  245. {
  246. test_polygon_polygon<P>();
  247. test_polygon_multi_polygon<P>();
  248. test_multi_polygon_multi_polygon<P>();
  249. test_linestring_polygon<P>();
  250. test_linestring_multi_polygon<P>();
  251. test_multi_linestring_polygon<P>();
  252. test_multi_linestring_multi_polygon<P>();
  253. test_linestring_linestring<P>();
  254. test_linestring_multi_linestring<P>();
  255. test_multi_linestring_multi_linestring<P>();
  256. test_point_polygon<P>();
  257. test_box_polygon<P>();
  258. }
  259. int test_main( int , char* [] )
  260. {
  261. typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > point_deg;
  262. typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::radian> > point_rad;
  263. test_all<point_deg>();
  264. test_linestring_linestring_radians<point_rad>();
  265. #if defined(HAVE_TTMATH)
  266. test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  267. #endif
  268. return 0;
  269. }