star_comb.cpp 4.6 KB

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