segment.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <iostream>
  12. #include <geometry_test_common.hpp>
  13. #include <boost/core/ignore_unused.hpp>
  14. #include <boost/geometry/geometries/concepts/segment_concept.hpp>
  15. #include <boost/geometry/geometries/point.hpp>
  16. #include <boost/geometry/geometries/segment.hpp>
  17. #include <boost/geometry/geometries/adapted/c_array.hpp>
  18. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  19. #include <boost/geometry/io/dsv/write.hpp>
  20. #include <test_common/test_point.hpp>
  21. #include <test_geometries/custom_segment.hpp>
  22. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
  23. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  24. template <typename P>
  25. void test_all()
  26. {
  27. typedef bg::model::referring_segment<P> S;
  28. P p1;
  29. P p2;
  30. S s(p1, p2);
  31. BOOST_CHECK_EQUAL(&s.first, &p1);
  32. BOOST_CHECK_EQUAL(&s.second, &p2);
  33. // Compilation tests, all things should compile.
  34. BOOST_CONCEPT_ASSERT( (bg::concepts::ConstSegment<S>) );
  35. BOOST_CONCEPT_ASSERT( (bg::concepts::Segment<S>) );
  36. typedef typename bg::coordinate_type<S>::type T;
  37. typedef typename bg::point_type<S>::type SP;
  38. boost::ignore_unused<T, SP>();
  39. //std::cout << sizeof(typename coordinate_type<S>::type) << std::endl;
  40. typedef bg::model::referring_segment<P const> refseg_t;
  41. //BOOST_CONCEPT_ASSERT( (concepts::ConstSegment<refseg_t>) );
  42. refseg_t seg(p1, p2);
  43. typedef typename bg::coordinate_type<refseg_t>::type CT;
  44. typedef typename bg::point_type<refseg_t>::type CSP;
  45. boost::ignore_unused<CT, CSP>();
  46. }
  47. template <typename S>
  48. void test_custom()
  49. {
  50. S seg;
  51. bg::set<0,0>(seg, 1);
  52. bg::set<0,1>(seg, 2);
  53. bg::set<1,0>(seg, 3);
  54. bg::set<1,1>(seg, 4);
  55. std::ostringstream out;
  56. out << bg::dsv(seg);
  57. BOOST_CHECK_EQUAL(out.str(), "((1, 2), (3, 4))");
  58. }
  59. int test_main(int, char* [])
  60. {
  61. test_all<int[3]>();
  62. test_all<float[3]>();
  63. test_all<double[3]>();
  64. //test_all<test_point>();
  65. test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
  66. test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
  67. test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
  68. test_custom<test::custom_segment>();
  69. test_custom<test::custom_segment_of<bg::model::point<double, 2, bg::cs::cartesian> > >();
  70. test_custom<test::custom_segment_of<test::custom_point_for_segment> >();
  71. test_custom<test::custom_segment_4>();
  72. return 0;
  73. }