Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:45

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // Use, modification and distribution is subject to the Boost Software License,
0006 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_SIDE_STRAIGHT_HPP
0010 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_SIDE_STRAIGHT_HPP
0011 
0012 #include <cstddef>
0013 
0014 #include <boost/range/value_type.hpp>
0015 
0016 #include <boost/geometry/core/radian_access.hpp>
0017 
0018 #include <boost/geometry/srs/spheroid.hpp>
0019 #include <boost/geometry/strategies/buffer.hpp>
0020 #include <boost/geometry/strategies/geographic/buffer_helper.hpp>
0021 #include <boost/geometry/strategies/geographic/parameters.hpp>
0022 #include <boost/geometry/util/math.hpp>
0023 #include <boost/geometry/util/select_calculation_type.hpp>
0024 
0025 
0026 namespace boost { namespace geometry
0027 {
0028 
0029 namespace strategy { namespace buffer
0030 {
0031 
0032 /*!
0033 \brief Create a straight buffer along a side, on the Earth
0034 \ingroup strategies
0035 \details This strategy can be used as SideStrategy for the buffer algorithm.
0036  */
0037 template
0038 <
0039     typename FormulaPolicy = strategy::andoyer,
0040     typename Spheroid = srs::spheroid<double>,
0041     typename CalculationType = void
0042 >
0043 class geographic_side_straight
0044 {
0045 public :
0046     //! \brief Constructs the strategy with a spheroid
0047     //! \param spheroid The spheroid to be used
0048     explicit inline geographic_side_straight(Spheroid const& spheroid)
0049         : m_spheroid(spheroid)
0050     {}
0051 
0052     //! \brief Constructs the strategy
0053     inline geographic_side_straight()
0054     {}
0055 
0056 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0057     // Returns true if the buffer distance is always the same
0058     static inline bool equidistant()
0059     {
0060         return true;
0061     }
0062 
0063 
0064     template
0065     <
0066         typename Point,
0067         typename DistanceStrategy,
0068         typename RangeOut
0069     >
0070     inline result_code apply(Point const& input_p1, Point const& input_p2,
0071                              buffer_side_selector side,
0072                              DistanceStrategy const& distance_strategy,
0073                              RangeOut& range_out) const
0074     {
0075         using calc_t = typename select_calculation_type
0076             <
0077                 Point,
0078                 typename boost::range_value<RangeOut>::type,
0079                 CalculationType
0080             >::type;
0081 
0082         using helper = geographic_buffer_helper<FormulaPolicy, calc_t>;
0083 
0084         calc_t const lon1_rad = get_as_radian<0>(input_p1);
0085         calc_t const lat1_rad = get_as_radian<1>(input_p1);
0086         calc_t const lon2_rad = get_as_radian<0>(input_p2);
0087         calc_t const lat2_rad = get_as_radian<1>(input_p2);
0088         if (lon1_rad == lon2_rad && lat1_rad == lat2_rad)
0089         {
0090             // Coordinates are simplified and therefore most often not equal.
0091             // But if simplify is skipped, or for lines with two
0092             // equal points, length is 0 and we cannot generate output.
0093             return result_no_output;
0094         }
0095 
0096 
0097         // Measure the angle from p1 to p2 with the Inverse transformation,
0098         // and subtract pi/2 to make it perpendicular.
0099         auto const inv = helper::azimuth(lon1_rad, lat1_rad, input_p2, m_spheroid);
0100         auto const angle = math::wrap_azimuth_in_radian(inv - geometry::math::half_pi<calc_t>());
0101 
0102         // Calculate the distance and generate two points at that distance
0103         auto const distance = distance_strategy.apply(input_p1, input_p2, side);
0104         helper::append_point(lon1_rad, lat1_rad, distance, angle, m_spheroid, range_out);
0105         helper::append_point(lon2_rad, lat2_rad, distance, angle, m_spheroid, range_out);
0106 
0107         return result_normal;
0108     }
0109 #endif // DOXYGEN_SHOULD_SKIP_THIS
0110 
0111 private :
0112     Spheroid m_spheroid;
0113 };
0114 
0115 }} // namespace strategy::buffer
0116 
0117 }} // namespace boost::geometry
0118 
0119 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_BUFFER_SIDE_STRAIGHT_HPP