/Src/Dependencies/Boost/libs/geometry/test/algorithms/union.cpp

http://hadesmem.googlecode.com/ · C++ · 327 lines · 205 code · 76 blank · 46 comment · 2 complexity · 3e8516cee1cab8c4f05e73a9926f1da2 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <iostream>
  12. #include <string>
  13. //#define BOOST_GEOMETRY_DEBUG_ASSEMBLE
  14. //#define BOOST_GEOMETRY_DEBUG_IDENTIFIER
  15. #include <algorithms/test_union.hpp>
  16. #include <algorithms/test_overlay.hpp>
  17. #include <algorithms/overlay/overlay_cases.hpp>
  18. #include <boost/geometry/geometries/point_xy.hpp>
  19. static std::string javier4[2] =
  20. {
  21. "POLYGON((-2 2, 1842 2, 1842 -2362, -2 -2362, -2 2), (0 0, 0 -2360, 1840 -2360, 1840 0, 0 0))",
  22. // "POLYGON((-0.01 -1960, 0 -1960, 0 -1880, 0.01 -1960, -0.01 -1960))"
  23. "POLYGON ((-0.01 -1960, 80.01 -1960, 0 -1880, -0.01 -1960))"
  24. };
  25. template <typename Ring, typename Polygon>
  26. void test_areal()
  27. {
  28. test_one<Polygon, Polygon, Polygon>("javier4",
  29. javier4[0], javier4[1],
  30. 1, 1, 13, 20016.4);
  31. test_one<Polygon, Polygon, Polygon>("simplex_normal",
  32. simplex_normal[0], simplex_normal[1],
  33. 1, 0, 13, 11.526367);
  34. test_one<Polygon, Polygon, Polygon>("simplex_with_empty_1",
  35. simplex_normal[0], polygon_empty,
  36. 1, 0, 4, 8.0);
  37. test_one<Polygon, Polygon, Polygon>("simplex_with_empty_2",
  38. polygon_empty, simplex_normal[0],
  39. 1, 0, 4, 8.0);
  40. test_one<Polygon, Polygon, Polygon>("star_ring", example_star, example_ring,
  41. 1, 0, 23, 5.67017141);
  42. // This sample was selected because of the border case, and ttmath generates one point more.
  43. test_one<Polygon, Polygon, Polygon>("star_poly", example_star, example_polygon,
  44. 1, 1,
  45. #if defined(HAVE_TTMATH)
  46. boost::is_same<typename bg::coordinate_type<Ring>::type, ttmath_big>::value ? 28 : 27,
  47. #else
  48. 27,
  49. #endif
  50. 5.647949);
  51. // Pseudo-box as Polygon
  52. // (note, internally, the intersection points is different, so yes,
  53. // it has to be tested)
  54. test_one<Polygon, Polygon, Polygon>("box_poly3", "POLYGON((1.5 1.5 , 1.5 2.5 , 4.5 2.5 , 4.5 1.5 , 1.5 1.5))",
  55. "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,5.3 2.5,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3))",
  56. 1, 1, 15, 5.93625);
  57. test_one<Polygon, Polygon, Polygon>("first_within_second",
  58. first_within_second[0], first_within_second[1],
  59. 1, 0, 5, 25.0);
  60. test_one<Polygon, Polygon, Polygon>("second_within_first",
  61. first_within_second[1], first_within_second[0],
  62. 1, 0, 5, 25.0);
  63. test_one<Polygon, Polygon, Polygon>("first_within_hole_of_second",
  64. first_within_hole_of_second[0], first_within_hole_of_second[1],
  65. 2, 1, 15, 17.0);
  66. test_one<Polygon, Polygon, Polygon>("new_hole",
  67. new_hole[0], new_hole[1],
  68. 1, 1, 14, 23.0);
  69. test_one<Polygon, Polygon, Polygon>("side_side",
  70. side_side[0], side_side[1], 1, 0, 7, 2.0);
  71. test_one<Polygon, Polygon, Polygon>("identical",
  72. identical[0], identical[1], 1, 0, 5, 1.0);
  73. test_one<Polygon, Polygon, Polygon>("disjoint",
  74. disjoint[0], disjoint[1], 2, 0, 10, 2.0);
  75. test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect",
  76. intersect_holes_intersect[0], intersect_holes_intersect[1],
  77. 1, 1, 14, 39.75);
  78. test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect_and_disjoint",
  79. intersect_holes_intersect_and_disjoint[0], intersect_holes_intersect_and_disjoint[1],
  80. 1, 1, 14, 39.75);
  81. test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect_and_touch",
  82. intersect_holes_intersect_and_touch[0], intersect_holes_intersect_and_touch[1],
  83. 1, 1, 14, 39.75);
  84. test_one<Polygon, Polygon, Polygon>("intersect_holes_new_ring",
  85. intersect_holes_new_ring[0], intersect_holes_new_ring[1],
  86. 1, 2, 15, 253.8961);
  87. test_one<Polygon, Polygon, Polygon>("intersect_holes_disjoint",
  88. intersect_holes_disjoint[0],
  89. intersect_holes_disjoint[1],
  90. 1, 0, 9, 40.0);
  91. test_one<Polygon, Polygon, Polygon>("within_holes_disjoint",
  92. within_holes_disjoint[0], within_holes_disjoint[1],
  93. 1, 0, 5, 49.0);
  94. test_one<Polygon, Polygon, Polygon>("winded",
  95. winded[0], winded[1],
  96. 1, 5, 30, 114.0);
  97. test_one<Polygon, Polygon, Polygon>("two_bends",
  98. two_bends[0], two_bends[1],
  99. 1, 0, 7, 40.0);
  100. test_one<Polygon, Polygon, Polygon>("star_comb_15",
  101. star_comb_15[0], star_comb_15[1],
  102. 1, 27, 204, 898.09693338);
  103. test_one<Polygon, Polygon, Polygon>("equal_holes_disjoint",
  104. equal_holes_disjoint[0], equal_holes_disjoint[1],
  105. 1, 1, 10, 81 - 3 * 7);
  106. test_one<Polygon, Polygon, Polygon>("only_hole_intersections1",
  107. only_hole_intersections[0], only_hole_intersections[1],
  108. 1, 2, 13, 190.9090909);
  109. test_one<Polygon, Polygon, Polygon>("only_hole_intersections2",
  110. only_hole_intersections[0], only_hole_intersections[2],
  111. 1, 2, 13, 190.9090909);
  112. test_one<Polygon, Polygon, Polygon>("intersect_exterior_and_interiors_winded",
  113. intersect_exterior_and_interiors_winded[0], intersect_exterior_and_interiors_winded[1],
  114. 1, 1, 26, 66.5333333);
  115. test_one<Polygon, Polygon, Polygon>("crossed",
  116. crossed[0], crossed[1],
  117. 1, 3, 17, 23.5); // Area from SQL Server - was somehow wrong before
  118. test_one<Polygon, Polygon, Polygon>("fitting",
  119. fitting[0], fitting[1],
  120. 1, 0, 5, 25);
  121. test_one<Polygon, Polygon, Polygon>("distance_zero",
  122. distance_zero[0], distance_zero[1],
  123. 1, 0, 11, 9.0098387);
  124. test_one<Polygon, Polygon, Polygon>("wrapped_a",
  125. wrapped[0], wrapped[1],
  126. 1, 1, 16, 16);
  127. test_one<Polygon, Polygon, Polygon>("wrapped_b",
  128. wrapped[0], wrapped[2],
  129. 1, 1, 16, 16);
  130. test_one<Polygon, Polygon, Polygon>("9",
  131. case_9[0], case_9[1], 2, 0, 8, 11);
  132. test_one<Polygon, Polygon, Polygon>("22",
  133. case_22[0], case_22[1], 2, 0, 8, 9.5);
  134. test_one<Polygon, Polygon, Polygon>("25",
  135. case_25[0], case_25[1], 2, 0, 8, 7);
  136. test_one<Polygon, Polygon, Polygon>("26",
  137. case_26[0], case_26[1], 2, 0, 9, 7.5);
  138. test_one<Polygon, Polygon, Polygon>("31",
  139. case_31[0], case_31[1], 2, 0, 8, 4.5);
  140. test_one<Polygon, Polygon, Polygon>("32",
  141. case_32[0], case_32[1], 2, 0, 8, 4.5);
  142. test_one<Polygon, Polygon, Polygon>("33",
  143. case_33[0], case_33[1], 2, 0, 8, 4.5);
  144. test_one<Polygon, Polygon, Polygon>("36",
  145. case_36[0], case_36[1], 1, 0, 10, 14.375);
  146. test_one<Polygon, Polygon, Polygon>("40",
  147. case_40[0], case_40[1], 2, 0, 18, 11);
  148. // Test rings which should be generated by assemble
  149. test_one<Polygon, Polygon, Polygon>("53_iet",
  150. case_53[0], case_53[2], 1, 1, 16, 16);
  151. test_one<Polygon, Polygon, Polygon>("58_iet",
  152. case_58[0], case_58[2], 1, 3, 20, 12.16666);
  153. test_one<Polygon, Polygon, Polygon>("59_iet",
  154. case_59[0], case_59[2], 1, 1, 14, 17.20833);
  155. /*
  156. test_one<Polygon, Polygon, Polygon>(102,
  157. simplex_normal[0], simplex_reversed[1],
  158. 1, 0, 7, X);
  159. test_one<Polygon, Polygon, Polygon>(103,
  160. simplex_reversed[0], simplex_normal[1],
  161. 1, 0, 7, 24.0);
  162. test_one<Polygon, Polygon, Polygon>(104,
  163. simplex_reversed[0], simplex_reversed[1],
  164. 1, 0, 7, 24.0);
  165. test_one<Polygon, Polygon, Polygon>(100,
  166. star_15, comb_15,
  167. 1, 10, 7, 24.0);
  168. */
  169. // test some other input/output types
  170. // 1 input Ring
  171. test_one<Polygon, Polygon, Ring>("identical_pr", identical[0], identical[1], 1, 0, 5, 1.0);
  172. test_one<Polygon, Ring, Polygon>("identical_rp", identical[0], identical[1], 1, 0, 5, 1.0);
  173. // 2 input rings
  174. test_one<Polygon, Ring, Ring>("identical_rr", identical[0], identical[1], 1, 0, 5, 1.0);
  175. // output is also Ring
  176. test_one<Ring, Ring, Ring>("identical_rrr", identical[0], identical[1], 1, 0, 5, 1.0);
  177. // "new hole", tested with Ring -> the newly formed hole will be omitted
  178. test_one<Ring, Ring, Ring>("new_hole_discarded", new_hole[0], new_hole[1], 1, 0, 9, 24.0);
  179. test_one<Polygon, Polygon, Polygon>("ggl_list_20110306_javier",
  180. ggl_list_20110306_javier[0], ggl_list_20110306_javier[1],
  181. 1, 1, 16, 80456.4904910401);
  182. #ifdef _MSC_VER
  183. {
  184. // Isovist (submitted by Brandon during Formal Review)
  185. std::string tn = string_from_type<typename bg::coordinate_type<Polygon>::type>::name();
  186. test_one<Polygon, Polygon, Polygon>("isovist",
  187. isovist1[0], isovist1[1],
  188. 1,
  189. 0,
  190. tn == std::string("f") ? 71
  191. : tn == std::string("d") ? 72
  192. : 73,
  193. 313.36036462);
  194. }
  195. #endif
  196. }
  197. template <typename P>
  198. void test_all()
  199. {
  200. typedef bg::model::polygon<P> polygon;
  201. typedef bg::model::ring<P> ring;
  202. typedef bg::model::box<P> box;
  203. test_areal<ring, polygon>();
  204. // Open
  205. test_areal<bg::model::ring<P, true, false>, bg::model::polygon<P, true, false> >();
  206. // Counter clockwise
  207. test_areal<bg::model::ring<P, false>, bg::model::polygon<P, false> >();
  208. // Counter clockwise and open
  209. test_areal<bg::model::ring<P, false, false>, bg::model::polygon<P, false, false> >();
  210. test_one<polygon, box, polygon>("box_ring", example_box, example_ring,
  211. 1, 1, 15, 6.38875);
  212. test_one<polygon, box, polygon>("box_poly", example_box, example_polygon,
  213. 1, 3, 23, 6.30983);
  214. test_one<polygon, box, polygon>("box_poly1", example_box,
  215. "POLYGON((3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2))",
  216. 1, 1, 15, 6.38875);
  217. test_one<polygon, box, polygon>("box_poly2", example_box,
  218. "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,5.3 2.5,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3))",
  219. 1, 1, 15, 5.93625);
  220. // 3: see areal
  221. test_one<polygon, box, polygon>("box_poly4", example_box,
  222. "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 2.5,4.5 1.2,4.9 0.8,2.9 0.7,2 1.3))",
  223. 1, 1, 15, 4.651245);
  224. test_one<polygon, box, polygon>("box_poly5", example_box,
  225. "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 2.5,4.5 2.3,5.0 2.3,5.0 2.1,4.5 2.1,4.5 1.9,4.0 1.9,4.5 1.2,4.9 0.8,2.9 0.7,2 1.3))",
  226. 1, 1, 21, 4.7191);
  227. test_one<polygon, box, polygon>("box_poly6", example_box,
  228. "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 1.2,2.9 0.7,2 1.3))",
  229. 1, 1, 15, 4.2174);
  230. test_one<polygon, box, polygon>("box_poly7", example_box,
  231. "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.0 3.0,5.0 2.0,2.9 0.7,2 1.3))",
  232. 1, 1, 17, 4.270554);
  233. test_one<polygon, box, polygon>("box_poly8", "box(0 0, 3 3)",
  234. "POLYGON((2 2, 1 4, 2 4, 3 3, 2 2))",
  235. 1, 0, 8, 10.25);
  236. }
  237. int test_main(int, char* [])
  238. {
  239. test_all<bg::model::d2::point_xy<double> >();
  240. #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  241. test_all<bg::model::d2::point_xy<float> >();
  242. //test_all<bg::model::d2::point_xy<long double> >();
  243. #if defined(HAVE_TTMATH)
  244. test_all<bg::model::d2::point_xy<ttmath_big> >();
  245. #endif
  246. #endif
  247. return 0;
  248. }