Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:51:42

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2015-2022, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0006 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0007 
0008 // Licensed under the Boost Software License version 1.0.
0009 // http://www.boost.org/users/license.html
0010 
0011 #ifndef BOOST_GEOMETRY_UTIL_NORMALIZE_SPHEROIDAL_BOX_COORDINATES_HPP
0012 #define BOOST_GEOMETRY_UTIL_NORMALIZE_SPHEROIDAL_BOX_COORDINATES_HPP
0013 
0014 #include <boost/geometry/core/assert.hpp>
0015 #include <boost/geometry/util/math.hpp>
0016 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
0017 
0018 
0019 namespace boost { namespace geometry
0020 {
0021 
0022 namespace math
0023 {
0024 
0025 #ifndef DOXYGEN_NO_DETAIL
0026 namespace detail
0027 {
0028 
0029 
0030 template <typename Units, typename CoordinateType, bool IsEquatorial = true>
0031 class normalize_spheroidal_box_coordinates
0032 {
0033 private:
0034     typedef normalize_spheroidal_coordinates<Units, CoordinateType> normalize;
0035     typedef constants_on_spheroid<CoordinateType, Units> constants;
0036 
0037     static inline bool is_band(CoordinateType const& longitude1,
0038                                CoordinateType const& longitude2)
0039     {
0040         return math::larger_or_equals(math::abs(longitude1 - longitude2),
0041                                       constants::period());
0042     }
0043 
0044 public:
0045     static inline void apply(CoordinateType& longitude1,
0046                              CoordinateType& latitude1,
0047                              CoordinateType& longitude2,
0048                              CoordinateType& latitude2,
0049                              bool band)
0050     {
0051         normalize::apply(longitude1, latitude1, false);
0052         normalize::apply(longitude2, latitude2, false);
0053 
0054         latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude1);
0055         latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude2);
0056 
0057         if (math::equals(latitude1, constants::min_latitude())
0058             && math::equals(latitude2, constants::min_latitude()))
0059         {
0060             // box degenerates to the south pole
0061             longitude1 = longitude2 = CoordinateType(0);
0062         }
0063         else if (math::equals(latitude1, constants::max_latitude())
0064                  && math::equals(latitude2, constants::max_latitude()))
0065         {
0066             // box degenerates to the north pole
0067             longitude1 = longitude2 = CoordinateType(0);
0068         }
0069         else if (band)
0070         {
0071             // the box is a band between two small circles (parallel
0072             // to the equator) on the spheroid
0073             longitude1 = constants::min_longitude();
0074             longitude2 = constants::max_longitude();
0075         }
0076         else if (longitude1 > longitude2)
0077         {
0078             // the box crosses the antimeridian, so we need to adjust
0079             // the longitudes
0080             longitude2 += constants::period();
0081         }
0082 
0083         latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude1);
0084         latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude2);
0085 
0086 #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
0087         BOOST_GEOMETRY_ASSERT(! math::larger(latitude1, latitude2));
0088         BOOST_GEOMETRY_ASSERT(! math::smaller(latitude1, constants::min_latitude()));
0089         BOOST_GEOMETRY_ASSERT(! math::larger(latitude2, constants::max_latitude()));
0090 #endif
0091 
0092         BOOST_GEOMETRY_ASSERT(! math::larger(longitude1, longitude2));
0093         BOOST_GEOMETRY_ASSERT(! math::smaller(longitude1, constants::min_longitude()));
0094         BOOST_GEOMETRY_ASSERT(! math::larger(longitude2 - longitude1, constants::period()));
0095     }
0096 
0097     static inline void apply(CoordinateType& longitude1,
0098                              CoordinateType& latitude1,
0099                              CoordinateType& longitude2,
0100                              CoordinateType& latitude2)
0101     {
0102         bool const band = is_band(longitude1, longitude2);
0103 
0104         apply(longitude1, latitude1, longitude2, latitude2, band);
0105     }
0106 };
0107 
0108 
0109 } // namespace detail
0110 #endif // DOXYGEN_NO_DETAIL
0111 
0112 
0113 /*!
0114 \brief Short utility to normalize the coordinates of a box on a spheroid
0115 \tparam Units The units of the coordindate system in the spheroid
0116 \tparam CoordinateType The type of the coordinates
0117 \param longitude1 Minimum longitude of the box
0118 \param latitude1 Minimum latitude of the box
0119 \param longitude2 Maximum longitude of the box
0120 \param latitude2 Maximum latitude of the box
0121 \ingroup utility
0122 */
0123 template <typename Units, typename CoordinateType>
0124 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
0125                                                  CoordinateType& latitude1,
0126                                                  CoordinateType& longitude2,
0127                                                  CoordinateType& latitude2)
0128 {
0129     detail::normalize_spheroidal_box_coordinates
0130         <
0131             Units, CoordinateType
0132         >::apply(longitude1, latitude1, longitude2, latitude2);
0133 }
0134 
0135 template <typename Units, bool IsEquatorial, typename CoordinateType>
0136 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
0137                                                  CoordinateType& latitude1,
0138                                                  CoordinateType& longitude2,
0139                                                  CoordinateType& latitude2)
0140 {
0141     detail::normalize_spheroidal_box_coordinates
0142         <
0143             Units, CoordinateType, IsEquatorial
0144         >::apply(longitude1, latitude1, longitude2, latitude2);
0145 }
0146 
0147 /*!
0148 \brief Short utility to normalize the coordinates of a box on a spheroid
0149 \tparam Units The units of the coordindate system in the spheroid
0150 \tparam CoordinateType The type of the coordinates
0151 \param longitude1 Minimum longitude of the box
0152 \param latitude1 Minimum latitude of the box
0153 \param longitude2 Maximum longitude of the box
0154 \param latitude2 Maximum latitude of the box
0155 \param band Indicates whether the box should be treated as a band or
0156        not and avoid the computation done in the other version of the function
0157 \ingroup utility
0158 */
0159 template <typename Units, typename CoordinateType>
0160 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
0161                                                  CoordinateType& latitude1,
0162                                                  CoordinateType& longitude2,
0163                                                  CoordinateType& latitude2,
0164                                                  bool band)
0165 {
0166     detail::normalize_spheroidal_box_coordinates
0167         <
0168             Units, CoordinateType
0169         >::apply(longitude1, latitude1, longitude2, latitude2, band);
0170 }
0171 
0172 template <typename Units, bool IsEquatorial, typename CoordinateType>
0173 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
0174                                                  CoordinateType& latitude1,
0175                                                  CoordinateType& longitude2,
0176                                                  CoordinateType& latitude2,
0177                                                  bool band)
0178 {
0179     detail::normalize_spheroidal_box_coordinates
0180         <
0181             Units, CoordinateType, IsEquatorial
0182         >::apply(longitude1, latitude1, longitude2, latitude2, band);
0183 }
0184 
0185 
0186 } // namespace math
0187 
0188 
0189 }} // namespace boost::geometry
0190 
0191 #endif // BOOST_GEOMETRY_UTIL_NORMALIZE_SPHEROIDAL_BOX_COORDINATES_HPP