9
3

intersects_sph.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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_intersects.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. true);
  18. test_geometry<ring, poly>(case_1[0], case_1[1],
  19. true);
  20. test_geometry<poly, poly>(case_1[0], case_1[1],
  21. true);
  22. test_geometry<poly, poly>(case_2[0], case_2[1],
  23. true);
  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. true);
  30. test_geometry<poly, poly>(case_5[0], case_5[1],
  31. true);
  32. test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1],
  33. true);
  34. test_geometry<poly, poly>(case_7[0], case_7[1],
  35. true);
  36. test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1],
  37. true);
  38. test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1],
  39. true);
  40. test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1],
  41. true);
  42. test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1],
  43. true);
  44. test_geometry<poly, poly>(case_12[0], case_12[1],
  45. true);
  46. test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1],
  47. true);
  48. test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1],
  49. true);
  50. test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1],
  51. true);
  52. test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1],
  53. true);
  54. test_geometry<poly, poly>(case_17_sph[0], case_17_sph[1],
  55. true);
  56. test_geometry<poly, poly>(case_17_sph[1], case_17_sph[0],
  57. true);
  58. test_geometry<poly, poly>(case_18_sph[0], case_18_sph[1],
  59. true);
  60. test_geometry<poly, poly>(case_18_sph[1], case_18_sph[0],
  61. true);
  62. }
  63. template <typename P>
  64. void test_polygon_multi_polygon()
  65. {
  66. typedef bg::model::polygon<P> poly;
  67. typedef bg::model::ring<P> ring;
  68. typedef bg::model::multi_polygon<poly> mpoly;
  69. test_geometry<ring, mpoly>(case_1[0], case_multi_2[0],
  70. true);
  71. test_geometry<poly, mpoly>(case_2[0], case_multi_2[0],
  72. true);
  73. }
  74. template <typename P>
  75. void test_multi_polygon_multi_polygon()
  76. {
  77. typedef bg::model::polygon<P> poly;
  78. typedef bg::model::multi_polygon<poly> mpoly;
  79. test_geometry<mpoly, mpoly>(case_multi_2[0], case_multi_2[1],
  80. true);
  81. }
  82. template <typename P>
  83. void test_linestring_polygon()
  84. {
  85. typedef bg::model::linestring<P> ls;
  86. typedef bg::model::polygon<P> poly;
  87. typedef bg::model::polygon<P> ring;
  88. test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  89. test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  90. test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
  91. test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
  92. test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
  93. test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  94. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  95. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  96. true);
  97. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
  98. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  99. true);
  100. test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
  101. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  102. true);
  103. }
  104. template <typename P>
  105. void test_linestring_multi_polygon()
  106. {
  107. typedef bg::model::linestring<P> ls;
  108. typedef bg::model::polygon<P> poly;
  109. typedef bg::model::multi_polygon<poly> mpoly;
  110. test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
  111. "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)))",
  112. true);
  113. }
  114. template <typename P>
  115. void test_multi_linestring_polygon()
  116. {
  117. typedef bg::model::linestring<P> ls;
  118. typedef bg::model::polygon<P> poly;
  119. typedef bg::model::ring<P> ring;
  120. typedef bg::model::multi_linestring<ls> mls;
  121. test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
  122. "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
  123. true);
  124. test_geometry<mls, ring>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
  125. "POLYGON((5 5,5 15,15 15,15 5,5 5))",
  126. true);
  127. test_geometry<mls, poly>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))",
  128. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  129. true);
  130. }
  131. template <typename P>
  132. void test_multi_linestring_multi_polygon()
  133. {
  134. typedef bg::model::linestring<P> ls;
  135. typedef bg::model::polygon<P> poly;
  136. typedef bg::model::multi_linestring<ls> mls;
  137. typedef bg::model::multi_polygon<poly> mpoly;
  138. test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
  139. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
  140. true);
  141. 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))",
  142. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  143. true);
  144. test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
  145. "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
  146. true);
  147. }
  148. template <typename P>
  149. void test_linestring_linestring()
  150. {
  151. typedef bg::model::linestring<P> ls;
  152. test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
  153. test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", true);
  154. }
  155. template <typename P>
  156. void test_linestring_multi_linestring()
  157. {
  158. typedef bg::model::linestring<P> ls;
  159. typedef bg::model::multi_linestring<ls> mls;
  160. test_geometry<ls, mls>("LINESTRING(0 0,10 0)",
  161. "MULTILINESTRING((1 0,2 0),(1 1,2 1))",
  162. true);
  163. test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)",
  164. "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))",
  165. true);
  166. }
  167. template <typename P>
  168. void test_multi_linestring_multi_linestring()
  169. {
  170. typedef bg::model::linestring<P> ls;
  171. typedef bg::model::multi_linestring<ls> mls;
  172. test_geometry<mls, mls>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))",
  173. "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))",
  174. true);
  175. }
  176. template <typename P>
  177. void test_point_polygon()
  178. {
  179. typedef bg::model::polygon<P> poly;
  180. // https://svn.boost.org/trac/boost/ticket/9162
  181. test_geometry<P, poly>("POINT(0 90)",
  182. "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
  183. true);
  184. test_geometry<P, poly>("POINT(-120 21)",
  185. "POLYGON((30 0,30 30,90 30, 90 0, 30 0))",
  186. false);
  187. // extended
  188. test_geometry<P, poly>("POINT(0 -90)",
  189. "POLYGON((0 -80,90 -80, -180 -80, -90 -80, 0 -80))",
  190. true);
  191. test_geometry<P, poly>("POINT(0 89)",
  192. "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
  193. true);
  194. test_geometry<P, poly>("POINT(-180 89)",
  195. "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
  196. true);
  197. }
  198. template <typename P>
  199. void test_all()
  200. {
  201. test_polygon_polygon<P>();
  202. test_polygon_multi_polygon<P>();
  203. test_multi_polygon_multi_polygon<P>();
  204. test_linestring_polygon<P>();
  205. test_linestring_multi_polygon<P>();
  206. test_multi_linestring_polygon<P>();
  207. test_multi_linestring_multi_polygon<P>();
  208. test_linestring_linestring<P>();
  209. test_linestring_multi_linestring<P>();
  210. test_multi_linestring_multi_linestring<P>();
  211. test_point_polygon<P>();
  212. }
  213. int test_main( int , char* [] )
  214. {
  215. test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  216. #if defined(HAVE_TTMATH)
  217. test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  218. #endif
  219. return 0;
  220. }