perimeter_geo.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2016-2017 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_perimeter.hpp>
  9. #include <algorithms/perimeter/perimeter_polygon_cases.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. template <typename P>
  13. struct geo_strategies
  14. {
  15. // Set radius type, but for integer coordinates we want to have floating
  16. // point radius type
  17. typedef typename bg::promote_floating_point
  18. <
  19. typename bg::coordinate_type<P>::type
  20. >::type rtype;
  21. typedef bg::srs::spheroid<rtype> stype;
  22. typedef bg::strategy::distance::andoyer<stype> andoyer_type;
  23. typedef bg::strategy::distance::thomas<stype> thomas_type;
  24. typedef bg::strategy::distance::vincenty<stype> vincenty_type;
  25. };
  26. template <typename P>
  27. void test_default() //this should use andoyer strategy
  28. {
  29. for (std::size_t i = 0; i <= 2; ++i)
  30. {
  31. test_geometry<bg::model::polygon<P> >(poly_data_geo[i],
  32. 1116814.237 + 1116152.605);
  33. }
  34. //since the geodesic distance is the shortest path it should go over the pole
  35. //in this case; thus the correct perimeter is the meridian length (below)
  36. //and not 40075160 which is the legth of the equator
  37. test_geometry<bg::model::polygon<P> >(poly_data_geo[3],
  38. 40007834.7139);
  39. //force to use equator path
  40. test_geometry<bg::model::polygon<P> >(poly_data_geo[4],
  41. 40075016.6856);
  42. // Multipolygon
  43. test_geometry<bg::model::multi_polygon<bg::model::polygon<P> > >
  44. (multipoly_data[0], 60011752.0709);
  45. // Geometries with length zero
  46. test_geometry<P>("POINT(0 0)", 0);
  47. test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,0 1,1 1,1 0,0 0)",
  48. 0);
  49. }
  50. template <typename P, typename N, typename Strategy>
  51. void test_with_strategy(N exp_length, Strategy strategy)
  52. {
  53. for (std::size_t i = 0; i <= 2; ++i)
  54. {
  55. test_geometry<bg::model::polygon<P> >(poly_data_geo[i],
  56. exp_length,
  57. strategy);
  58. }
  59. // Geometries with length zero
  60. test_geometry<P>("POINT(0 0)", 0, strategy);
  61. test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,0 1,1 1,1 0,0 0)",
  62. 0,
  63. strategy);
  64. }
  65. template <typename P>
  66. void test_andoyer()
  67. {
  68. typename geo_strategies<P>::andoyer_type andoyer;
  69. test_with_strategy<P>(1116814.237 + 1116152.605, andoyer);
  70. }
  71. template <typename P>
  72. void test_thomas()
  73. {
  74. typename geo_strategies<P>::thomas_type thomas;
  75. test_with_strategy<P>(1116825.795 + 1116158.7417, thomas);
  76. }
  77. template <typename P>
  78. void test_vincenty()
  79. {
  80. typename geo_strategies<P>::vincenty_type vincenty;
  81. test_with_strategy<P>(1116825.857 + 1116159.144, vincenty);
  82. }
  83. template <typename P>
  84. void test_all()
  85. {
  86. test_default<P>();
  87. test_andoyer<P>();
  88. test_thomas<P>();
  89. test_vincenty<P>();
  90. }
  91. int test_main(int, char* [])
  92. {
  93. // Works only for double(?!)
  94. //test_all<bg::model::d2::point_xy<int,
  95. // bg::cs::geographic<bg::degree> > >();
  96. //test_all<bg::model::d2::point_xy<float,
  97. // bg::cs::geographic<bg::degree> > >();
  98. test_all<bg::model::d2::point_xy<double,
  99. bg::cs::geographic<bg::degree> > >();
  100. #if defined(HAVE_TTMATH)
  101. test_all<bg::model::d2::point_xy<ttmath_big> >();
  102. #endif
  103. return 0;
  104. }