covered_by_sph.cpp 12 KB

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