/Src/Dependencies/Boost/libs/geometry/test/algorithms/overlay/robustness/star_comb.cpp

http://hadesmem.googlecode.com/ · C++ · 157 lines · 122 code · 28 blank · 7 comment · 8 complexity · 0bc8fae1364e0706bc333b8f00bdd720 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2009-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 <sstream>
  9. #include <fstream>
  10. #include <iomanip>
  11. #include <string>
  12. #define BOOST_GEOMETRY_REPORT_OVERLAY_ERROR
  13. #define BOOST_GEOMETRY_NO_BOOST_TEST
  14. #define BOOST_GEOMETRY_TIME_OVERLAY
  15. #include <boost/program_options.hpp>
  16. #include <boost/random/linear_congruential.hpp>
  17. #include <boost/random/uniform_int.hpp>
  18. #include <boost/random/uniform_real.hpp>
  19. #include <boost/random/variate_generator.hpp>
  20. #include <boost/timer.hpp>
  21. #include <star_comb.hpp>
  22. #include <test_overlay_p_q.hpp>
  23. #include <boost/geometry/geometry.hpp>
  24. #include <boost/geometry/multi/multi.hpp>
  25. #include <boost/geometry/geometries/point_xy.hpp>
  26. #include <boost/geometry/multi/geometries/multi_polygon.hpp>
  27. #include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
  28. #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
  29. template <typename Polygon>
  30. void add(Polygon& polygon, double x, double y, int)
  31. {
  32. typedef typename boost::geometry::point_type<Polygon>::type p;
  33. boost::geometry::exterior_ring(polygon).push_back(boost::geometry::make<p>(x, y));
  34. }
  35. template <typename Polygon>
  36. void test_star_comb(int star_point_count, int comb_comb_count, double factor1, double factor2, bool do_union, p_q_settings const& settings)
  37. {
  38. Polygon star, comb;
  39. make_star(star, add<Polygon>, star_point_count, factor1, factor2);
  40. make_comb(comb, add<Polygon>, comb_comb_count);
  41. std::ostringstream out;
  42. out << "star_comb";
  43. test_overlay_p_q
  44. <
  45. Polygon,
  46. typename bg::coordinate_type<Polygon>::type
  47. >(out.str(), star, comb, settings);
  48. }
  49. template <typename T, bool Clockwise, bool Closed>
  50. void test_all(int count, int star_point_count, int comb_comb_count, double factor1, double factor2, bool do_union, p_q_settings const& settings)
  51. {
  52. boost::timer t;
  53. typedef bg::model::polygon
  54. <
  55. bg::model::d2::point_xy<T>, Clockwise, Closed
  56. > polygon;
  57. int index = 0;
  58. for(int i = 0; i < count; i++)
  59. {
  60. test_star_comb<polygon>(star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
  61. }
  62. std::cout
  63. << " type: " << string_from_type<T>::name()
  64. << " time: " << t.elapsed() << std::endl;
  65. }
  66. int main(int argc, char** argv)
  67. {
  68. try
  69. {
  70. namespace po = boost::program_options;
  71. po::options_description description("=== star_comb ===\nAllowed options");
  72. int count = 1;
  73. bool do_union = false;
  74. bool ccw = false;
  75. bool open = false;
  76. double factor1 = 1.1;
  77. double factor2 = 0.2;
  78. int point_count = 50;
  79. p_q_settings settings;
  80. description.add_options()
  81. ("help", "Help message")
  82. ("count", po::value<int>(&count)->default_value(1), "Number of tests")
  83. ("point_count", po::value<int>(&point_count)->default_value(1), "Number of points in the star")
  84. ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
  85. ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
  86. ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
  87. ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
  88. ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
  89. ;
  90. po::variables_map varmap;
  91. po::store(po::parse_command_line(argc, argv, description), varmap);
  92. po::notify(varmap);
  93. if (varmap.count("help"))
  94. {
  95. std::cout << description << std::endl;
  96. return 1;
  97. }
  98. int star_point_count = point_count * 2 + 1;
  99. int comb_comb_count = point_count;
  100. if (ccw && open)
  101. {
  102. test_all<double, false, false>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
  103. }
  104. else if (ccw)
  105. {
  106. test_all<double, false, true>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
  107. }
  108. else if (open)
  109. {
  110. test_all<double, true, false>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
  111. }
  112. else
  113. {
  114. test_all<double, true, true>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
  115. }
  116. #if defined(HAVE_TTMATH)
  117. // test_all<ttmath_big, true, true>(seed, count, max, svg, level);
  118. #endif
  119. }
  120. catch(std::exception const& e)
  121. {
  122. std::cout << "Exception " << e.what() << std::endl;
  123. }
  124. catch(...)
  125. {
  126. std::cout << "Other exception" << std::endl;
  127. }
  128. return 0;
  129. }