File indexing completed on 2025-07-11 08:12:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP
0012 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP
0013
0014 #include <boost/geometry/core/assert.hpp>
0015 #include <boost/geometry/core/coordinate_dimension.hpp>
0016 #include <boost/geometry/core/coordinate_type.hpp>
0017 #include <boost/geometry/strategies/line_interpolate.hpp>
0018 #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
0019 #include <boost/geometry/util/algorithm.hpp>
0020 #include <boost/geometry/util/numeric_cast.hpp>
0021 #include <boost/geometry/util/select_calculation_type.hpp>
0022
0023
0024 namespace boost { namespace geometry
0025 {
0026
0027 namespace strategy { namespace line_interpolate
0028 {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template
0044 <
0045 typename CalculationType = void,
0046 typename DistanceStrategy = distance::pythagoras<CalculationType>
0047 >
0048 class cartesian
0049 {
0050 public:
0051 template <typename Point, typename Fraction, typename Distance>
0052 inline void apply(Point const& p0,
0053 Point const& p1,
0054 Fraction const& fraction,
0055 Point & p,
0056 Distance const&) const
0057 {
0058 typedef typename select_calculation_type_alt
0059 <
0060 CalculationType, Point
0061 >::type calc_t;
0062 typedef typename coordinate_type<Point>::type coord_t;
0063
0064
0065 Fraction const one_minus_fraction = 1-fraction;
0066 geometry::detail::for_each_dimension<Point>([&](auto dimension)
0067 {
0068
0069
0070
0071 calc_t coord0 = util::numeric_cast<calc_t>(get<dimension>(p0));
0072 calc_t coord1 = util::numeric_cast<calc_t>(get<dimension>(p1));
0073 calc_t result = calc_t(coord1 * fraction) + calc_t(coord0 * one_minus_fraction);
0074 set<dimension>(p, util::numeric_cast<coord_t>(result));
0075 });
0076 }
0077 };
0078
0079
0080 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0081 namespace services
0082 {
0083
0084 template <>
0085 struct default_strategy<cartesian_tag>
0086 {
0087 typedef strategy::line_interpolate::cartesian<> type;
0088 };
0089
0090
0091 }
0092 #endif
0093
0094
0095 }}
0096
0097
0098 }}
0099
0100 #endif