123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DENSIFY_HPP
- #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DENSIFY_HPP
- #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
- #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
- #include <boost/geometry/arithmetic/arithmetic.hpp>
- #include <boost/geometry/arithmetic/dot_product.hpp>
- #include <boost/geometry/core/assert.hpp>
- #include <boost/geometry/core/coordinate_dimension.hpp>
- #include <boost/geometry/core/coordinate_type.hpp>
- #include <boost/geometry/geometries/point.hpp>
- #include <boost/geometry/strategies/densify.hpp>
- #include <boost/geometry/util/math.hpp>
- #include <boost/geometry/util/select_most_precise.hpp>
- namespace boost { namespace geometry
- {
- namespace strategy { namespace densify
- {
- template
- <
- typename CalculationType = void
- >
- class cartesian
- {
- public:
- template <typename Point, typename AssignPolicy, typename T>
- static inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold)
- {
- typedef typename AssignPolicy::point_type out_point_t;
- typedef typename select_most_precise
- <
- typename coordinate_type<Point>::type,
- typename coordinate_type<out_point_t>::type,
- CalculationType
- >::type calc_t;
- typedef model::point<calc_t, geometry::dimension<Point>::value, cs::cartesian> calc_point_t;
-
- calc_point_t cp0, cp1;
- geometry::detail::conversion::convert_point_to_point(p0, cp0);
- geometry::detail::conversion::convert_point_to_point(p1, cp1);
-
- calc_point_t dir01 = cp1;
- geometry::subtract_point(dir01, cp0);
- calc_t const dot01 = geometry::dot_product(dir01, dir01);
- calc_t const len = math::sqrt(dot01);
- BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
- signed_size_type n = signed_size_type(len / length_threshold);
- if (n <= 0)
- {
- return;
- }
-
-
-
- calc_t step = len / (n + 1);
- calc_t d = step;
- for (signed_size_type i = 0 ; i < n ; ++i, d += step)
- {
-
- calc_point_t pd = dir01;
-
- geometry::multiply_value(pd, calc_t(i + 1));
- geometry::divide_value(pd, calc_t(n + 1));
-
-
-
- geometry::add_point(pd, cp0);
-
-
- out_point_t p;
- assert_dimension_equal<calc_point_t, out_point_t>();
- geometry::detail::conversion::convert_point_to_point(pd, p);
-
- policy.apply(p);
- }
- }
- };
- #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
- namespace services
- {
- template <>
- struct default_strategy<cartesian_tag>
- {
- typedef strategy::densify::cartesian<> type;
- };
- }
- #endif
- }}
- }}
- #endif
|