File indexing completed on 2025-01-18 09:36:42
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/select_most_precise.hpp>
0026
0027
0028 namespace boost { namespace geometry
0029 {
0030
0031 namespace strategy { namespace densify
0032 {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 template
0046 <
0047 typename CalculationType = void
0048 >
0049 class cartesian
0050 {
0051 public:
0052 template <typename Point, typename AssignPolicy, typename T>
0053 static inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold)
0054 {
0055 typedef typename AssignPolicy::point_type out_point_t;
0056 typedef typename coordinate_type<out_point_t>::type out_coord_t;
0057 typedef typename select_most_precise
0058 <
0059 typename coordinate_type<Point>::type, out_coord_t,
0060 CalculationType
0061 >::type calc_t;
0062
0063 typedef model::point<calc_t, geometry::dimension<Point>::value, cs::cartesian> calc_point_t;
0064
0065 assert_dimension_equal<calc_point_t, out_point_t>();
0066
0067 calc_point_t cp0, dir01;
0068
0069 geometry::detail::for_each_dimension<calc_point_t>([&](auto index)
0070 {
0071 calc_t const coord0 = boost::numeric_cast<calc_t>(get<index>(p0));
0072 calc_t const coord1 = boost::numeric_cast<calc_t>(get<index>(p1));
0073 set<index>(cp0, coord0);
0074 set<index>(dir01, coord1 - coord0);
0075 });
0076
0077 calc_t const dot01 = geometry::dot_product(dir01, dir01);
0078 calc_t const len = math::sqrt(dot01);
0079
0080 BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
0081
0082 signed_size_type const n = signed_size_type(len / length_threshold);
0083 if (n <= 0)
0084 {
0085 return;
0086 }
0087
0088 calc_t const den = calc_t(n + 1);
0089 for (signed_size_type i = 0 ; i < n ; ++i)
0090 {
0091 out_point_t out;
0092
0093 calc_t const num = calc_t(i + 1);
0094 geometry::detail::for_each_dimension<out_point_t>([&](auto index)
0095 {
0096
0097 calc_t const coord = get<index>(cp0) + get<index>(dir01) * num / den;
0098
0099 set<index>(out, boost::numeric_cast<out_coord_t>(coord));
0100 });
0101
0102 policy.apply(out);
0103 }
0104 }
0105 };
0106
0107
0108 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0109 namespace services
0110 {
0111
0112 template <>
0113 struct default_strategy<cartesian_tag>
0114 {
0115 typedef strategy::densify::cartesian<> type;
0116 };
0117
0118
0119 }
0120 #endif
0121
0122
0123 }}
0124
0125
0126 }}
0127
0128 #endif