rtree_epsilon.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Boost.Geometry Index
  2. // Unit Test
  3. // Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland.
  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. // Enable enlargement of Values' bounds by epsilon in the rtree
  8. // for Points and Segments
  9. #define BOOST_GEOMETRY_INDEX_EXPERIMENTAL_ENLARGE_BY_EPSILON
  10. #include <vector>
  11. #include <rtree/test_rtree.hpp>
  12. #include <boost/geometry/geometries/register/point.hpp>
  13. #include <boost/geometry/geometries/polygon.hpp>
  14. template <typename Params>
  15. void test_rtree(unsigned vcount)
  16. {
  17. typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
  18. std::vector<point_t> values;
  19. double eps = std::numeric_limits<double>::epsilon();
  20. values.push_back(point_t(eps/2, eps/2));
  21. for ( unsigned i = 1 ; i < vcount ; ++i )
  22. {
  23. values.push_back(point_t(i, i));
  24. }
  25. point_t qpt(0, 0);
  26. BOOST_CHECK(bg::intersects(qpt, values[0]));
  27. {
  28. bgi::rtree<point_t, Params> rt(values);
  29. std::vector<point_t> result;
  30. rt.query(bgi::intersects(qpt), std::back_inserter(result));
  31. BOOST_CHECK(result.size() == 1);
  32. rt.remove(values.begin() + vcount/2, values.end());
  33. result.clear();
  34. rt.query(bgi::intersects(qpt), std::back_inserter(result));
  35. BOOST_CHECK(result.size() == 1);
  36. }
  37. {
  38. bgi::rtree<point_t, Params> rt;
  39. rt.insert(values);
  40. std::vector<point_t> result;
  41. rt.query(bgi::intersects(qpt), std::back_inserter(result));
  42. BOOST_CHECK(result.size() == 1);
  43. rt.remove(values.begin() + vcount/2, values.end());
  44. result.clear();
  45. rt.query(bgi::intersects(qpt), std::back_inserter(result));
  46. BOOST_CHECK(result.size() == 1);
  47. }
  48. }
  49. template <int Max, int Min>
  50. void test_rtree_all()
  51. {
  52. int pow = Max;
  53. for (int l = 0 ; l < 3 ; ++l)
  54. {
  55. pow *= Max;
  56. int vcount = (pow * 8) / 10;
  57. //std::cout << Max << " " << Min << " " << vcount << std::endl;
  58. test_rtree< bgi::linear<Max, Min> >(vcount);
  59. test_rtree< bgi::quadratic<Max, Min> >(vcount);
  60. test_rtree< bgi::rstar<Max, Min> >(vcount);
  61. }
  62. }
  63. int test_main(int, char* [])
  64. {
  65. test_rtree_all<2, 1>();
  66. test_rtree_all<4, 1>();
  67. test_rtree_all<4, 2>();
  68. test_rtree_all<5, 3>();
  69. return 0;
  70. }