File indexing completed on 2025-07-05 08:34:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DENSIFY_HPP
0011 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DENSIFY_HPP
0012
0013
0014 #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
0015 #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
0016 #include <boost/geometry/arithmetic/arithmetic.hpp>
0017 #include <boost/geometry/arithmetic/dot_product.hpp>
0018 #include <boost/geometry/core/assert.hpp>
0019 #include <boost/geometry/core/coordinate_dimension.hpp>
0020 #include <boost/geometry/core/coordinate_type.hpp>
0021 #include <boost/geometry/geometries/point.hpp>
0022 #include <boost/geometry/strategies/densify.hpp>
0023 #include <boost/geometry/util/algorithm.hpp>
0024 #include <boost/geometry/util/math.hpp>
0025 #include <boost/geometry/util/numeric_cast.hpp>
0026 #include <boost/geometry/util/select_most_precise.hpp>
0027
0028
0029 namespace boost { namespace geometry
0030 {
0031
0032 namespace strategy { namespace densify
0033 {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 template
0047 <
0048 typename CalculationType = void
0049 >
0050 class cartesian
0051 {
0052 public:
0053 template <typename Point, typename AssignPolicy, typename T>
0054 static inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold)
0055 {
0056 typedef typename AssignPolicy::point_type out_point_t;
0057 typedef typename coordinate_type<out_point_t>::type out_coord_t;
0058 typedef typename select_most_precise
0059 <
0060 typename coordinate_type<Point>::type, out_coord_t,
0061 CalculationType
0062 >::type calc_t;
0063
0064 typedef model::point<calc_t, geometry::dimension<Point>::value, cs::cartesian> calc_point_t;
0065
0066 assert_dimension_equal<calc_point_t, out_point_t>();
0067
0068 calc_point_t cp0, dir01;
0069
0070 geometry::detail::for_each_dimension<calc_point_t>([&](auto index)
0071 {
0072 calc_t const coord0 = util::numeric_cast<calc_t>(get<index>(p0));
0073 calc_t const coord1 = util::numeric_cast<calc_t>(get<index>(p1));
0074 set<index>(cp0, coord0);
0075 set<index>(dir01, coord1 - coord0);
0076 });
0077
0078 calc_t const dot01 = geometry::dot_product(dir01, dir01);
0079 calc_t const len = math::sqrt(dot01);
0080
0081 BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
0082
0083 signed_size_type const n = signed_size_type(len / length_threshold);
0084 if (n <= 0)
0085 {
0086 return;
0087 }
0088
0089 calc_t const den = calc_t(n + 1);
0090 for (signed_size_type i = 0 ; i < n ; ++i)
0091 {
0092 out_point_t out;
0093
0094 calc_t const num = calc_t(i + 1);
0095 geometry::detail::for_each_dimension<out_point_t>([&](auto index)
0096 {
0097
0098 calc_t const coord = get<index>(cp0) + get<index>(dir01) * num / den;
0099
0100 set<index>(out, util::numeric_cast<out_coord_t>(coord));
0101 });
0102
0103 policy.apply(out);
0104 }
0105 }
0106 };
0107
0108
0109 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0110 namespace services
0111 {
0112
0113 template <>
0114 struct default_strategy<cartesian_tag>
0115 {
0116 typedef strategy::densify::cartesian<> type;
0117 };
0118
0119
0120 }
0121 #endif
0122
0123
0124 }}
0125
0126
0127 }}
0128
0129 #endif