get_turns_linear_areal_sph.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // Boost.Geometry
  2. // Unit Test
  3. // Copyright (c) 2016, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include "test_get_turns.hpp"
  9. #include <boost/geometry/geometries/geometries.hpp>
  10. template <typename T>
  11. void test_all()
  12. {
  13. typedef bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::degree> > pt;
  14. typedef bg::model::linestring<pt> ls;
  15. typedef bg::model::polygon<pt> poly;
  16. test_geometry<ls, poly>("LINESTRING(15 5,24 5,20 2,19 0,13 -4,1 0,10 0,13 3.0027386970408236,15 7,16 10.096620161421658,10 10.151081711048134,8 10.145026423873857,4 6.0128694190616088,2 8.0210217579873273,1 10.028657322246225)",
  17. "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))",
  18. expected("miu+")("iuu+")("tcc+")("tuu=")("mcu+")("mic=")("muu+")
  19. ("tiu+")("mcu+")("mic=")("mcc+")("miu=")("mxu+"));
  20. test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  21. "miu+", "mxu+");
  22. test_geometry<ls, poly>("LINESTRING(0 0,5 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  23. "tiu+", "txu+");
  24. 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))",
  25. expected("tcu+")("mic=")("mcc+")("txu="));
  26. 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))",
  27. expected("tcc+")("miu=")("mcu+")("txc="));
  28. test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10.151081711048134)",
  29. "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))",
  30. expected("tcu+")("mic=")("mcu+")("mic=")("mxu+"));
  31. test_geometry<ls, poly>("LINESTRING(11 1,10 0,0 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  32. "tcc+", "txu=");
  33. test_geometry<ls, poly>("LINESTRING(0 0,10 0,11 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  34. "tcu+", "tuc=");
  35. test_geometry<ls, poly>("LINESTRING(10 0,0 0,-1 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  36. "tcc+", "tuu=");
  37. // true hole
  38. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  39. "POLYGON((0 0,0 10,10 10,10 5,10 0,0 0)(2 2,10 5,2 8,2 2))",
  40. expected("tiu+")("tiu+"));
  41. test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)",
  42. "POLYGON((0 0,0 10,10 10,10 5,10 0,0 0)(2 2,10 5,2 8,2 2))",
  43. expected("mcu+")("ecc=")("tiu+")("mxc="));
  44. // fake hole
  45. test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
  46. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  47. expected("tuu+")("tiu+"));
  48. test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)",
  49. "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))",
  50. expected("mcu+")("tuc=")("tcu+")("mxc="));
  51. // true hole
  52. test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 2)",
  53. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  54. expected("mcu+")("mic=")("tcu+")("txc="));
  55. test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 8)",
  56. "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
  57. expected("mcu+")("mic=")("tcc+")("txu="));
  58. // SPIKE - NON-ENDPOINT - NON-OPPOSITE
  59. // spike - neq eq
  60. test_geometry<ls, poly>("LINESTRING(2 2.0036594926050877,4 4,1 1.0022887548647630)",
  61. "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  62. expected("mcc+")("txu=")("tcu=")("mxc="));
  63. // spike - eq eq
  64. test_geometry<ls, poly>("LINESTRING(0 0,4 4,1 1.0022887548647630)",
  65. "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  66. expected("tcc+")("txu=")("tcu=")("mxc="));
  67. // spike - eq neq
  68. test_geometry<ls, poly>("LINESTRING(0 0,3 3.0031983963093536,1 1.0022887548647630)",
  69. "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  70. expected("tcc+")("mxu=")("mcu=")("mxc="));
  71. // spike - neq neq
  72. test_geometry<ls, poly>("LINESTRING(1 1.0022887548647630,3 3.0031983963093536,2 2.0036594926050877)",
  73. "POLYGON((0 0,4 4,6 3,6 0,0 0))",
  74. expected("mcc+")("mxu=")("mcu=")("mxc="));
  75. // spike - out neq
  76. test_geometry<ls, poly>("LINESTRING(0 -0.0030515201230775146,3 3.0024370300767784,2 2.0021346673827409)",
  77. "POLYGON((1 1,4 4,6 3,6 0,1 1))",
  78. expected("mcc+")("mxu=")("mcu=")("mxc="));
  79. // spike - out eq
  80. test_geometry<ls, poly>("LINESTRING(0 -0.0030515201230775146,4 4,2 2.0021346673827409)",
  81. "POLYGON((1 1,4 4,6 3,6 0,1 1))",
  82. expected("mcc+")("txu=")("tcu=")("mxc="));
  83. // spike - out out/eq
  84. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2.0036594926050877)",
  85. "POLYGON((1 0,4 4,6 3,1 0))",
  86. expected("tuu+"));
  87. test_geometry<ls, poly>("LINESTRING(0 0,4 4,2 2.0036594926050877)",
  88. "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.0036594926050877)",
  92. "POLYGON((4 0,4 5,6 3,4 0))",
  93. expected("muu+"));
  94. test_geometry<ls, poly>("LINESTRING(0 0,4 4.0024308111527205,2 2.0048800944714089)",
  95. "POLYGON((0 4,5 4,6 3,6 0,-1 -1,0 4))",
  96. expected("miu+"));
  97. test_geometry<ls, poly>("LINESTRING(0 1,1 1.0012195839797347,0 1)",
  98. "POLYGON((0 0,3 3,3 0,0 0))",
  99. expected("muu+"));
  100. test_geometry<ls, poly>("LINESTRING(0 1,3 3,0 1)",
  101. "POLYGON((0 0,3 3,3 0,0 0))",
  102. expected("tuu+"));
  103. test_geometry<ls, poly>("LINESTRING(0 1,0 0,0 1)",
  104. "POLYGON((0 0,3 3,3 0,0 0))",
  105. expected("tuu+"));
  106. // SPIKE - NON-ENDPOINT - OPPOSITE
  107. // opposite - eq eq
  108. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2.0036594926050877)",
  109. "POLYGON((-1 -1,0 0,4 4,6 3,-1 -1))",
  110. expected("tcu+")("txc=")("tcc=")("mxu="));
  111. // opposite - neq eq
  112. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2.0036594926050877)",
  113. "POLYGON((-1 -1,0 0,5 4.9931712414532354,6 3,-1 -1))",
  114. expected("mcu+")("txc=")("tcc=")("mxu="));
  115. // opposite - eq, neq
  116. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2.0036594926050877)",
  117. "POLYGON((-2 -2,-1 -1.0022887548647628,4 4,6 3,-2 -2))",
  118. expected("tcu+")("mxc=")("mcc=")("mxu="));
  119. // opposite - neq neq
  120. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2.0036594926050877)",
  121. "POLYGON((-2 -2,-1 -1.0022887548647628,3 3.0031983963093536,6 3,-2 -2))",
  122. expected("mcu+")("mxc=")("mcc=")("mxu="));
  123. // opposite - neq neq
  124. test_geometry<ls, poly>("LINESTRING(6 6,4 4,0 0,2 2.0036594926050877)",
  125. "POLYGON((-2 -2,-1 -1.0022887548647628,3 3.0031983963093536,5 4.9931712414532354,6 3,-2 -2))",
  126. expected("mcu+")("mxc=")("mcc=")("mxu="));
  127. // spike vs internal
  128. test_geometry<ls, poly>("LINESTRING(0 1,1 1,0 1)", // --
  129. "POLYGON((1 0,1 1,2 1,1 0))",
  130. expected("tuu+"));
  131. test_geometry<ls, poly>("LINESTRING(1 2,1 1,1 2)", // |
  132. "POLYGON((1 0,1 1,2 1,1 0))",
  133. expected("tuu+"));
  134. test_geometry<ls, poly>("LINESTRING(0 2,1 1,0 2)", // \ (avoid multi-line comment)
  135. "POLYGON((1 0,1 1,2 1,1 0))",
  136. expected("tuu+"));
  137. test_geometry<ls, poly>("LINESTRING(2 0,1 1,2 0)", // \ (avoid multi-line comment)
  138. "POLYGON((1 0,1 1,2 1,2 0,1 0))",
  139. expected("tiu+")("tiu+")("txu+")); // TODO: should spike point be duplicated?
  140. test_geometry<ls, poly>("LINESTRING(0 0,1 1,0 0)", // /
  141. "POLYGON((1 0,1 1,2 1,1 0))",
  142. expected("tuu+"));
  143. test_geometry<ls, poly>("LINESTRING(2 2,1 1,2 2)", // /
  144. "POLYGON((1 0,1 1,2 1,1 0))",
  145. expected("tuu+"));
  146. test_geometry<ls, poly>("LINESTRING(2 1,1 1,2 1)", // --
  147. "POLYGON((1 0,1 1,2 1,1 0))",
  148. expected("tcu+")("txc=")("tcc=")("txu="));
  149. // 21.01.2015
  150. test_geometry<ls, poly>("LINESTRING(1 2.9977189008308085,3 1.0004570537241195)",
  151. "POLYGON((0 0,0 4,4 4,4 0,2 2,0 0))",
  152. expected("mcu+")("mxc="));
  153. // extended
  154. test_geometry<ls, poly>("LINESTRING(1 6.9651356719477091,4 4,7 1.0022887548647630)",
  155. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  156. expected("tcu+")("mxc="));
  157. test_geometry<ls, poly>("LINESTRING(1 6.9651356719477091,3 4.9931712414532363,7 1.0022887548647630)",
  158. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  159. expected("mcu+")("mxc="));
  160. test_geometry<ls, poly>("LINESTRING(1 6.9651356719477091,5 3.0031983963093536,7 1.0022887548647630)",
  161. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  162. expected("mcu+")("mxc="));
  163. test_geometry<ls, poly>("LINESTRING(4 4,7 1.0022887548647630)",
  164. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  165. expected("tcu+")("mxc="));
  166. test_geometry<ls, poly>("LINESTRING(5 3.0031983963093536,7 1.0022887548647630)",
  167. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  168. expected("mcu+")("mxc="));
  169. // reversed
  170. test_geometry<ls, poly>("LINESTRING(7 1.0022887548647630,4 4,1 6.9651356719477091)",
  171. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  172. expected("mcc+")("tiu="));
  173. test_geometry<ls, poly>("LINESTRING(7 1.0022887548647630,3 4.9931712414532363,1 6.9651356719477091)",
  174. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  175. expected("mcc+")("miu="));
  176. test_geometry<ls, poly>("LINESTRING(7 1.0022887548647630,5 3.0031983963093536,1 6.9651356719477091)",
  177. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  178. expected("mcc+")("ccc=")("miu="));
  179. test_geometry<ls, poly>("LINESTRING(7 1.0022887548647630,4 4)",
  180. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  181. expected("mcc+")("txu="));
  182. test_geometry<ls, poly>("LINESTRING(7 1.0022887548647630,5 3.0031983963093536)",
  183. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  184. expected("mcc+")("mxu="));
  185. test_geometry<ls, poly>("LINESTRING(7 1.0022887548647630,3 4.9931712414532363)",
  186. "POLYGON((0 0,0 8,8 8,8 0,4 4,0 0))",
  187. expected("mcc+")("miu="));
  188. // 23.01.2015 - spikes
  189. test_geometry<ls, poly>("LINESTRING(3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 1.7773315888299086)",
  190. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  191. expected("miu+")("miu+")("miu+")("mxu+"));
  192. test_geometry<ls, poly>("LINESTRING(7 8, 6 10.035925377760330, 11 -0.31552621163523403)",
  193. "POLYGON((0 0,0 10,10 10,10 0,0 0))",
  194. expected("miu+")("iuu+"));
  195. // 25.01.2015
  196. test_geometry<ls, poly>("LINESTRING(2 3, 4 5, 0 5.9782377228588262, 5 6.0009072995372446)",
  197. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))",
  198. expected("miu+")("miu+")("mcu+")("mxc="));
  199. test_geometry<ls, poly>("LINESTRING(0 5.9782377228588262, 5 6.0009072995372446)",
  200. "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))",
  201. expected("miu+")("mcu+")("mxc="));
  202. }
  203. int test_main(int, char* [])
  204. {
  205. test_all<float>();
  206. test_all<double>();
  207. //#if ! defined(_MSC_VER)
  208. // test_all<long double>();
  209. //#endif
  210. //#if defined(HAVE_TTMATH)
  211. // test_all<ttmath_big>();
  212. //#endif
  213. return 0;
  214. }