box_view.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2010-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. #include <algorithm>
  8. #include <iterator>
  9. #include <sstream>
  10. #include <string>
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/geometries/geometries.hpp>
  13. #include <boost/geometry/geometries/point_xy.hpp>
  14. #include <boost/geometry/views/box_view.hpp>
  15. #include <boost/geometry/io/wkt/read.hpp>
  16. template <typename Box, bool Reverse>
  17. void test_geometry(std::string const& wkt, std::string const& expected,
  18. bg::order_selector expected_order)
  19. {
  20. Box box;
  21. bg::read_wkt(wkt, box);
  22. typedef bg::box_view<Box, Reverse> view_type;
  23. view_type range(box);
  24. {
  25. std::ostringstream out;
  26. for (typename boost::range_iterator<view_type>::type it = boost::begin(range);
  27. it != boost::end(range); ++it)
  28. {
  29. out << " " << bg::get<0>(*it) << bg::get<1>(*it);
  30. }
  31. BOOST_CHECK_EQUAL(out.str(), expected);
  32. }
  33. {
  34. // Check forward/backward behaviour
  35. typename boost::range_iterator<view_type>::type it = boost::begin(range);
  36. it++;
  37. it--;
  38. // Not verified further, same as segment
  39. }
  40. {
  41. // Check random access behaviour
  42. int const n = boost::size(range);
  43. BOOST_CHECK_EQUAL(n, 5);
  44. }
  45. // Check Boost.Range concept
  46. BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept<view_type>) );
  47. // Check order
  48. bg::order_selector order = bg::point_order<view_type>::value;
  49. BOOST_CHECK_EQUAL(order, expected_order);
  50. }
  51. template <typename P>
  52. void test_all()
  53. {
  54. test_geometry<bg::model::box<P>, true> ("polygon((1 1,2 2))", " 11 12 22 21 11", bg::clockwise);
  55. test_geometry<bg::model::box<P>, false>("polygon((1 1,2 2))", " 11 21 22 12 11", bg::counterclockwise);
  56. test_geometry<bg::model::box<P>, true> ("polygon((3 3,5 5))", " 33 35 55 53 33", bg::clockwise);
  57. }
  58. int test_main(int, char* [])
  59. {
  60. test_all<bg::model::d2::point_xy<double> >();
  61. return 0;
  62. }