closest_points_pt_seg.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Boost.Geometry
  2. // Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
  3. // Copyright (c) 2021, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_CLOSEST_POINTS_CROSS_TRACK_HPP
  8. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_CLOSEST_POINTS_CROSS_TRACK_HPP
  9. #include <boost/geometry/core/coordinate_dimension.hpp>
  10. #include <boost/geometry/core/coordinate_promotion.hpp>
  11. #include <boost/geometry/core/coordinate_system.hpp>
  12. #include <boost/geometry/core/radian_access.hpp>
  13. #include <boost/geometry/geometries/point.hpp>
  14. #include <boost/geometry/srs/spheroid.hpp>
  15. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  16. #include <boost/geometry/util/select_calculation_type.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace strategy { namespace closest_points
  20. {
  21. template
  22. <
  23. typename FormulaPolicy = geometry::strategy::andoyer,
  24. typename Spheroid = srs::spheroid<double>,
  25. typename CalculationType = void
  26. >
  27. class geographic_cross_track
  28. : public distance::detail::geographic_cross_track
  29. <
  30. FormulaPolicy,
  31. Spheroid,
  32. CalculationType,
  33. false,
  34. true
  35. >
  36. {
  37. using base_t = distance::detail::geographic_cross_track
  38. <
  39. FormulaPolicy,
  40. Spheroid,
  41. CalculationType,
  42. false,
  43. true
  44. >;
  45. template <typename Point, typename PointOfSegment>
  46. struct calculation_type
  47. : promote_floating_point
  48. <
  49. typename select_calculation_type
  50. <
  51. Point,
  52. PointOfSegment,
  53. CalculationType
  54. >::type
  55. >
  56. {};
  57. public :
  58. explicit geographic_cross_track(Spheroid const& spheroid = Spheroid())
  59. : base_t(spheroid)
  60. {}
  61. template <typename Point, typename PointOfSegment>
  62. auto apply(Point const& p,
  63. PointOfSegment const& sp1,
  64. PointOfSegment const& sp2) const
  65. {
  66. auto result = base_t::apply(get_as_radian<0>(sp1), get_as_radian<1>(sp1),
  67. get_as_radian<0>(sp2), get_as_radian<1>(sp2),
  68. get_as_radian<0>(p), get_as_radian<1>(p),
  69. base_t::m_spheroid);
  70. model::point
  71. <
  72. typename calculation_type<Point, PointOfSegment>::type,
  73. dimension<PointOfSegment>::value,
  74. typename coordinate_system<PointOfSegment>::type
  75. > cp;
  76. geometry::set_from_radian<0>(cp, result.lon);
  77. geometry::set_from_radian<1>(cp, result.lat);
  78. return cp;
  79. }
  80. };
  81. }} // namespace strategy::closest_points
  82. }} // namespace boost::geometry
  83. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_CLOSEST_POINTS_CROSS_TRACK_HPP