length_geo.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2016 Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <algorithms/test_length.hpp>
  9. #include <algorithms/length/linestring_cases.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. #include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp>
  13. #include <test_geometries/all_custom_linestring.hpp>
  14. #include <test_geometries/wrapped_boost_array.hpp>
  15. template <typename P>
  16. struct geo_strategies
  17. {
  18. // Set radius type, but for integer coordinates we want to have floating
  19. // point radius type
  20. typedef typename bg::promote_floating_point
  21. <
  22. typename bg::coordinate_type<P>::type
  23. >::type rtype;
  24. typedef bg::srs::spheroid<rtype> stype;
  25. typedef bg::strategy::distance::andoyer<stype> andoyer_type;
  26. typedef bg::strategy::distance::thomas<stype> thomas_type;
  27. typedef bg::strategy::distance::vincenty<stype> vincenty_type;
  28. };
  29. template <typename P>
  30. void test_default() //this should use andoyer strategy
  31. {
  32. for(std::size_t i = 0; i < 2; ++i)
  33. {
  34. test_geometry<bg::model::linestring<P> >(Ls_data_geo[i],
  35. 1116814.237 + 1116152.605);
  36. }
  37. // Geometries with length zero
  38. test_geometry<P>("POINT(0 0)", 0);
  39. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0);
  40. }
  41. template <typename P, typename N, typename Strategy>
  42. void test_with_strategy(N exp_length, Strategy strategy)
  43. {
  44. for(std::size_t i = 0; i < 2; ++i)
  45. {
  46. test_geometry<bg::model::linestring<P> >(Ls_data_geo[i],
  47. exp_length,
  48. strategy);
  49. }
  50. // Geometries with length zero
  51. test_geometry<P>("POINT(0 0)", 0, strategy);
  52. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0,
  53. strategy);
  54. }
  55. template <typename P>
  56. void test_andoyer()
  57. {
  58. typename geo_strategies<P>::andoyer_type andoyer;
  59. test_with_strategy<P>(1116814.237 + 1116152.605, andoyer);
  60. }
  61. template <typename P>
  62. void test_thomas()
  63. {
  64. typename geo_strategies<P>::thomas_type thomas;
  65. test_with_strategy<P>(1116825.795 + 1116158.7417, thomas);
  66. }
  67. template <typename P>
  68. void test_vincenty()
  69. {
  70. typename geo_strategies<P>::vincenty_type vincenty;
  71. test_with_strategy<P>(1116825.857 + 1116159.144, vincenty);
  72. }
  73. template <typename P>
  74. void test_all()
  75. {
  76. test_default<P>();
  77. test_andoyer<P>();
  78. test_thomas<P>();
  79. test_vincenty<P>();
  80. }
  81. template <typename P>
  82. void test_empty_input()
  83. {
  84. test_empty_input(bg::model::linestring<P>());
  85. test_empty_input(bg::model::multi_linestring<P>());
  86. }
  87. int test_main(int, char* [])
  88. {
  89. // Works only for double(?!)
  90. //test_all<bg::model::d2::point_xy<int,
  91. // bg::cs::geographic<bg::degree> > >();
  92. //test_all<bg::model::d2::point_xy<float,
  93. // bg::cs::geographic<bg::degree> > >();
  94. test_all<bg::model::d2::point_xy<double,
  95. bg::cs::geographic<bg::degree> > >();
  96. #if defined(HAVE_TTMATH)
  97. test_all<bg::model::d2::point_xy<ttmath_big> >();
  98. #endif
  99. //test_empty_input<bg::model::d2::point_xy<double,
  100. // bg::cs::geographic<bg::degree> > >();
  101. return 0;
  102. }