minmaxdist.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Boost.Geometry Index
  2. // Unit Test
  3. // Copyright (c) 2011-2013 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 <algorithm>
  8. #include <geometry_index_test_common.hpp>
  9. #include <boost/geometry/index/detail/algorithms/minmaxdist.hpp>
  10. #include <boost/geometry/geometries/point_xy.hpp>
  11. #include <boost/geometry/geometries/point.hpp>
  12. #include <boost/geometry/geometries/box.hpp>
  13. #define BOOST_GEOMETRY_TEST_DEBUG
  14. template <typename Point, typename Indexable>
  15. void test(Point const& pt, Indexable const& indexable,
  16. typename bg::default_distance_result<Point, Indexable>::type expected_value)
  17. {
  18. typename bg::default_distance_result<Point, Indexable>::type value = bgi::detail::minmaxdist(pt, indexable);
  19. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  20. std::ostringstream out;
  21. out << typeid(typename bg::coordinate_type<Point>::type).name()
  22. << " "
  23. << typeid(typename bg::coordinate_type<Indexable>::type).name()
  24. << " "
  25. << typeid(bg::default_distance_result<Point, Indexable>::type).name()
  26. << " "
  27. << "minmaxdist : " << value
  28. << std::endl;
  29. std::cout << out.str();
  30. #endif
  31. BOOST_CHECK_CLOSE(value, expected_value, 0.0001);
  32. }
  33. template <typename Indexable, typename Point>
  34. void test_indexable(Point const& pt, std::string const& wkt,
  35. typename bg::default_distance_result<Point, Indexable>::type expected_value)
  36. {
  37. Indexable indexable;
  38. bg::read_wkt(wkt, indexable);
  39. test(pt, indexable, expected_value);
  40. }
  41. void test_large_integers()
  42. {
  43. typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type;
  44. typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type;
  45. int_point_type int_pt(0, 0);
  46. double_point_type double_pt(0, 0);
  47. bg::model::box<int_point_type> int_box;
  48. bg::model::box<double_point_type> double_box;
  49. std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))";
  50. bg::read_wkt(box_li, int_box);
  51. bg::read_wkt(box_li, double_box);
  52. BOOST_CHECK(bgi::detail::minmaxdist(int_pt, int_box) == bgi::detail::minmaxdist(double_pt, double_box));
  53. }
  54. int test_main(int, char* [])
  55. {
  56. typedef bg::model::point<int, 2, bg::cs::cartesian> P2ic;
  57. typedef bg::model::point<float, 2, bg::cs::cartesian> P2fc;
  58. typedef bg::model::point<double, 2, bg::cs::cartesian> P2dc;
  59. typedef bg::model::point<int, 3, bg::cs::cartesian> P3ic;
  60. typedef bg::model::point<float, 3, bg::cs::cartesian> P3fc;
  61. typedef bg::model::point<double, 3, bg::cs::cartesian> P3dc;
  62. test_indexable<bg::model::box<P2ic> >(P2ic(1, 2), "POLYGON((0 1,2 4))", 5.0);
  63. test_indexable<bg::model::box<P2fc> >(P2fc(1, 2), "POLYGON((0 1,2 4))", 5.0);
  64. test_indexable<bg::model::box<P2dc> >(P2dc(1, 2), "POLYGON((0 1,2 4))", 5.0);
  65. test_indexable<bg::model::box<P3ic> >(P3ic(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
  66. test_indexable<bg::model::box<P3fc> >(P3fc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
  67. test_indexable<bg::model::box<P3dc> >(P3dc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
  68. test_indexable<bg::model::box<P2ic> >(P2ic(1, 2), "POLYGON((1 2,3 5))", 4.0);
  69. #ifdef HAVE_TTMATH
  70. typedef bg::model::point<ttmath_big, 2, bg::cs::cartesian> P2ttmc;
  71. typedef bg::model::point<ttmath_big, 3, bg::cs::cartesian> P3ttmc;
  72. test_indexable<bg::model::box<P2ttmc> >(P2ttmc(1, 2), "POLYGON((0 1,2 4))", 5.0);
  73. test_indexable<bg::model::box<P3ttmc> >(P3ttmc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
  74. #endif
  75. test_large_integers();
  76. return 0;
  77. }