enrich_intersection_points.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #error This unit test is not updated for several years
  12. #include <iostream>
  13. #include <geometry_test_common.hpp>
  14. #include <boost/geometry/algorithms/intersection.hpp>
  15. //#include <boost/geometry/algorithms/detail/overlay/get_intersection_points.hpp>
  16. //#include <boost/geometry/algorithms/detail/overlay/merge_intersection_points.hpp>
  17. #include <boost/geometry/algorithms/detail/overlay/enrich_intersection_points.hpp>
  18. #include <boost/geometry/strategies/strategies.hpp>
  19. #define GEOMETRY_TEST_OVERLAY_NOT_REVERSED
  20. #include <boost/algorithm/string/replace.hpp>
  21. #if defined(TEST_WITH_SVG)
  22. # include <boost/geometry/io/svg/svg_mapper.hpp>
  23. #endif
  24. struct test_enrich_intersection_points
  25. {
  26. static inline std::string dir(int d)
  27. {
  28. return d == 0 ? "-" : (d == 1 ? "L" : "R");
  29. }
  30. template <typename G1, typename G2>
  31. static void apply(std::string const& id,
  32. boost::tuple<int, std::string> const& expected_count_and_center,
  33. G1 const& g1, G2 const& g2, double precision)
  34. {
  35. //std::cout << "#" << id << std::endl;
  36. typedef bg::detail::intersection::intersection_point
  37. <typename bg::point_type<G2>::type> ip;
  38. typedef typename boost::range_const_iterator<std::vector<ip> >::type iterator;
  39. std::vector<ip> ips;
  40. bg::get_intersection_points(g1, g2, ips);
  41. bg::merge_intersection_points(ips);
  42. bg::enrich_intersection_points(ips, true);
  43. std::ostringstream out;
  44. out << std::setprecision(2);
  45. bool first = true;
  46. for (iterator it = boost::begin(ips); it != boost::end(ips); ++it, first = false)
  47. {
  48. out << (first ? "" : ",");
  49. for (unsigned int i = 0; i < it->info.size(); i++)
  50. {
  51. out << dir(it->info[i].direction);
  52. }
  53. }
  54. int n = boost::size(ips);
  55. //std::cout << n << " " << out.str() << std::endl;
  56. BOOST_CHECK_EQUAL(expected_count_and_center.get<0>(), n);
  57. BOOST_CHECK_EQUAL(expected_count_and_center.get<1>(), out.str());
  58. #if defined(TEST_WITH_SVG)
  59. {
  60. std::ostringstream filename;
  61. filename << "enrich_ip" << id << ".svg";
  62. std::ofstream svg(filename.str().c_str());
  63. bg::svg_mapper<typename bg::point_type<G2>::type> mapper(svg, 500, 500);
  64. mapper.add(g1);
  65. mapper.add(g2);
  66. mapper.map(g1, "fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");
  67. mapper.map(g2, "opacity:0.8;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");
  68. for (iterator it = boost::begin(ips); it != boost::end(ips); ++it)
  69. {
  70. mapper.map(it->point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
  71. }
  72. }
  73. #endif
  74. }
  75. };
  76. int test_main(int, char* [])
  77. {
  78. std::vector<boost::tuple<int, std::string> > expected;
  79. /*
  80. TODO Will be refactored
  81. // NOTE: the order is sometimes not really important, in GCC it is sometimes
  82. // different from here...
  83. // 1-6
  84. expected.push_back(boost::make_tuple(6, "RL,LR,LR,RL,RL,LR"));
  85. expected.push_back(boost::make_tuple(8, "RL,LR,LR,RL,RL,LR,LR,RL"));
  86. expected.push_back(boost::make_tuple(4, "RLRR,RRRL,RRRL,RRRL"));
  87. expected.push_back(boost::make_tuple(12, "RL,LR,RL,LR,LR,RL,RL,LR,LR,RL,LR,RL"));
  88. expected.push_back(boost::make_tuple(17, "LR,RL,LR,RRLR,RL,LR,RL,RL,LR,LR,RL,LR,RL,RL,LR,RL,LR"));
  89. expected.push_back(boost::make_tuple(2, "--RR,LR"));
  90. // 7-12
  91. expected.push_back(boost::make_tuple(2, "LL,LL"));
  92. expected.push_back(boost::make_tuple(2, "RL--,LL--"));
  93. expected.push_back(boost::make_tuple(1, "RLLL"));
  94. expected.push_back(boost::make_tuple(2, "RL--,LL--"));
  95. expected.push_back(boost::make_tuple(1, "RRLR"));
  96. expected.push_back(boost::make_tuple(8, "RL,LR,RL,LR,RL,LR,RL,LR"));
  97. // 13-18
  98. expected.push_back(boost::make_tuple(2, "LL--,LL--"));
  99. expected.push_back(boost::make_tuple(2, "RL--,LL--"));
  100. expected.push_back(boost::make_tuple(2, "RL--,LL--"));
  101. expected.push_back(boost::make_tuple(2, "LL,--RL"));
  102. expected.push_back(boost::make_tuple(2, "RR--,--LR"));
  103. expected.push_back(boost::make_tuple(2, "RR--,--LR"));
  104. // 19-24
  105. expected.push_back(boost::make_tuple(2, "LL,LL"));
  106. expected.push_back(boost::make_tuple(0, ""));
  107. expected.push_back(boost::make_tuple(0, ""));
  108. expected.push_back(boost::make_tuple(1, "RLLLRRLR"));
  109. expected.push_back(boost::make_tuple(2, "RL,RLRRRRLR"));
  110. expected.push_back(boost::make_tuple(1, "LRRRRRLR"));
  111. // 25-30
  112. expected.push_back(boost::make_tuple(1, "LRRRLLRL"));
  113. expected.push_back(boost::make_tuple(1, "LRLLLLLR"));
  114. expected.push_back(boost::make_tuple(2, "LR,LRRRRRRL"));
  115. expected.push_back(boost::make_tuple(2, "LR,LRLLRRLR"));
  116. expected.push_back(boost::make_tuple(2, "RL,LRRRLLLR"));
  117. expected.push_back(boost::make_tuple(2, "LR,LRLLLLRL"));
  118. // 31-36
  119. expected.push_back(boost::make_tuple(1, "--LLLL--"));
  120. expected.push_back(boost::make_tuple(1, "LR--LLRL"));
  121. expected.push_back(boost::make_tuple(1, "LRLLLL--"));
  122. expected.push_back(boost::make_tuple(2, "LR,LRLLRR--"));
  123. expected.push_back(boost::make_tuple(1, "LRLLRRLR"));
  124. expected.push_back(boost::make_tuple(3, "RL,LR,RLLLRRLR"));
  125. // 37-42
  126. expected.push_back(boost::make_tuple(3, "LRRRRRLR,RL,LR"));
  127. expected.push_back(boost::make_tuple(3, "LR--RRRL,LR,RL"));
  128. expected.push_back(boost::make_tuple(3, "RL,LR,LRRRRRRL"));
  129. // 43-48
  130. expected.push_back(boost::make_tuple(4, "LR,RL,RL,LR"));
  131. // 49
  132. expected.push_back(boost::make_tuple(16, "--RL,RRLR,RRLR,RL,LLRL,RLLLRRLR,RR--,--LR,RLRR,--LL,RL--,RL,RRRL,RL,LR,RRRLRRRL"));
  133. // 101
  134. expected.push_back(boost::make_tuple(3, "RL,LR,RL"));
  135. // ticket#17
  136. expected.push_back(boost::make_tuple(6, "LR,RL,LR,RL,RL,LR"));
  137. //test_all<bg::model::d2::point_xy<float>, test_enrich_intersection_points>(expected);
  138. test_all<bg::model::d2::point_xy<double>, test_enrich_intersection_points>(expected);
  139. //test_all<boost::tuple<double, double>, test_enrich_intersection_points>(expected);
  140. */
  141. return 0;
  142. }