winding.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2014, 2016.
  5. // Modifications copyright (c) 2014-2016 Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include <strategies/test_within.hpp>
  11. template <typename Point>
  12. void test_cartesian()
  13. {
  14. typedef bg::model::polygon<Point> polygon;
  15. std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))";
  16. std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))";
  17. std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))";
  18. bg::strategy::within::winding<Point> s;
  19. test_geometry<Point, polygon>("b1", "POINT(1 1)", box, s, true);
  20. test_geometry<Point, polygon>("b2", "POINT(3 3)", box, s, false);
  21. // Test ALL corners (officialy false but some strategies might answer true)
  22. test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, s, false);
  23. test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, s, false);
  24. test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, s, false);
  25. test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, s, false);
  26. // Test ALL sides (officialy false but some strategies might answer true)
  27. test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, s, false);
  28. test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, s, false);
  29. test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, s, false);
  30. test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, s, false);
  31. test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, s, true);
  32. test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, s, false);
  33. test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, s, false);
  34. test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, s, false);
  35. test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, s, false);
  36. test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, s, false);
  37. test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, s, false);
  38. test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, s, false);
  39. test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, s, true);
  40. test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, s, false);
  41. test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, s, false);
  42. test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, s, false);
  43. test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, s, false);
  44. test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, s, false);
  45. test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, s, false);
  46. test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, s, false);
  47. // Lying ON (one of the sides of) interior ring
  48. test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)",
  49. "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))",
  50. s, false);
  51. }
  52. template <typename T>
  53. void test_spherical()
  54. {
  55. typedef bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::degree> > point;
  56. typedef bg::model::polygon<point> polygon;
  57. bg::strategy::within::winding<point> s;
  58. // Ticket #9354
  59. test_geometry<point, polygon>(
  60. "#9354",
  61. "POINT(-78.1239 25.9556)",
  62. "POLYGON((-97.08466667 25.95683333, -97.13683333 25.954, -97.1 26, -97.08466667 25.95683333))",
  63. s,
  64. false);
  65. test_geometry<point, polygon>(
  66. "sph1N",
  67. "POINT(0 10.001)",
  68. "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
  69. s,
  70. bg::strategy::side::spherical_side_formula<>::apply(
  71. point(-10, 10),
  72. point(10, 10),
  73. point(0, (T)10.001)) == -1 // right side
  74. /*true*/);
  75. test_geometry<point, polygon>(
  76. "sph1S",
  77. "POINT(0 -10.001)",
  78. "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
  79. s,
  80. bg::strategy::side::spherical_side_formula<>::apply(
  81. point(10, -10),
  82. point(-10, -10),
  83. point(0, (T)-10.001)) == -1 // right side
  84. /*true*/);
  85. test_geometry<point, polygon>(
  86. "sph2S",
  87. "POINT(0 10.001)",
  88. "POLYGON((-10 20, 10 20, 10 10, -10 10, -10 20))",
  89. s,
  90. bg::strategy::side::spherical_side_formula<>::apply(
  91. point(10, 10),
  92. point(-10, 10),
  93. point(0, (T)10.001)) == -1 // right side
  94. /*false*/);
  95. test_geometry<point, polygon>(
  96. "sph3N",
  97. "POINT(0 10)",
  98. "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
  99. s,
  100. bg::strategy::side::spherical_side_formula<>::apply(
  101. point(-10, 10),
  102. point(10, 10),
  103. point(0, (T)10.001)) == -1 // right side
  104. /*true*/);
  105. test_geometry<point, polygon>(
  106. "sph3S",
  107. "POINT(0 -10)",
  108. "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))",
  109. s,
  110. bg::strategy::side::spherical_side_formula<>::apply(
  111. point(10, -10),
  112. point(-10, -10),
  113. point(0, (T)-10.001)) == -1 // right side
  114. /*true*/);
  115. test_geometry<point, polygon>(
  116. "sphEq1",
  117. "POINT(179 10)",
  118. "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
  119. s,
  120. true,
  121. false);
  122. test_geometry<point, polygon>(
  123. "sphEq2",
  124. "POINT(179 10)",
  125. "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
  126. s,
  127. false,
  128. false);
  129. test_geometry<point, polygon>(
  130. "sphEq3",
  131. "POINT(-179 10)",
  132. "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
  133. s,
  134. true,
  135. false);
  136. test_geometry<point, polygon>(
  137. "sphEq4",
  138. "POINT(-179 10)",
  139. "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
  140. s,
  141. false,
  142. false);
  143. test_geometry<point, polygon>(
  144. "sphEq5",
  145. "POINT(169 10)",
  146. "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
  147. s,
  148. false,
  149. false);
  150. test_geometry<point, polygon>(
  151. "sphEq6",
  152. "POINT(-169 10)",
  153. "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))",
  154. s,
  155. false,
  156. false);
  157. test_geometry<point, polygon>(
  158. "sphEq7",
  159. "POINT(169 10)",
  160. "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
  161. s,
  162. false,
  163. false);
  164. test_geometry<point, polygon>(
  165. "sphEq8",
  166. "POINT(-169 10)",
  167. "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))",
  168. s,
  169. false,
  170. false);
  171. }
  172. int test_main(int, char* [])
  173. {
  174. test_cartesian<bg::model::point<float, 2, bg::cs::cartesian> >();
  175. test_cartesian<bg::model::point<double, 2, bg::cs::cartesian> >();
  176. test_spherical<float>();
  177. test_spherical<double>();
  178. #if defined(HAVE_TTMATH)
  179. test_cartesian<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
  180. test_spherical<ttmath_big>();
  181. #endif
  182. return 0;
  183. }