/Src/Dependencies/Boost/libs/geometry/test/algorithms/test_envelope.hpp

http://hadesmem.googlecode.com/ · C++ Header · 107 lines · 77 code · 24 blank · 6 comment · 0 complexity · 1b8f55bb0cb70442d7428c3d567b8f39 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2011 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. #ifndef BOOST_GEOMETRY_TEST_ENVELOPE_HPP
  8. #define BOOST_GEOMETRY_TEST_ENVELOPE_HPP
  9. #include <geometry_test_common.hpp>
  10. #include <boost/geometry/algorithms/envelope.hpp>
  11. #include <boost/geometry/geometries/box.hpp>
  12. #include <boost/geometry/strategies/strategies.hpp>
  13. #include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
  14. template<typename Box, std::size_t DimensionCount>
  15. struct check_result
  16. {};
  17. template <typename Box>
  18. struct check_result<Box, 2>
  19. {
  20. typedef typename bg::coordinate_type<Box>::type ctype;
  21. typedef typename boost::mpl::if_
  22. <
  23. boost::is_arithmetic<ctype>,
  24. double,
  25. ctype
  26. >::type type;
  27. static void apply(Box const& b, const type& x1, const type& y1, const type& z1,
  28. const type& x2, const type& y2, const type& z2)
  29. {
  30. BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
  31. BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
  32. BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
  33. BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
  34. }
  35. };
  36. template <typename Box>
  37. struct check_result<Box, 3>
  38. {
  39. typedef typename bg::coordinate_type<Box>::type ctype;
  40. typedef typename boost::mpl::if_
  41. <
  42. boost::is_arithmetic<ctype>,
  43. double,
  44. ctype
  45. >::type type;
  46. static void apply(Box const& b, const type& x1, const type& y1, const type& z1,
  47. const type& x2, const type& y2, const type& z2)
  48. {
  49. BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
  50. BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
  51. BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 2>(b)), z1, 0.001);
  52. BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
  53. BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
  54. BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 2>(b)), z2, 0.001);
  55. }
  56. };
  57. template <typename Geometry, typename T>
  58. void test_envelope(std::string const& wkt,
  59. const T& x1, const T& x2,
  60. const T& y1, const T& y2,
  61. const T& z1 = 0, const T& z2 = 0)
  62. {
  63. typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
  64. Geometry geometry;
  65. bg::read_wkt(wkt, geometry);
  66. box_type b;
  67. bg::envelope(geometry, b);
  68. check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
  69. }
  70. template <typename Geometry, typename T>
  71. void test_envelope_strategy(std::string const& wkt,
  72. const T& x1, const T& x2,
  73. const T& y1, const T& y2,
  74. const T& z1 = 0, const T& z2 = 0)
  75. {
  76. typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
  77. Geometry geometry;
  78. bg::read_wkt(wkt, geometry);
  79. box_type b;
  80. bg::envelope(geometry, b);
  81. check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
  82. }
  83. #endif