Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:32:12

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2012-2014 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_CARTESIAN_BUFFER_JOIN_ROUND_BY_DIVIDE_HPP
0010 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_JOIN_ROUND_BY_DIVIDE_HPP
0011 
0012 #include <boost/geometry/core/cs.hpp>
0013 #include <boost/geometry/policies/compare.hpp>
0014 #include <boost/geometry/strategies/buffer.hpp>
0015 #include <boost/geometry/util/math.hpp>
0016 #include <boost/geometry/util/select_most_precise.hpp>
0017 
0018 #ifdef BOOST_GEOMETRY_DEBUG_BUFFER_WARN
0019 #include <boost/geometry/io/wkt/wkt.hpp>
0020 #endif
0021 
0022 namespace boost { namespace geometry
0023 {
0024 
0025 
0026 namespace strategy { namespace buffer
0027 {
0028 
0029 
0030 class join_round_by_divide
0031 {
0032 public :
0033 
0034     inline join_round_by_divide(std::size_t max_level = 4)
0035         : m_max_level(max_level)
0036     {}
0037 
0038     template
0039     <
0040         typename PromotedType,
0041         typename Point,
0042         typename DistanceType,
0043         typename RangeOut
0044     >
0045     inline void mid_points(Point const& vertex,
0046                 Point const& p1, Point const& p2,
0047                 DistanceType const& buffer_distance,
0048                 RangeOut& range_out,
0049                 std::size_t level = 1) const
0050     {
0051         // Generate 'vectors'
0052         PromotedType const vp1_x = get<0>(p1) - get<0>(vertex);
0053         PromotedType const vp1_y = get<1>(p1) - get<1>(vertex);
0054 
0055         PromotedType const vp2_x = (get<0>(p2) - get<0>(vertex));
0056         PromotedType const vp2_y = (get<1>(p2) - get<1>(vertex));
0057 
0058         // Average them to generate vector in between
0059         PromotedType const two = 2;
0060         PromotedType const v_x = (vp1_x + vp2_x) / two;
0061         PromotedType const v_y = (vp1_y + vp2_y) / two;
0062 
0063         PromotedType const length2 = geometry::math::sqrt(v_x * v_x + v_y * v_y);
0064 
0065         PromotedType const prop = buffer_distance / length2;
0066 
0067         Point mid_point;
0068         set<0>(mid_point, get<0>(vertex) + v_x * prop);
0069         set<1>(mid_point, get<1>(vertex) + v_y * prop);
0070 
0071         if (level < m_max_level)
0072         {
0073             mid_points<PromotedType>(vertex, p1, mid_point, buffer_distance, range_out, level + 1);
0074         }
0075         range_out.push_back(mid_point);
0076         if (level < m_max_level)
0077         {
0078             mid_points<PromotedType>(vertex, mid_point, p2, buffer_distance, range_out, level + 1);
0079         }
0080     }
0081 
0082     template <typename Point, typename DistanceType, typename RangeOut>
0083     inline bool apply(Point const& ip, Point const& vertex,
0084                 Point const& perp1, Point const& perp2,
0085                 DistanceType const& buffer_distance,
0086                 RangeOut& range_out) const
0087     {
0088         using promoted_type = typename geometry::select_most_precise
0089             <
0090                 coordinate_type_t<Point>,
0091                 double
0092             >::type;
0093 
0094         geometry::equal_to<Point> equals;
0095 
0096         if (equals(perp1, perp2))
0097         {
0098 #ifdef BOOST_GEOMETRY_DEBUG_BUFFER_WARN
0099             std::cout << "Corner for equal points " << geometry::wkt(ip) << " " << geometry::wkt(perp1) << std::endl;
0100 #endif
0101             return false;
0102         }
0103 
0104         // Generate 'vectors'
0105         promoted_type const vix = (get<0>(ip) - get<0>(vertex));
0106         promoted_type const viy = (get<1>(ip) - get<1>(vertex));
0107 
0108         promoted_type const length_i = geometry::math::sqrt(vix * vix + viy * viy);
0109 
0110         promoted_type const bd = geometry::math::abs(buffer_distance);
0111         promoted_type const prop = bd / length_i;
0112 
0113         Point bp;
0114         set<0>(bp, get<0>(vertex) + vix * prop);
0115         set<1>(bp, get<1>(vertex) + viy * prop);
0116 
0117         range_out.push_back(perp1);
0118 
0119         if (m_max_level > 1)
0120         {
0121             mid_points<promoted_type>(vertex, perp1, bp, bd, range_out);
0122             range_out.push_back(bp);
0123             mid_points<promoted_type>(vertex, bp, perp2, bd, range_out);
0124         }
0125         else if (m_max_level == 1)
0126         {
0127             range_out.push_back(bp);
0128         }
0129 
0130         range_out.push_back(perp2);
0131         return true;
0132     }
0133 
0134     template <typename NumericType>
0135     static inline NumericType max_distance(NumericType const& distance)
0136     {
0137         return distance;
0138     }
0139 
0140 private :
0141     std::size_t m_max_level;
0142 };
0143 
0144 
0145 }} // namespace strategy::buffer
0146 
0147 
0148 }} // namespace boost::geometry
0149 
0150 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_JOIN_ROUND_BY_DIVIDE_HPP