interior_triangles.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #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 <test_overlay_p_q.hpp>
  16. #include <boost/program_options.hpp>
  17. #include <boost/random/linear_congruential.hpp>
  18. #include <boost/random/uniform_int.hpp>
  19. #include <boost/random/uniform_real.hpp>
  20. #include <boost/random/variate_generator.hpp>
  21. #include <boost/timer.hpp>
  22. template <typename Polygon>
  23. inline void make_polygon(Polygon& polygon, int count_x, int count_y, int index, int offset)
  24. {
  25. typedef typename bg::point_type<Polygon>::type point_type;
  26. bg::exterior_ring(polygon).push_back(point_type(0, 0));
  27. bg::exterior_ring(polygon).push_back(point_type(0, count_y * 10));
  28. bg::exterior_ring(polygon).push_back(point_type(count_x * 10 + 10, count_y * 10));
  29. bg::exterior_ring(polygon).push_back(point_type(count_x * 10 + 10, 0));
  30. bg::exterior_ring(polygon).push_back(point_type(0, 0));
  31. for(int j = 0; j < count_x; ++j)
  32. {
  33. for(int k = 0; k < count_y; ++k)
  34. {
  35. polygon.inners().push_back(typename Polygon::inner_container_type::value_type());
  36. polygon.inners().back().push_back(point_type(offset + j * 10 + 1, k * 10 + 1));
  37. polygon.inners().back().push_back(point_type(offset + j * 10 + 7, k * 10 + 5 + index));
  38. polygon.inners().back().push_back(point_type(offset + j * 10 + 5 + index, k * 10 + 7));
  39. polygon.inners().back().push_back(point_type(offset + j * 10 + 1, k * 10 + 1));
  40. }
  41. }
  42. bg::correct(polygon);
  43. }
  44. template <typename Polygon>
  45. void test_star_comb(int count_x, int count_y, int offset, p_q_settings const& settings)
  46. {
  47. Polygon p, q;
  48. make_polygon(p, count_x, count_y, 0, 0);
  49. make_polygon(q, count_x, count_y, 1, offset);
  50. std::ostringstream out;
  51. out << "interior_triangles";
  52. test_overlay_p_q
  53. <
  54. Polygon,
  55. typename bg::coordinate_type<Polygon>::type
  56. >(out.str(), p, q, settings);
  57. }
  58. template <typename T, bool Clockwise, bool Closed>
  59. void test_all(int count, int count_x, int count_y, int offset, p_q_settings const& settings)
  60. {
  61. boost::timer t;
  62. typedef bg::model::polygon
  63. <
  64. bg::model::d2::point_xy<T>, Clockwise, Closed
  65. > polygon;
  66. for(int i = 0; i < count; i++)
  67. {
  68. test_star_comb<polygon>(count_x, count_y, offset, settings);
  69. }
  70. std::cout
  71. << " type: " << string_from_type<T>::name()
  72. << " time: " << t.elapsed() << std::endl;
  73. }
  74. int main(int argc, char** argv)
  75. {
  76. try
  77. {
  78. namespace po = boost::program_options;
  79. po::options_description description("=== interior_triangles ===\nAllowed options");
  80. int offset = 0;
  81. int count = 1;
  82. int count_x = 10;
  83. int count_y = 10;
  84. bool ccw = false;
  85. bool open = false;
  86. p_q_settings settings;
  87. description.add_options()
  88. ("help", "Help message")
  89. ("count", po::value<int>(&count)->default_value(1), "Number of tests")
  90. ("count_x", po::value<int>(&count_x)->default_value(10), "Triangle count in x-direction")
  91. ("count_y", po::value<int>(&count_y)->default_value(10), "Triangle count in y-direction")
  92. ("offset", po::value<int>(&offset)->default_value(0), "Offset of second triangle in x-direction")
  93. ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
  94. ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
  95. ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
  96. ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
  97. ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
  98. ;
  99. po::variables_map varmap;
  100. po::store(po::parse_command_line(argc, argv, description), varmap);
  101. po::notify(varmap);
  102. if (varmap.count("help"))
  103. {
  104. std::cout << description << std::endl;
  105. return 1;
  106. }
  107. if (ccw && open)
  108. {
  109. test_all<double, false, false>(count, count_x, count_y, offset, settings);
  110. }
  111. else if (ccw)
  112. {
  113. test_all<double, false, true>(count, count_x, count_y, offset, settings);
  114. }
  115. else if (open)
  116. {
  117. test_all<double, true, false>(count, count_x, count_y, offset, settings);
  118. }
  119. else
  120. {
  121. test_all<double, true, true>(count, count_x, count_y, offset, settings);
  122. }
  123. #if defined(HAVE_TTMATH)
  124. // test_all<ttmath_big, true, true>(seed, count, max, svg, level);
  125. #endif
  126. }
  127. catch(std::exception const& e)
  128. {
  129. std::cout << "Exception " << e.what() << std::endl;
  130. }
  131. catch(...)
  132. {
  133. std::cout << "Other exception" << std::endl;
  134. }
  135. return 0;
  136. }