box.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/algorithms/make.hpp>
  13. #include <boost/geometry/geometries/point.hpp>
  14. #include <boost/geometry/geometries/box.hpp>
  15. #include <boost/geometry/geometries/adapted/c_array.hpp>
  16. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  17. #include <test_common/test_point.hpp>
  18. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
  19. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  20. template <typename P>
  21. bg::model::box<P> create_box()
  22. {
  23. P p1;
  24. P p2;
  25. bg::assign_values(p1, 1, 2, 5);
  26. bg::assign_values(p2, 3, 4, 6);
  27. return bg::model::box<P>(p1, p2);
  28. }
  29. template <typename B, typename T>
  30. void check_box(B& to_check,
  31. T min_x, T min_y, T min_z,
  32. T max_x, T max_y, T max_z)
  33. {
  34. BOOST_CHECK_EQUAL(bg::get<0>(to_check.min_corner()), min_x);
  35. BOOST_CHECK_EQUAL(bg::get<1>(to_check.min_corner()), min_y);
  36. BOOST_CHECK_EQUAL(bg::get<2>(to_check.min_corner()), min_z);
  37. BOOST_CHECK_EQUAL(bg::get<0>(to_check.max_corner()), max_x);
  38. BOOST_CHECK_EQUAL(bg::get<1>(to_check.max_corner()), max_y);
  39. BOOST_CHECK_EQUAL(bg::get<2>(to_check.max_corner()), max_z);
  40. }
  41. template <typename P>
  42. void test_construction()
  43. {
  44. typedef typename bg::coordinate_type<P>::type T;
  45. bg::model::box<P> b1 = bg::make_zero<bg::model::box<P> >();
  46. check_box(b1, T(),T(),T(),T(),T(),T());
  47. bg::model::box<P> b2(create_box<P>());
  48. check_box(b2, 1,2,5,3,4,6);
  49. bg::model::box<P> b3 = bg::make_inverse<bg::model::box<P> >();
  50. check_box(b3, boost::numeric::bounds<T>::highest(),
  51. boost::numeric::bounds<T>::highest(),
  52. boost::numeric::bounds<T>::highest(),
  53. boost::numeric::bounds<T>::lowest(),
  54. boost::numeric::bounds<T>::lowest(),
  55. boost::numeric::bounds<T>::lowest());
  56. }
  57. template <typename P>
  58. void test_assignment()
  59. {
  60. bg::model::box<P> b(create_box<P>());
  61. bg::set<0>(b.min_corner(), 10);
  62. bg::set<1>(b.min_corner(), 20);
  63. bg::set<2>(b.min_corner(), 30);
  64. bg::set<0>(b.max_corner(), 40);
  65. bg::set<1>(b.max_corner(), 50);
  66. bg::set<2>(b.max_corner(), 60);
  67. check_box(b, 10,20,30,40,50,60);
  68. }
  69. template <typename P>
  70. void test_all()
  71. {
  72. test_construction<P>();
  73. test_assignment<P>();
  74. }
  75. int test_main(int, char* [])
  76. {
  77. test_all<int[3]>();
  78. test_all<float[3]>();
  79. test_all<double[3]>();
  80. test_all<test::test_point>();
  81. test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
  82. test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
  83. test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
  84. return 0;
  85. }