test_envelope.hpp 3.0 KB

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