meridian_segment.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Boost.Geometry
  2. // Copyright (c) 2017-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. #ifndef BOOST_GEOMETRY_FORMULAS_MERIDIAN_SEGMENT_HPP
  9. #define BOOST_GEOMETRY_FORMULAS_MERIDIAN_SEGMENT_HPP
  10. #include <boost/math/constants/constants.hpp>
  11. #include <boost/geometry/core/radius.hpp>
  12. #include <boost/geometry/util/condition.hpp>
  13. #include <boost/geometry/util/math.hpp>
  14. #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
  15. namespace boost { namespace geometry { namespace formula
  16. {
  17. /*!
  18. \brief Test if a segment is meridian or not.
  19. */
  20. class meridian_segment
  21. {
  22. public :
  23. enum SegmentType {NonMeridian, MeridianCrossingPole, MeridianNotCrossingPole};
  24. template <typename T>
  25. static inline SegmentType is_meridian(T lon1, T lat1, T lon2, T lat2)
  26. {
  27. SegmentType res = NonMeridian;
  28. T diff = geometry::math::longitude_distance_signed<geometry::radian>(lon1, lon2);
  29. if ( meridian_not_crossing_pole(lat1, lat2, diff) )
  30. {
  31. res = MeridianNotCrossingPole;
  32. }
  33. else if ( meridian_crossing_pole(diff) )
  34. {
  35. res = MeridianCrossingPole;
  36. }
  37. return res;
  38. }
  39. template <typename T>
  40. static bool meridian_not_crossing_pole(T lat1, T lat2, T diff)
  41. {
  42. T half_pi = math::half_pi<T>();
  43. return math::equals(diff, T(0)) ||
  44. (math::equals(lat2, half_pi) && math::equals(lat1, -half_pi));
  45. }
  46. template <typename T>
  47. static bool meridian_crossing_pole(T diff)
  48. {
  49. return math::equals(math::abs(diff), math::pi<T>());
  50. }
  51. };
  52. }}} // namespace boost::geometry::formula
  53. #endif //BOOST_GEOMETRY_FORMULAS_MERIDIAN_SEGMENT_HPP