rtree_insert_remove.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <rtree/test_rtree.hpp>
  8. #include <boost/geometry/geometries/register/point.hpp>
  9. #include <boost/geometry/geometries/polygon.hpp>
  10. template <typename Params>
  11. void test_rtree(unsigned vcount)
  12. {
  13. typedef bg::model::point<int, 1, bg::cs::cartesian> point_t;
  14. bgi::rtree<point_t, Params> rt;
  15. BOOST_CHECK(rt.remove(point_t(0)) == 0);
  16. for ( unsigned i = 0 ; i < vcount ; ++i )
  17. {
  18. rt.insert(point_t(static_cast<int>(i)));
  19. }
  20. BOOST_CHECK(rt.size() == vcount);
  21. BOOST_CHECK(rt.count(point_t(vcount / 2)) == 1);
  22. for ( unsigned i = 0 ; i < vcount + 3 ; ++i )
  23. {
  24. rt.remove(point_t((i + 3) % vcount));
  25. }
  26. BOOST_CHECK(rt.size() == 0);
  27. BOOST_CHECK(rt.count(point_t(vcount / 2)) == 0);
  28. for ( unsigned i = 0 ; i < vcount ; ++i )
  29. {
  30. rt.insert(point_t((i + 5) % vcount));
  31. }
  32. BOOST_CHECK(rt.size() == vcount);
  33. BOOST_CHECK(rt.count(point_t(vcount / 2)) == 1);
  34. for ( unsigned i = 0 ; i < vcount + 3 ; ++i )
  35. {
  36. rt.remove(point_t((i + 7) % vcount));
  37. }
  38. BOOST_CHECK(rt.size() == 0);
  39. BOOST_CHECK(rt.count(point_t(vcount / 2)) == 0);
  40. }
  41. template <int Max, int Min>
  42. void test_rtree_all()
  43. {
  44. int pow = Max;
  45. for (int l = 0 ; l < 3 ; ++l)
  46. {
  47. pow *= Max;
  48. int vcount = (pow * 8) / 10;
  49. //std::cout << Max << " " << Min << " " << vcount << std::endl;
  50. test_rtree< bgi::linear<Max, Min> >(vcount);
  51. test_rtree< bgi::quadratic<Max, Min> >(vcount);
  52. test_rtree< bgi::rstar<Max, Min> >(vcount);
  53. }
  54. }
  55. int test_main(int, char* [])
  56. {
  57. test_rtree_all<2, 1>();
  58. test_rtree_all<4, 1>();
  59. test_rtree_all<4, 2>();
  60. test_rtree_all<5, 3>();
  61. return 0;
  62. }