relative_order.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2017.
  5. // Modifications copyright (c) 2017, 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 <iostream>
  11. #include <geometry_test_common.hpp>
  12. #include <boost/foreach.hpp>
  13. #include <boost/geometry/algorithms/intersection.hpp>
  14. #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
  15. #include <boost/geometry/algorithms/detail/overlay/get_relative_order.hpp>
  16. #include <boost/geometry/algorithms/make.hpp>
  17. #include <boost/geometry/geometries/point_xy.hpp>
  18. #if defined(TEST_WITH_SVG)
  19. # include <boost/geometry/io/svg/svg_mapper.hpp>
  20. #endif
  21. #include <boost/geometry/strategies/side.hpp>
  22. #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
  23. template <typename P, typename T>
  24. void test_with_point(std::string const& /*caseid*/,
  25. T pi_x, T pi_y, T pj_x, T pj_y,
  26. T ri_x, T ri_y, T rj_x, T rj_y,
  27. T si_x, T si_y, T sj_x, T sj_y,
  28. int expected_order)
  29. {
  30. P pi = bg::make<P>(pi_x, pi_y);
  31. P pj = bg::make<P>(pj_x, pj_y);
  32. P ri = bg::make<P>(ri_x, ri_y);
  33. P rj = bg::make<P>(rj_x, rj_y);
  34. P si = bg::make<P>(si_x, si_y);
  35. P sj = bg::make<P>(sj_x, sj_y);
  36. typedef typename bg::strategy::side::services::default_strategy
  37. <
  38. typename bg::cs_tag<P>::type
  39. >::type strategy_type;
  40. int order = bg::detail::overlay::get_relative_order::apply(pi, pj, ri, rj, si, sj, strategy_type());
  41. BOOST_CHECK_EQUAL(order, expected_order);
  42. /*
  43. std::cout << caseid
  44. << (caseid.find("_") == std::string::npos ? " " : "")
  45. << " " << method
  46. << " " << detected
  47. << " " << order
  48. << std::endl;
  49. */
  50. /*#if defined(TEST_WITH_SVG)
  51. {
  52. std::ostringstream filename;
  53. filename << "get_turn_info_" << caseid
  54. << "_" << string_from_type<typename bg::coordinate_type<P>::type>::name()
  55. << ".svg";
  56. std::ofstream svg(filename.str().c_str());
  57. bg::svg_mapper<P> mapper(svg, 500, 500);
  58. mapper.add(bg::make<P>(0, 0));
  59. mapper.add(bg::make<P>(10, 10));
  60. bg::model::linestring<P> p; p.push_back(pi); p.push_back(pj); p.push_back(pk);
  61. bg::model::linestring<P> q; q.push_back(qi); q.push_back(qj); q.push_back(qk);
  62. mapper.map(p, "opacity:0.8;stroke:rgb(0,192,0);stroke-width:3");
  63. mapper.map(q, "opacity:0.8;stroke:rgb(0,0,255);stroke-width:3");
  64. std::string style = ";font-family='Verdana';font-weight:bold";
  65. std::string align = ";text-anchor:end;text-align:end";
  66. int offset = 8;
  67. mapper.text(pi, "pi", "fill:rgb(0,192,0)" + style, offset, offset);
  68. mapper.text(pj, "pj", "fill:rgb(0,192,0)" + style, offset, offset);
  69. mapper.text(pk, "pk", "fill:rgb(0,192,0)" + style, offset, offset);
  70. mapper.text(qi, "qi", "fill:rgb(0,0,255)" + style + align, -offset, offset);
  71. mapper.text(qj, "qj", "fill:rgb(0,0,255)" + style + align, -offset, offset);
  72. mapper.text(qk, "qk", "fill:rgb(0,0,255)" + style + align, -offset, offset);
  73. int factor = 1; // second info, if any, will go left by factor -1
  74. int ch = '1';
  75. for (typename tp_vector::const_iterator it = info.begin();
  76. it != info.end();
  77. ++it, factor *= -1, ch++)
  78. {
  79. bool at_j = it->method == bg::detail::overlay::method_crosses;
  80. std::string op;
  81. op += operation_char(it->operations[0].operation);
  82. align = ";text-anchor:middle;text-align:center";
  83. mapper.text(at_j ? pj : pk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
  84. op.clear();
  85. op += operation_char(it->operations[1].operation);
  86. mapper.text(at_j ? qj : qk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
  87. // Map intersection point + method
  88. mapper.map(it->point, "opacity:0.8;fill:rgb(255,0,0);stroke:rgb(0,0,100);stroke-width:1");
  89. op.clear();
  90. op += method_char(it->method);
  91. if (info.size() != 1)
  92. {
  93. op += ch;
  94. op += " p:"; op += operation_char(it->operations[0].operation);
  95. op += " q:"; op += operation_char(it->operations[1].operation);
  96. }
  97. mapper.text(it->point, op, "fill:rgb(255,0,0)" + style, offset, -offset);
  98. }
  99. }
  100. #endif
  101. */
  102. }
  103. template <typename P>
  104. void test_all()
  105. {
  106. test_with_point<P, double>("OLR1",
  107. 5, 1, 5, 8, // p
  108. 3, 5, 7, 5, // r
  109. 3, 3, 7, 2, // s
  110. 1);
  111. test_with_point<P, double>("OLR2",
  112. 5, 1, 5, 8, // p
  113. 3, 5, 7, 5, // r
  114. 3, 7, 7, 6, // s
  115. -1);
  116. test_with_point<P, double>("OLR3",
  117. 5, 1, 5, 8, // p
  118. 3, 5, 7, 5, // r
  119. 4, 2, 9, 6, // s
  120. 1);
  121. test_with_point<P, double>("OLR4",
  122. 5, 1, 5, 8, // p
  123. 3, 5, 7, 5, // r
  124. 3, 8, 9, 4, // s
  125. -1);
  126. test_with_point<P, double>("OLR5",
  127. 5, 1, 5, 8, // p
  128. 3, 5, 7, 5, // r
  129. 4, 2, 8, 6, // s
  130. 1);
  131. test_with_point<P, double>("OLR6",
  132. 5, 1, 5, 8, // p
  133. 3, 5, 7, 5, // r
  134. 3, 7, 9, 4, // s
  135. -1);
  136. test_with_point<P, double>("OLR7",
  137. 5, 1, 5, 8, // p
  138. 3, 5, 7, 5, // r
  139. 1, 4, 7, 7, // s
  140. -1);
  141. test_with_point<P, double>("OLR8",
  142. 5, 1, 5, 8, // p
  143. 3, 5, 7, 5, // r
  144. 1, 6, 7, 3, // s
  145. 1);
  146. test_with_point<P, double>("OD1",
  147. 5, 1, 5, 8, // p
  148. 3, 5, 7, 5, // r
  149. 7, 2, 3, 3, // s
  150. 1);
  151. test_with_point<P, double>("OD9",
  152. 5, 1, 5, 8, // p
  153. 3, 5, 7, 5, // r
  154. 7, 5, 3, 3, // s
  155. 1);
  156. test_with_point<P, double>("OD10",
  157. 5, 1, 5, 8, // p
  158. 3, 5, 7, 5, // r
  159. 7, 5, 3, 7, // s
  160. -1);
  161. test_with_point<P, double>("OD11",
  162. 5, 1, 5, 8, // p
  163. 7, 5, 3, 5, // r
  164. 3, 5, 7, 7, // s
  165. -1);
  166. test_with_point<P, double>("OD12",
  167. 5, 1, 5, 8, // p
  168. 7, 5, 3, 5, // r
  169. 3, 5, 7, 3, // s
  170. 1);
  171. }
  172. int test_main(int, char* [])
  173. {
  174. test_all<bg::model::d2::point_xy<double> >();
  175. return 0;
  176. }