linestring_concept.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2011-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 <deque>
  8. #include <vector>
  9. #include <geometry_test_common.hpp>
  10. #include <boost/geometry/algorithms/append.hpp>
  11. #include <boost/geometry/algorithms/clear.hpp>
  12. #include <boost/geometry/algorithms/make.hpp>
  13. #include <boost/geometry/core/access.hpp>
  14. #include <boost/geometry/geometries/geometries.hpp>
  15. #include <boost/geometry/geometries/concepts/linestring_concept.hpp>
  16. #include <boost/geometry/io/dsv/write.hpp>
  17. #include <test_common/test_point.hpp>
  18. #include <test_geometries/all_custom_linestring.hpp>
  19. #include <test_geometries/wrapped_boost_array.hpp>
  20. template <typename Geometry>
  21. void test_linestring()
  22. {
  23. BOOST_CONCEPT_ASSERT( (bg::concepts::Linestring<Geometry>) );
  24. BOOST_CONCEPT_ASSERT( (bg::concepts::ConstLinestring<Geometry>) );
  25. Geometry geometry;
  26. typedef typename bg::point_type<Geometry>::type P;
  27. bg::clear(geometry);
  28. BOOST_CHECK_EQUAL(boost::size(geometry), 0u);
  29. bg::append(geometry, bg::make<P>(1, 2));
  30. BOOST_CHECK_EQUAL(boost::size(geometry), 1u);
  31. bg::append(geometry, bg::make<P>(3, 4));
  32. BOOST_CHECK_EQUAL(boost::size(geometry), 2u);
  33. bg::traits::resize<Geometry>::apply(geometry, 1);
  34. BOOST_CHECK_EQUAL(boost::size(geometry), 1u);
  35. //std::cout << bg::dsv(geometry) << std::endl;
  36. P p = *boost::begin(geometry);
  37. //std::cout << bg::dsv(p) << std::endl;
  38. BOOST_CHECK_EQUAL(bg::get<0>(p), 1);
  39. BOOST_CHECK_EQUAL(bg::get<1>(p), 2);
  40. bg::clear(geometry);
  41. BOOST_CHECK_EQUAL(boost::size(geometry), 0u);
  42. }
  43. template <typename Point>
  44. void test_all()
  45. {
  46. test_linestring<bg::model::linestring<Point> >();
  47. test_linestring<test::wrapped_boost_array<Point, 10> >();
  48. test_linestring<all_custom_linestring<Point> >();
  49. }
  50. int test_main(int, char* [])
  51. {
  52. test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
  53. test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
  54. test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
  55. return 0;
  56. }