9
3

is_valid.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/is_valid.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 Geometry>
  15. void test(Geometry const& geometry, bool expected_value)
  16. {
  17. bool value = bgi::detail::is_valid(geometry);
  18. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  19. std::ostringstream out;
  20. out << typeid(typename bg::coordinate_type<Geometry>::type).name()
  21. << " "
  22. << typeid(bool).name()
  23. << " "
  24. << "is_valid : " << value
  25. << std::endl;
  26. std::cout << out.str();
  27. #endif
  28. BOOST_CHECK(value == expected_value);
  29. }
  30. template <typename Box>
  31. void test_box(std::string const& wkt, bool expected_value)
  32. {
  33. Box box;
  34. bg::read_wkt(wkt, box);
  35. test(box, expected_value);
  36. typename bg::point_type<Box>::type temp_pt;
  37. temp_pt = box.min_corner();
  38. box.min_corner() = box.max_corner();
  39. box.max_corner() = temp_pt;
  40. test(box, !expected_value);
  41. }
  42. void test_large_integers()
  43. {
  44. typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type;
  45. typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type;
  46. bg::model::box<int_point_type> int_box;
  47. bg::model::box<double_point_type> double_box;
  48. std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))";
  49. bg::read_wkt(box_li, int_box);
  50. bg::read_wkt(box_li, double_box);
  51. BOOST_CHECK(bgi::detail::is_valid(int_box) == bgi::detail::is_valid(double_box));
  52. std::string const box_li2 = "POLYGON((1872000 528000, 1536119 192000))";
  53. bg::read_wkt(box_li2, int_box);
  54. bg::read_wkt(box_li2, double_box);
  55. BOOST_CHECK(bgi::detail::is_valid(int_box) == bgi::detail::is_valid(double_box));
  56. }
  57. int test_main(int, char* [])
  58. {
  59. typedef bg::model::point<int, 2, bg::cs::cartesian> P2ic;
  60. typedef bg::model::point<float, 2, bg::cs::cartesian> P2fc;
  61. typedef bg::model::point<double, 2, bg::cs::cartesian> P2dc;
  62. typedef bg::model::point<int, 3, bg::cs::cartesian> P3ic;
  63. typedef bg::model::point<float, 3, bg::cs::cartesian> P3fc;
  64. typedef bg::model::point<double, 3, bg::cs::cartesian> P3dc;
  65. test(P2ic(0, 0), true);
  66. test(P2fc(0, 0), true);
  67. test(P2dc(0, 0), true);
  68. test(P3ic(0, 0, 0), true);
  69. test(P3fc(0, 0, 0), true);
  70. test(P3dc(0, 0, 0), true);
  71. test_box<bg::model::box<P2ic> >("POLYGON((0 1,2 4))", true);
  72. test_box<bg::model::box<P2fc> >("POLYGON((0 1,2 4))", true);
  73. test_box<bg::model::box<P2dc> >("POLYGON((0 1,2 4))", true);
  74. test_box<bg::model::box<P3ic> >("POLYGON((0 1 2,2 4 6))", true);
  75. test_box<bg::model::box<P3fc> >("POLYGON((0 1 2,2 4 6))", true);
  76. test_box<bg::model::box<P3dc> >("POLYGON((0 1 2,2 4 6))", true);
  77. #ifdef HAVE_TTMATH
  78. typedef bg::model::point<ttmath_big, 2, bg::cs::cartesian> P2ttmc;
  79. typedef bg::model::point<ttmath_big, 3, bg::cs::cartesian> P3ttmc;
  80. test_geometry<bg::model::box<P2ttmc> >("POLYGON((0 1,2 4))", true);
  81. test_geometry<bg::model::box<P3ttmc> >("POLYGON((0 1 2,2 4 6))", true);
  82. #endif
  83. test_large_integers();
  84. return 0;
  85. }