intersects_antimeridian.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERSECTS_ANTIMERIDIAN_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERSECTS_ANTIMERIDIAN_HPP
  9. #include <boost/geometry/core/access.hpp>
  10. #include <boost/geometry/core/coordinate_system.hpp>
  11. #include <boost/geometry/util/math.hpp>
  12. #include <boost/geometry/algorithms/detail/normalize.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. namespace detail { namespace envelope
  16. {
  17. struct intersects_antimeridian
  18. {
  19. template <typename Units, typename CoordinateType>
  20. static inline bool apply(CoordinateType const& lon1,
  21. CoordinateType const& lat1,
  22. CoordinateType const& lon2,
  23. CoordinateType const& lat2)
  24. {
  25. typedef math::detail::constants_on_spheroid
  26. <
  27. CoordinateType, Units
  28. > constants;
  29. return
  30. math::equals(math::abs(lat1), constants::max_latitude())
  31. ||
  32. math::equals(math::abs(lat2), constants::max_latitude())
  33. ||
  34. math::larger(math::abs(lon1 - lon2), constants::half_period());
  35. }
  36. template <typename Segment>
  37. static inline bool apply(Segment const& segment)
  38. {
  39. return apply(detail::indexed_point_view<Segment, 0>(segment),
  40. detail::indexed_point_view<Segment, 1>(segment));
  41. }
  42. template <typename Point>
  43. static inline bool apply(Point const& p1, Point const& p2)
  44. {
  45. Point p1_normalized = detail::return_normalized<Point>(p1);
  46. Point p2_normalized = detail::return_normalized<Point>(p2);
  47. return apply
  48. <
  49. typename coordinate_system<Point>::type::units
  50. >(geometry::get<0>(p1_normalized),
  51. geometry::get<1>(p1_normalized),
  52. geometry::get<0>(p2_normalized),
  53. geometry::get<1>(p2_normalized));
  54. }
  55. };
  56. }} // namespace detail::envelope
  57. }} // namespace boost::geometry
  58. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_INTERSECTS_ANTIMERIDIAN_HPP