/Src/Dependencies/Boost/libs/geometry/test/algorithms/overlay/relative_order.cpp

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