get_turns_linear_areal.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2014, 2015.
  7. // Modifications copyright (c) 2014-2015 Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #include "test_get_turns.hpp"
  15. #include <boost/geometry/geometries/geometries.hpp>
  16. //TEST
  17. //#include <to_svg.hpp>
  18. template <typename T>
  19. void test_all()
  20. {
  21. typedef bg::model::point<T, 2, bg::cs::cartesian> pt;
  22. typedef bg::model::linestring<pt> ls;
  23. typedef bg::model::polygon<pt> poly;
  24. test_geometry<ls, poly>("LINESTRING(15 5,24 5,20 2,19 0,13 -4,1 0,10 0,13 3,15 7,16 10,10 10,8 10,4 6,2 8,1 10)",
  25. "POLYGON((0 0,5 5,0 10,20 10,20 2,19 0,0 0)(10 3,15 3,15 7,10 7,10 3))",
  26. expected("miu+")("iuu+")("tcc+")("tuu=")("mcu+")("mic=")("muu+")
  27. ("tiu+")("mcu+")("mic=")("mcc+")("miu=")("mxu+"));
  28. test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  29. "miu+", "mxu+");
  30. test_geometry<ls, poly>("LINESTRING(0 0,5 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  31. "tiu+", "txu+");
  32. test_geometry<ls, poly>("LINESTRING(0 0,5 0,5 5,10 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  33. expected("tcu+")("mic=")("mcc+")("txu="));
  34. test_geometry<ls, poly>("LINESTRING(10 0,5 0,5 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  35. expected("tcc+")("miu=")("mcu+")("txc="));
  36. test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10)",
  37. "POLYGON((0 0,5 5,0 10,20 10,20 2,19 0,0 0)(10 3,15 3,15 7,10 7,10 3))",
  38. expected("tcu+")("mic=")("mcu+")("mic=")("mxu+"));
  39. test_geometry<ls, poly>("LINESTRING(11 1,10 0,0 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  40. "tcc+", "txu=");
  41. test_geometry<ls, poly>("LINESTRING(0 0,10 0,11 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  42. "tcu+", "tuc=");
  43. test_geometry<ls, poly>("LINESTRING(10 0,0 0,-1 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  44. "tcc+", "tuu=");
  45. // true hole
  46. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  47. "POLYGON((0 0,0 10,10 10,10 5,10 0,0 0)(2 2,10 5,2 8,2 2))",
  48. expected("tiu+")("tiu+"));
  49. test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)",
  50. "POLYGON((0 0,0 10,10 10,10 5,10 0,0 0)(2 2,10 5,2 8,2 2))",
  51. expected("mcu+")("ecc=")("tiu+")("mxc="));
  52. // fake hole
  53. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  54. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  55. expected("tuu+")("tiu+"));
  56. test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)",
  57. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  58. expected("mcu+")("tuc=")("tcu+")("mxc="));
  59. // true hole
  60. test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 2)",
  61. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  62. expected("mcu+")("mic=")("tcu+")("txc="));
  63. test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 8)",
  64. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  65. expected("mcu+")("mic=")("tcc+")("txu="));
  66. // SPIKE - NON-ENDPOINT - NON-OPPOSITE
  67. // spike - neq eq
  68. test_geometry<ls, poly>("LINESTRING(2 2,4 4,1 1)", "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  69. expected("mcc+")("txu=")("tcu=")("mxc="));
  70. // spike - eq eq
  71. test_geometry<ls, poly>("LINESTRING(0 0,4 4,1 1)", "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  72. expected("tcc+")("txu=")("tcu=")("mxc="));
  73. // spike - eq neq
  74. test_geometry<ls, poly>("LINESTRING(0 0,3 3,1 1)", "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  75. expected("tcc+")("mxu=")("mcu=")("mxc="));
  76. // spike - neq neq
  77. test_geometry<ls, poly>("LINESTRING(1 1,3 3,2 2)", "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  78. expected("mcc+")("mxu=")("mcu=")("mxc="));
  79. // spike - out neq
  80. test_geometry<ls, poly>("LINESTRING(0 0,3 3,2 2)", "POLYGON((1 1,4 4,6 3,6 0,1 1))",
  81. expected("mcc+")("mxu=")("mcu=")("mxc="));
  82. // spike - out eq
  83. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2)", "POLYGON((1 1,4 4,6 3,6 0,1 1))",
  84. expected("mcc+")("txu=")("tcu=")("mxc="));
  85. // spike - out out/eq
  86. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2)", "POLYGON((1 0,4 4,6 3,1 0))",
  87. expected("tuu+"));
  88. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2)", "POLYGON((0 1,4 4,6 3,6 0,-1 -1,0 1))",
  89. expected("tiu+"));
  90. // spike - out out/neq
  91. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2)", "POLYGON((4 0,4 5,6 3,4 0))",
  92. expected("muu+"));
  93. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2)", "POLYGON((0 4,5 4,6 3,6 0,-1 -1,0 4))",
  94. expected("miu+"));
  95. test_geometry<ls, poly>("LINESTRING(0 1,1 1,0 1)", "POLYGON((0 0,3 3,3 0,0 0))",
  96. expected("muu+"));
  97. test_geometry<ls, poly>("LINESTRING(0 1,3 3,0 1)", "POLYGON((0 0,3 3,3 0,0 0))",
  98. expected("tuu+"));
  99. test_geometry<ls, poly>("LINESTRING(0 1,0 0,0 1)", "POLYGON((0 0,3 3,3 0,0 0))",
  100. expected("tuu+"));
  101. // SPIKE - NON-ENDPOINT - OPPOSITE
  102. // opposite - eq eq
  103. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2)", "POLYGON((-1 -1,0 0,4 4,6 3,-1 -1))",
  104. expected("tcu+")("txc=")("tcc=")("mxu="));
  105. // opposite - neq eq
  106. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2)", "POLYGON((-1 -1,0 0,5 5,6 3,-1 -1))",
  107. expected("mcu+")("txc=")("tcc=")("mxu="));
  108. // opposite - eq, neq
  109. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2)", "POLYGON((-2 -2,-1 -1,4 4,6 3,-2 -2))",
  110. expected("tcu+")("mxc=")("mcc=")("mxu="));
  111. // opposite - neq neq
  112. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2)", "POLYGON((-2 -2,-1 -1,3 3,6 3,-2 -2))",
  113. expected("mcu+")("mxc=")("mcc=")("mxu="));
  114. // opposite - neq neq
  115. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2)", "POLYGON((-2 -2,-1 -1,3 3,5 5,6 3,-2 -2))",
  116. expected("mcu+")("mxc=")("mcc=")("mxu="));
  117. // spike vs internal
  118. test_geometry<ls, poly>("LINESTRING(0 1,1 1,0 1)", // --
  119. "POLYGON((1 0,1 1,2 1,1 0))",
  120. expected("tuu+"));
  121. test_geometry<ls, poly>("LINESTRING(1 2,1 1,1 2)", // |
  122. "POLYGON((1 0,1 1,2 1,1 0))",
  123. expected("tuu+"));
  124. test_geometry<ls, poly>("LINESTRING(0 2,1 1,0 2)",
  125. "POLYGON((1 0,1 1,2 1,1 0))",
  126. expected("tuu+"));
  127. test_geometry<ls, poly>("LINESTRING(2 0,1 1,2 0)",
  128. "POLYGON((1 0,1 1,2 1,2 0,1 0))",
  129. expected("tiu+")("tiu+")("txu+")); // TODO: should spike point be duplicated?
  130. test_geometry<ls, poly>("LINESTRING(0 0,1 1,0 0)", // /
  131. "POLYGON((1 0,1 1,2 1,1 0))",
  132. expected("tuu+"));
  133. test_geometry<ls, poly>("LINESTRING(2 2,1 1,2 2)", // /
  134. "POLYGON((1 0,1 1,2 1,1 0))",
  135. expected("tuu+"));
  136. test_geometry<ls, poly>("LINESTRING(2 1,1 1,2 1)",
  137. "POLYGON((1 0,1 1,2 1,1 0))",
  138. expected("tcu+")("txc=")("tcc=")("txu="));
  139. // 21.01.2015
  140. test_geometry<ls, poly>("LINESTRING(1 3,3 1)",
  141. "POLYGON((0 0,0 4,4 4,4 0,2 2,0 0))",
  142. expected("mcu+")("mxc="));
  143. // extended
  144. test_geometry<ls, poly>("LINESTRING(1 7,4 4,7 1)",
  145. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  146. expected("tcu+")("mxc="));
  147. test_geometry<ls, poly>("LINESTRING(1 7,3 5,7 1)",
  148. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  149. expected("mcu+")("mxc="));
  150. test_geometry<ls, poly>("LINESTRING(1 7,5 3,7 1)",
  151. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  152. expected("mcu+")("mxc="));
  153. test_geometry<ls, poly>("LINESTRING(4 4,7 1)",
  154. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  155. expected("tcu+")("mxc="));
  156. test_geometry<ls, poly>("LINESTRING(5 3,7 1)",
  157. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  158. expected("mcu+")("mxc="));
  159. // reversed
  160. test_geometry<ls, poly>("LINESTRING(7 1,4 4,1 7)",
  161. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  162. expected("mcc+")("tiu="));
  163. test_geometry<ls, poly>("LINESTRING(7 1,3 5,1 7)",
  164. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  165. expected("mcc+")("miu="));
  166. test_geometry<ls, poly>("LINESTRING(7 1,5 3,1 7)",
  167. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  168. expected("mcc+")("ccc=")("miu="));
  169. test_geometry<ls, poly>("LINESTRING(7 1,4 4)",
  170. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  171. expected("mcc+")("txu="));
  172. test_geometry<ls, poly>("LINESTRING(7 1,5 3)",
  173. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  174. expected("mcc+")("mxu="));
  175. test_geometry<ls, poly>("LINESTRING(7 1,3 5)",
  176. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  177. expected("mcc+")("miu="));
  178. // 23.01.2015 - spikes
  179. test_geometry<ls, poly>("LINESTRING(3 10, 1 5, 1 10, 3 4, 7 8, 6 10, 10 2)",
  180. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  181. expected("miu+")("miu+")("miu+")("mxu+"));
  182. // extended
  183. test_geometry<ls, poly>("LINESTRING(7 8, 6 10, 11 0)",
  184. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  185. expected("miu+")("iuu+"));
  186. // 25.01.2015
  187. test_geometry<ls, poly>("LINESTRING(2 3, 4 5, 0 6, 5 6)",
  188. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))",
  189. expected("miu+")("miu+")("mcu+")("mxc="));
  190. test_geometry<ls, poly>("LINESTRING(0 6, 5 6)",
  191. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))",
  192. expected("miu+")("mcu+")("mxc="));
  193. }
  194. int test_main(int, char* [])
  195. {
  196. test_all<float>();
  197. test_all<double>();
  198. #if ! defined(_MSC_VER)
  199. test_all<long double>();
  200. #endif
  201. #if defined(HAVE_TTMATH)
  202. test_all<ttmath_big>();
  203. #endif
  204. return 0;
  205. }