envelope_segment.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Boost.Geometry
  2. // Copyright (c) 2016-2018 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, 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 <geometry_test_common.hpp>
  9. #include <boost/geometry/io/wkt/wkt.hpp>
  10. #include <boost/geometry/geometries/box.hpp>
  11. #include <boost/geometry/strategies/geographic/envelope_segment.hpp>
  12. #include <boost/geometry/strategies/spherical/envelope_segment.hpp>
  13. template
  14. <
  15. typename FormulaPolicy,
  16. typename P,
  17. typename CT
  18. >
  19. void test_strategies_lat(P p1, P p2, CT expected_max, CT expected_min,
  20. CT expected_max_sph, CT expected_min_sph, CT error = 0.0001)
  21. {
  22. bg::model::box<P> box;
  23. bg::strategy::envelope::geographic_segment
  24. <
  25. FormulaPolicy,
  26. bg::srs::spheroid<CT>,
  27. CT
  28. > strategy_geo;
  29. strategy_geo.apply(p1, p2, box);
  30. CT p_min_degree_geo = bg::get<0, 1>(box);
  31. CT p_max_degree_geo = bg::get<1, 1>(box);
  32. BOOST_CHECK_CLOSE(p_max_degree_geo, expected_max, error);
  33. BOOST_CHECK_CLOSE(p_min_degree_geo, expected_min, error);
  34. typedef bg::strategy::envelope::spherical_segment<CT> strategy_sph_t;
  35. strategy_sph_t::apply(p1, p2, box);
  36. CT p_min_degree_sph = bg::get<0, 1>(box);
  37. CT p_max_degree_sph = bg::get<1, 1>(box);
  38. BOOST_CHECK_CLOSE(p_max_degree_sph, expected_max_sph, error);
  39. BOOST_CHECK_CLOSE(p_min_degree_sph, expected_min_sph, error);
  40. }
  41. template <typename CT>
  42. void test_all()
  43. {
  44. typedef bg::model::point<CT, 2, bg::cs::geographic<bg::degree> > Pg;
  45. // Short segments
  46. test_strategies_lat<bg::strategy::thomas>
  47. (Pg(1, 1), Pg(10, 5), 5.0, 1.0, 5.0, 1.0);
  48. test_strategies_lat<bg::strategy::thomas>
  49. (Pg(1, 1), Pg(10, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
  50. test_strategies_lat<bg::strategy::thomas>
  51. (Pg(-5, 1), Pg(4, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
  52. test_strategies_lat<bg::strategy::thomas>
  53. (Pg(175, 1), Pg(184, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
  54. test_strategies_lat<bg::strategy::thomas>
  55. (Pg(355, 1), Pg(4, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
  56. // Reverse direction
  57. test_strategies_lat<bg::strategy::thomas>
  58. (Pg(1, 2), Pg(70, 1), 2.0239716998355468, 1.0, 2.0228167431951536, 1.0);
  59. test_strategies_lat<bg::strategy::thomas>
  60. (Pg(70, 1), Pg(1, 2), 2.0239716998351849, 1.0, 2.022816743195063, 1.0);
  61. // Long segments
  62. test_strategies_lat<bg::strategy::thomas>
  63. (Pg(0, 1), Pg(170, 1), 11.975026023950877, 1.0, 11.325049479775814, 1.0);
  64. test_strategies_lat<bg::strategy::thomas>
  65. (Pg(0, 1), Pg(179, 1), 68.452669316418039, 1.0, 63.437566893227093, 1.0);
  66. test_strategies_lat<bg::strategy::thomas>
  67. (Pg(0, 1), Pg(179.5, 1), 78.84050225214871, 1.0, 75.96516822754981, 1.0);
  68. test_strategies_lat<bg::strategy::thomas>
  69. (Pg(0, 1), Pg(180.5, 1), 78.84050225214871, 1.0, 75.965168227550194, 1.0);
  70. test_strategies_lat<bg::strategy::thomas>
  71. (Pg(0, 1), Pg(180, 1), 90.0, 1.0, 90.0, 1.0);
  72. // South hemisphere
  73. test_strategies_lat<bg::strategy::thomas>
  74. (Pg(1, -1), Pg(10, -5), -1.0, -5.0, -1.0, -5.0);
  75. test_strategies_lat<bg::strategy::thomas>
  76. (Pg(1, -1), Pg(10, -1), -1.0, -1.0031124506594733, -1.0, -1.0030915676477881);
  77. test_strategies_lat<bg::strategy::thomas>
  78. (Pg(1, -1), Pg(170, -1), -1.0, -10.85834257048573, -1.0, -10.321374780571153);
  79. // Different strategies for inverse
  80. test_strategies_lat<bg::strategy::thomas>
  81. (Pg(1, 1), Pg(10, 1), 1.0031124506594733, 1.0,
  82. 1.0030915676477881, 1.0, 0.00000001);
  83. test_strategies_lat<bg::strategy::andoyer>
  84. (Pg(1, 1), Pg(10, 1), 1.0031124504591062, 1.0,
  85. 1.0030915676477881, 1.0, 0.00000001);
  86. test_strategies_lat<bg::strategy::vincenty>
  87. (Pg(1, 1), Pg(10, 1), 1.0031124508942098, 1.0,
  88. 1.0030915676477881, 1.0, 0.00000001);
  89. // Meridian and equator
  90. test_strategies_lat<bg::strategy::thomas>
  91. (Pg(1, 10), Pg(1, -10), 10.0, -10.0, 10.0, -10.0);
  92. test_strategies_lat<bg::strategy::thomas>
  93. (Pg(1, 0), Pg(10, 0), 0.0, 0.0, 0.0, 0.0);
  94. // One endpoint in northern hemisphere and the other in southern hemisphere
  95. test_strategies_lat<bg::strategy::thomas>
  96. (Pg(1, 1), Pg(150, -5), 1.0, -8.1825389632359933, 1.0, -8.0761230625567588);
  97. test_strategies_lat<bg::strategy::thomas>
  98. (Pg(150, -5), Pg(1, 1), 1.0, -8.1825389632359933, 1.0, -8.0761230625568015);
  99. test_strategies_lat<bg::strategy::thomas>
  100. (Pg(150, 5), Pg(1, -1), 8.1825389632359933, -1.0, 8.0761230625568015, -1.0);
  101. }
  102. int test_main( int , char* [] )
  103. {
  104. test_all<double>();
  105. return 0;
  106. }