envelope_segment.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2017-2018 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fisikopoulos, 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. #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ENVELOPE_SEGMENT_HPP
  9. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ENVELOPE_SEGMENT_HPP
  10. #include <boost/geometry/srs/spheroid.hpp>
  11. #include <boost/geometry/strategies/cartesian/envelope_segment.hpp>
  12. #include <boost/geometry/strategies/envelope.hpp>
  13. #include <boost/geometry/strategies/geographic/azimuth.hpp>
  14. #include <boost/geometry/strategies/geographic/parameters.hpp>
  15. #include <boost/geometry/strategies/normalize.hpp>
  16. #include <boost/geometry/strategies/spherical/envelope_segment.hpp>
  17. #include <boost/geometry/strategies/spherical/expand_box.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. namespace strategy { namespace envelope
  21. {
  22. template
  23. <
  24. typename FormulaPolicy = strategy::andoyer,
  25. typename Spheroid = geometry::srs::spheroid<double>,
  26. typename CalculationType = void
  27. >
  28. class geographic_segment
  29. {
  30. public:
  31. typedef Spheroid model_type;
  32. inline geographic_segment()
  33. : m_spheroid()
  34. {}
  35. explicit inline geographic_segment(Spheroid const& spheroid)
  36. : m_spheroid(spheroid)
  37. {}
  38. typedef strategy::expand::spherical_box box_expand_strategy_type;
  39. static inline box_expand_strategy_type get_box_expand_strategy()
  40. {
  41. return box_expand_strategy_type();
  42. }
  43. template <typename Point, typename Box>
  44. inline void apply(Point const& point1, Point const& point2, Box& box) const
  45. {
  46. Point p1_normalized, p2_normalized;
  47. strategy::normalize::spherical_point::apply(point1, p1_normalized);
  48. strategy::normalize::spherical_point::apply(point2, p2_normalized);
  49. geometry::strategy::azimuth::geographic
  50. <
  51. FormulaPolicy,
  52. Spheroid,
  53. CalculationType
  54. > azimuth_geographic(m_spheroid);
  55. typedef typename geometry::detail::cs_angular_units
  56. <
  57. Point
  58. >::type units_type;
  59. // first compute the envelope range for the first two coordinates
  60. strategy::envelope::detail::envelope_segment_impl
  61. <
  62. geographic_tag
  63. >::template apply<units_type>(geometry::get<0>(p1_normalized),
  64. geometry::get<1>(p1_normalized),
  65. geometry::get<0>(p2_normalized),
  66. geometry::get<1>(p2_normalized),
  67. box,
  68. azimuth_geographic);
  69. // now compute the envelope range for coordinates of
  70. // dimension 2 and higher
  71. strategy::envelope::detail::envelope_one_segment
  72. <
  73. 2, dimension<Point>::value
  74. >::apply(point1, point2, box);
  75. }
  76. private:
  77. Spheroid m_spheroid;
  78. };
  79. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  80. namespace services
  81. {
  82. template <typename CalculationType>
  83. struct default_strategy<segment_tag, geographic_tag, CalculationType>
  84. {
  85. typedef strategy::envelope::geographic_segment
  86. <
  87. strategy::andoyer,
  88. srs::spheroid<double>,
  89. CalculationType
  90. > type;
  91. };
  92. }
  93. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  94. }} // namespace strategy::envelope
  95. }} //namepsace boost::geometry
  96. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ENVELOPE_SEGMENT_HPP