length.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <algorithms/test_length.hpp>
  8. #include <boost/geometry/geometries/geometries.hpp>
  9. #include <boost/geometry/geometries/point_xy.hpp>
  10. #include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp>
  11. #include <test_geometries/all_custom_linestring.hpp>
  12. #include <test_geometries/wrapped_boost_array.hpp>
  13. template <typename P>
  14. void test_all()
  15. {
  16. // 3-4-5 triangle
  17. test_geometry<std::pair<P, P> >("LINESTRING(0 0,3 4)", 5);
  18. // 3-4-5 plus 1-1
  19. test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,3 4,4 3)", 5 + sqrt(2.0));
  20. test_geometry<all_custom_linestring<P> >("LINESTRING(0 0,3 4,4 3)", 5 + sqrt(2.0));
  21. test_geometry<test::wrapped_boost_array<P, 3> >("LINESTRING(0 0,3 4,4 3)", 5 + sqrt(2.0));
  22. // Geometries with length zero
  23. test_geometry<P>("POINT(0 0)", 0);
  24. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0);
  25. }
  26. template <typename P>
  27. void test_empty_input()
  28. {
  29. test_empty_input(bg::model::linestring<P>());
  30. }
  31. int test_main(int, char* [])
  32. {
  33. test_all<bg::model::d2::point_xy<int> >();
  34. test_all<bg::model::d2::point_xy<float> >();
  35. test_all<bg::model::d2::point_xy<double> >();
  36. #if defined(HAVE_TTMATH)
  37. test_all<bg::model::d2::point_xy<ttmath_big> >();
  38. #endif
  39. // test_empty_input<bg::model::d2::point_xy<int> >();
  40. return 0;
  41. }